Menu keyboard navigation broken in demos #16444
Labels
component: menu
This is the name of the generic UI component, not the React module!
component: Paper
This is the name of the generic UI component, not the React module!
v4.x
In #15901, the Menu demos were changed to use the
keepMounted
property. This breaks the auto-focus functionality inMenuList
since it is then mounted before it is open and thefocus
call happens on mount.Expected Behavior 🤔
After opening the menu in the Simple Menu demo (and other menu demos), the arrow keys should change menu item focus.
Current Behavior 😯
After opening the menu, focus is on the
Paper
element that wraps theMenuList
ul and the arrow keys have no effect. Hitting tab after opening the menu moves the focus from thePaper
to theMenuList
and then the arrow keys work as intended.Steps to Reproduce 🕹
Link: https://codesandbox.io/s/material-demo-3obkw
Your Environment 🌎
Possible Resolution
The easiest fix is to remove the
keepMounted
prop from the demo. I'm not sure what the reason was for adding it. Of course, ideally we would fixMenu
such that theautoFocus
works even with thekeepMounted
prop. I think this could be achieved by only specifyingautoFocus
(on MenuList or MenuItem) whenopen
istrue
. Sincefocus
is called whenautoFocus
changes to true (in addition to on mount whenautoFocus=true
), this should take care of the problem.The text was updated successfully, but these errors were encountered: