Skip to content

bug(aria/menu): Escape inside a submenu closes the whole menu instead of only the submenu #34071

Open

Description

@artaommahe

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():

.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 (

case ESCAPE:
if (!hasModifierKey(event)) {
event.preventDefault();
this.menuStack.close(this, {
focusNextOnEmpty: FocusNext.currentItem,
focusParentTrigger: true,
});
), and 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:

  1. Tab to "Open menu A" and press Enter.
  2. ArrowDown to "Categorize" and press ArrowRight. The submenu opens with focus on "Mark as important".
  3. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions