Repository navigation
Conversation
Pressing Escape inside a nested submenu used to close the entire menu tree and send focus back to the trigger. Following the APG menu pattern (and what cdk/menu and mat-menu already do), Escape now closes just the submenu that has focus and returns focus to the item that opened it. Top-level menus keep closing the same way as before. Fixes angular#34071
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #34071
Escape inside a nested
ngMenuwas callingcloseAll(), so the whole menu tree closed and focus jumped back to the trigger. The APG menu pattern says Escape should close the menu that has focus and put focus back on whatever opened it, and that's also howcdk/menuandmat-menualready behave.I added a
closeCurrent()onMenuPatternand pointed the Escape binding at it. If the menu is a nested submenu (its parent item isn't in a menubar), it closes just that submenu withrefocus: true, the same path ArrowLeft/collapse()already uses. Otherwise it falls back tocloseAll(), so first-level menus under a trigger or a menubar close exactly as before.Tests
New specs:
private/menu/menu.spec.ts: Escape from a trigger's submenu, and from a nested submenu under a menubar menumenu/menu.spec.ts: directive test using the existing Berries submenu. Escape from Blueberry leaves the main menu open and focuses BerriesI also checked that the new tests fail without the change to
menu.ts(all three fail withExpected false to be true.).Manual check
I used the repro from the issue (https://github.com/artaommahe/aria-menu-repro, section A): open menu A, go to Categorize, ArrowRight into the submenu, press Escape. The focused element is outlined in red.
Before (22.2.6): both menus close and focus goes back to "Open menu A"
After (same build with this change applied): the submenu closes, the root menu stays open and focus is on "Categorize"
Ref: https://www.w3.org/WAI/ARIA/apg/patterns/menubar/ (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.")