Repository navigation
Description
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
Pressing Escape while focus is in a submenu closes every open menu and moves focus back to the root ngMenuTrigger. MenuPattern maps Escape to closeAll():
components/src/aria/private/menu/menu.ts
Line 182 in 5856d87
| .on('Escape', () => this.closeAll()) |
The WAI-ARIA Authoring Practices menu pattern specifies one level: "Escape: Close the menu that contains focus and return focus to the element or context, e.g., menu button or parent menuitem, from which the menu was opened." (https://www.w3.org/WAI/ARIA/apg/patterns/menubar/). The APG navigation menubar example behaves that way.
The other Angular menus already do: @angular/cdk/menu closes only the current menu and focuses its parent trigger (
components/src/cdk/menu/menu.ts
Lines 84 to 90 in 5856d87
| case ESCAPE: | |
| if (!hasModifierKey(event)) { | |
| event.preventDefault(); | |
| this.menuStack.close(this, { | |
| focusNextOnEmpty: FocusNext.currentItem, | |
| focusParentTrigger: true, | |
| }); |
mat-menu does the same. So a menu migrated from CDK or Material to @angular/aria changes keyboard behaviour.
If closing the whole tree is intended, an option to close one level would help, similar to Base UI's closeParentOnEsc.
Reproduction
StackBlitz link: https://stackblitz.com/github/artaommahe/aria-menu-repro
Repo: https://github.com/artaommahe/aria-menu-repro (section A; node check.mjs runs the steps with Playwright)
Steps to reproduce:
- Tab to "Open menu A" and press Enter.
- ArrowDown to "Categorize" and press ArrowRight. The submenu opens with focus on "Mark as important".
- Press Escape.
Expected Behavior
Only the submenu closes. Focus returns to "Categorize", and the root menu stays open.
Actual Behavior
Both menus close and focus returns to the "Open menu A" trigger.
Environment
- Angular: 22.2.4
- CDK/Material: 22.2.6 (@angular/aria 22.2.6)
- Browser(s): Chromium 156
- Operating System (e.g. Windows, macOS, Ubuntu): macOS
This issue was drafted and filed by Claude Code (an AI coding agent) on behalf of artaommahe.
Activity