Skip to content

Commit

Permalink
Ensure we only prevent default for events that we handle
Browse files Browse the repository at this point in the history
  • Loading branch information
paustint committed Dec 8, 2024
1 parent 0b29ebd commit f83e251
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions libs/ui/src/lib/form/context-menu/ContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
isArrowUpKey,
isEnterKey,
isEscapeKey,
isSpaceKey,
menuItemSelectScroll,
selectMenuItemFromKeyboard,
} from '@jetstream/shared/ui-utils';
Expand Down Expand Up @@ -87,8 +88,11 @@ export const ContextMenu: FunctionComponent<ContextMenuProps> = ({ parentElement
}, [focusedItem, items, selectedItem]);

function handleKeyDown(event: KeyboardEvent<HTMLAnchorElement>) {
event.preventDefault();
event.stopPropagation();
if (isEscapeKey(event) || isArrowUpKey(event) || isArrowDownKey(event) || isEnterKey(event) || isSpaceKey(event)) {
event.preventDefault();
event.stopPropagation();
}

let newFocusedItem;

if (isEscapeKey(event)) {
Expand All @@ -108,7 +112,7 @@ export const ContextMenu: FunctionComponent<ContextMenuProps> = ({ parentElement
} else {
newFocusedItem = focusedItem + 1;
}
} else if (isEnterKey(event) && isNumber(focusedItem)) {
} else if ((isEnterKey(event) || isSpaceKey(event)) && isNumber(focusedItem)) {
const item = items[focusedItem];
if (!item.disabled) {
setSelectedItem(item);
Expand Down

0 comments on commit f83e251

Please sign in to comment.