-
Notifications
You must be signed in to change notification settings - Fork 34
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
Focus of menu button on close seems incorrect. #55
Comments
Maybe it should only re-focus the button on |
From the Headless UI documentation on the Menu: > Clicking the `MenuButton` toggles the menu and focuses the `MenuItems` component. Using the focus trap here is a little unintuitive, because the menu item elements themselves are not focusable. However, this is a useful approach because * Focus should be locked within the menu anyway, per the accessibility requirements of a menu * Focus needs to be returned to the previously-focused element when the menu closes, which the `focus-trap` modifier will do for us The documentation for the `focus-trap` library describes how you should handle a case where the element that focus is trapped within has no focusable children, which is to focus the "wrapper" element itself using `initialFocus`, which is the approach taken here! Closes GavinJoyce#55
From the Headless UI documentation on the Menu: > Clicking the `MenuButton` toggles the menu and focuses the `MenuItems` component. Using the focus trap here is a little unintuitive, because the menu item elements themselves are not focusable. However, this is a useful approach because * Focus should be locked within the menu anyway, per the accessibility requirements of a menu * Focus needs to be returned to the previously-focused element when the menu closes, which the `focus-trap` modifier will do for us The documentation for the `focus-trap` library describes how you should handle a case where the element that focus is trapped within has no focusable children, which is to focus the "wrapper" element itself using `initialFocus`, which is the approach taken here! Closes GavinJoyce#55
Both reasonable suggestions to me. Which do you prefer @alexlafroscia ? |
#58 fixes this by allowing a focus-trap on the |
When I click out side of the menu, say on another button, when the menu closes it sets focus back on the menu button whereas I'd expect the focus to remain on the element I just clicked on. I'm not clear if it makes sense to refocus the button at all. Maybe it does under some circumstances but unsure what they are. In short though, the example below doesn't make sense so there is some improvement that could be made:
In this screencast I'm doing the following:
Screen.Recording.2021-06-18.at.10.36.56.mov
I think the offending code is here:
ember-headlessui/addon/components/menu.js
Lines 35 to 37 in 57f3da1
The text was updated successfully, but these errors were encountered: