Skip to content

Commit

Permalink
fix(menu): allow keyboard events to propogate from menu-items
Browse files Browse the repository at this point in the history
  • Loading branch information
TarunAdobe committed Oct 1, 2024
1 parent e14d082 commit f986c6d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/menu/src/Menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,21 +590,27 @@ export class Menu extends SizedMixin(SpectrumElement, { noDefaultSize: true }) {

protected navigateBetweenRelatedMenus(event: KeyboardEvent): void {
const { key } = event;
event.stopPropagation();

if (key === 'ArrowRight' || key === 'ArrowLeft') {
event.preventDefault();
}

const shouldOpenSubmenu =
(this.isLTR && key === 'ArrowRight') ||
(!this.isLTR && key === 'ArrowLeft');
const shouldCloseSelfAsSubmenu =
(this.isLTR && key === 'ArrowLeft') ||
(!this.isLTR && key === 'ArrowRight');
if (shouldOpenSubmenu) {
event.stopPropagation();
const lastFocusedItem = this.childItems[this.focusedItemIndex];
if (lastFocusedItem?.hasSubmenu) {
// Remove focus while opening overlay from keyboard or the visible focus
// will slip back to the first item in the menu.
lastFocusedItem.openOverlay();
}
} else if (shouldCloseSelfAsSubmenu && this.isSubmenu) {
event.stopPropagation();
this.dispatchEvent(new Event('close', { bubbles: true }));
this.updateSelectedItemIndex();
}
Expand Down

0 comments on commit f986c6d

Please sign in to comment.