Skip to content

Commit 80e6c66

Browse files
committed
#248 open only one menu on keyboard shortcut
1 parent b96ed72 commit 80e6c66

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ interface DropdownMenuProps {
2727
/** The list of menu items */
2828
items: Item[];
2929
trigger: DropdownTriggerRenderFunction;
30+
/** Enables the keyboard shortcut */
31+
isMainMenu?: boolean;
3032
}
3133

3234
/** Gets the index of an array and loops around when at the beginning or end */
@@ -89,6 +91,7 @@ function normalizeItems(items: Item[]) {
8991
export function DropdownMenu({
9092
items,
9193
trigger,
94+
isMainMenu,
9295
}: DropdownMenuProps): JSX.Element {
9396
const menuId = useId();
9497
const dropdownRef = useRef<HTMLDivElement>(null);
@@ -168,7 +171,7 @@ export function DropdownMenu({
168171
handleToggle();
169172
setUseKeys(true);
170173
},
171-
{},
174+
{ enabled: !!isMainMenu },
172175
[isActive],
173176
);
174177
// Click / open the item

data-browser/src/components/Navigation.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ function NavBar() {
211211
/>
212212
{showButtons && subject && (
213213
<ResourceContextMenu
214+
isMainMenu
214215
subject={subject}
215216
trigger={MenuBarDropdownTrigger}
216217
/>

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export interface ResourceContextMenuProps {
3030
hide?: string[];
3131
trigger?: DropdownTriggerRenderFunction;
3232
simple?: boolean;
33+
/** If it's the primary menu in the navbar. Used for triggering keyboard shortcut */
34+
isMainMenu?: boolean;
3335
}
3436

3537
/** Dropdown menu that opens a bunch of actions for some resource */
@@ -38,6 +40,7 @@ function ResourceContextMenu({
3840
hide,
3941
trigger,
4042
simple,
43+
isMainMenu,
4144
}: ResourceContextMenuProps) {
4245
const store = useStore();
4346
const navigate = useNavigate();
@@ -140,7 +143,13 @@ function ResourceContextMenu({
140143

141144
const triggerComp = trigger ?? buildDefaultTrigger(<FaEllipsisV />);
142145

143-
return <DropdownMenu items={filteredItems} trigger={triggerComp} />;
146+
return (
147+
<DropdownMenu
148+
items={filteredItems}
149+
trigger={triggerComp}
150+
isMainMenu={isMainMenu}
151+
/>
152+
);
144153
}
145154

146155
export default ResourceContextMenu;

0 commit comments

Comments
 (0)