Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DropDownMenu] TabIndex, Close on ESC, Emitting button label #3558

Closed
sburgess8 opened this issue Mar 2, 2016 · 8 comments
Closed

[DropDownMenu] TabIndex, Close on ESC, Emitting button label #3558

sburgess8 opened this issue Mar 2, 2016 · 8 comments
Labels

Comments

@sburgess8
Copy link
Contributor

First off, thanks for your hard work on this project, it's really incredible.

Keyboard behavior differs between DropDownMenu and IconMenu.

In IconMenu, we can tab to an IconMenu in the DOM. Then by hitting spacebar the menu opens and we are able to move through the indices there. Then, upon hitting ESC the menu closes and we are returned to the TabIndex of the menu icon in the page.

In DropDownMenu, we can't select the menu by tabbing through the page nor can we close the menu by hitting escape. In addition, we can't create a custom label for the DropDownMenu emitting button that is not one of the options in the menu. This common use case is shown in the Material Design spec here (second one down): https://www.google.com/design/spec/components/menus.html# . I worked around this by making the first MenuItem disabled as setting that and the default option.

I'd like to request that we make the behavior of DropDownMenu the same as IconMenu. What would be even better is if we could choose to turn off or change this behavior through the use of a prop. Since devs don't have access to open and close these menus programmatically, it would be yugely useful to provide an interface via props. It may be as simple as saying "<DropDownMenu closeOnEsc={ false } />". If not that, providing a way to programmatically open and close the menu using a ref would be useful.

DropDownMenu getting keyboard focus has been requested before here: #714 (comment)
"When tabbing through a form or page and the tab order shifts onto a Drop Down menu it should get focus"

This was said to be fixed here: #846 but does not provide that functionality.

DropDownMenu is not selectable by tabbing and can't be closed by hitting ESC. It is not a feature to be able to use a dropdown with a custom label for the menu emitting button as specified in the Material Design spec.
http://www.material-ui.com/#/components/dropdown-menu

IconMenu is selectable by tabbing and can be closed by hitting ESC: http://www.material-ui.com/#/components/icon-menu

Thank you.

@mbrookes
Copy link
Member

mbrookes commented Mar 2, 2016

Sounds like you have this all figured out. Please submit a PR! 👍

@chrismcv
Copy link
Contributor

chrismcv commented Mar 3, 2016

How does #3583 work in this context? It focusses on <SelectField /> but mainly uses <DropdownMenu /> to fix it.

@sburgess8
Copy link
Contributor Author

It doesn't but I will be sure to refer to what you did working on this PR. Thanks.

@tintin1343
Copy link
Contributor

@sburgess8 : Has this issue resolved for you by using the above PR suggestion? Do let us know.

@stephenburgess8
Copy link

Thanks for your interest. #3583 does not solve the issue of dropdown menus being accessible in the tab index of a page. This issue is preventing our adoption of this component. I have not compared the DropDownMenu vs IconMenu vis a vis tabbing since the most recent major refactor. I will include it on my todo list to investigate and hopefully work on a PR in the near future.

@tintin1343
Copy link
Contributor

tintin1343 commented Apr 22, 2016

Cool. Do share your observations. Thanks!

@caesay
Copy link

caesay commented Aug 5, 2016

I've taken a stab at implementing this (see the change list at my fork).

You can:

  • Navigate to, and see the focus state of SelectField / DropDownMenu.
  • Use space to open, esc to close menu, or enter to select an item.
  • Set a custom label (pretty sure you can just use a SelectField with a hint text for this)

Before I open a PR, there's a weird bug though in the context of SelectField. When the popover closes via the keyboard, I re-focus the DropDownMenu (see here) so you maintain the tab position. The item properly gets focused for a moment, but then this causes a blur event (?) on the containing TextField, which does a setState, which for some reason causes the <body> to take focus (maybe the DropDown DOM element is being removed temporarily?). This line (TextField#L350) is the culprit - comment it out and the DropDownMenu retains focus properly.

Can anyone provide some feedback as to why the DropDownMenu might loosing focus when TextField does a setState and what I can do about it?

@smeijer
Copy link

smeijer commented Jan 12, 2017

Is there any progress on this? Not being able to select a form component with tab, is a no-go for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants