Skip to content

Commit c9b19a4

Browse files
committedFeb 4, 2023
#248 open only one menu on keyboard shortcut
1 parent 677edf2 commit c9b19a4

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed
 

‎data-browser/src/components/Dropdown/index.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ interface DropdownMenuProps {
2626
/** The list of menu items */
2727
items: Item[];
2828
trigger: DropdownTriggerRenderFunction;
29+
/** Enables the keyboard shortcut */
30+
isMainMenu?: boolean;
2931
}
3032

3133
/** Gets the index of an array and loops around when at the beginning or end */
@@ -88,6 +90,7 @@ function normalizeItems(items: Item[]) {
8890
export function DropdownMenu({
8991
items,
9092
trigger,
93+
isMainMenu,
9194
}: DropdownMenuProps): JSX.Element {
9295
const menuId = useId();
9396
const dropdownRef = useRef<HTMLDivElement>(null);
@@ -167,7 +170,7 @@ export function DropdownMenu({
167170
handleToggle();
168171
setUseKeys(true);
169172
},
170-
{},
173+
{ enabled: !!isMainMenu },
171174
[isActive],
172175
);
173176
// Click / open the item

‎data-browser/src/components/Navigation.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ function NavBar(): JSX.Element {
136136

137137
{showButtons && subject && (
138138
<ResourceContextMenu
139+
isMainMenu
139140
subject={subject}
140141
trigger={MenuBarDropdownTrigger}
141142
/>

‎data-browser/src/components/ResourceContextMenu/index.tsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export interface ResourceContextMenuProps {
3131
hide?: string[];
3232
trigger?: DropdownTriggerRenderFunction;
3333
simple?: boolean;
34+
/** If it's the primary menu in the navbar. Used for triggering keyboard shortcut */
35+
isMainMenu?: boolean;
3436
}
3537

3638
/** Dropdown menu that opens a bunch of actions for some resource */
@@ -39,6 +41,7 @@ function ResourceContextMenu({
3941
hide,
4042
trigger,
4143
simple,
44+
isMainMenu,
4245
}: ResourceContextMenuProps) {
4346
const store = useStore();
4447
const navigate = useNavigate();
@@ -149,7 +152,13 @@ function ResourceContextMenu({
149152

150153
const triggerComp = trigger ?? buildDefaultTrigger(<FaEllipsisV />);
151154

152-
return <DropdownMenu items={filteredItems} trigger={triggerComp} />;
155+
return (
156+
<DropdownMenu
157+
items={filteredItems}
158+
trigger={triggerComp}
159+
isMainMenu={isMainMenu}
160+
/>
161+
);
153162
}
154163

155164
export default ResourceContextMenu;

0 commit comments

Comments
 (0)
Please sign in to comment.