Repository navigation
Conversation
The menu prevents the default action of Enter and Space, so selecting an item from the keyboard never reached the element itself. Links inside ngMenuItem didn't navigate and (click) listeners on the item didn't run, while the same item worked fine with a mouse. Click the item's element before submitting so keyboard and pointer activation behave the same. The synthetic click is ignored by the menu's own click handler so the item isn't submitted twice. Fixes angular#34072
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 #34072
The menu's keyboard manager prevents the default action for Enter and Space, and
MenuPattern.trigger()only calledsubmit(). So with the keyboard the item's element was never activated:<a ngMenuItem href>didn't navigate and a(click)listener on the item didn't run. Both work with the mouse because the real click happens before the menu handles it.trigger()now callselement.click()on the active item (when it's enabled and doesn't open a submenu) and then submits, which is the same order a pointer click goes through. The synthetic click bubbles up to the menu's(click)host listener, soonClickignores clicks while the item is being activated. Otherwise the item would be submitted twice and focus would jump back into the menu.Items with a submenu still just open the submenu, and disabled items still do nothing.
Tests
private/menu/menu.spec.ts: Enter/Space clicks the element. A click that reachesonClickdoesn't select twice. No click for disabled or submenu itemsmenu/menu.spec.ts: with the trigger example, Enter on Apple fires one click on the item, emitsitemSelectedonce and closes the menuWithout the
menu.tschange, the two click tests fail (Expected spy click to have been called once. It was called 0 times.).Manual check
I used the reporter's repro (https://github.com/artaommahe/aria-menu-repro, section B). Its
check.mjswith the change applied to 22.2.6:Before (22.2.6): Enter on the link leaves the hash empty and the (click) log stays empty
After: the hash is
#targetand "(click) ran" shows up in the logOne thing I left alone: top-level items in a
ngMenuBarthat don't have a submenu go throughMenuBarPattern, which doesn't submit on Enter at all. That seemed like a separate change, but I'm happy to fold it in here if you'd prefer.