-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fix Dropdown/DropdownMenu toggle closing in all UAs #31170
Conversation
Size Change: -4 B (0%) Total Size: 1.05 MB
ℹ️ View Unchanged
|
Changing the tabindex affects a11y so this will PR needs a11y feedback. Added the related tag 👍 |
@stokesman I came to the same conclusion in #30392. Could you rebase this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works great!
@diegohaz can you take a brief look as well? |
b67dbcf
to
4ff1e08
Compare
Thanks for reviewing @ellatrix! It's rebased with a comment like the suggested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ideal solution would be ignoring clicks on the toggle button when the popover is open (without using disabled
). But this looks like an easier workaround, so let's go for it for now.
Thanks for reviewing @diegohaz 🙇
Tricky since a |
* trunk: (74 commits) Update docs for ClipboardButton component (#34711) Post Title Block: add typography formatting options (#31623) Bump plugin version to 11.5.0 Navigation Screen: Adjust header toolbar icon styles (#34833) Fix the parent menu item field in REST API responses (#34835) Rewrite FocusableIframe as hook API (#26753) Create Block: Remove wp-cli callout since not recommended and outdated (#34821) Global Styles: Fix dimensions panel default controls display (#34828) [RNMobile][Embed block] Enable embed preview for Instagram and Vimeo providers (#34563) Increase Link UI search results to 10 on Nav Editor screen (#34808) Prevent welcome guide overflow x scroll (#34713) Enable open on click for Page List inside Navigation. (#34675) [RNMobile] [Embed block] - Unavailable preview fallback bottom sheet title update (#34674) Add missing field _invalid in menu item REST API (#34670) Fix Dropdown/DropdownMenu toggle closing in all UAs (#31170) Navigation submenu block: replace global shortcut event handlers with local ones (#34812) Navigation Screen: Consolidate menu name and switcher (#34786) Remove parent and position validation from menu item REST API endpoint (#34672) Clean theme data when switching themes in the customizer (#34540) Components: add reset timeout to ColorPicker's copy functionality. (#34601) ...
The Dropdown (and DropdownMenu) components have broken toggle behavior in some browsers (notably Safari and Firefox on macOS). Making the root element of the
Dropdown
component focusable makes its current toggling logic work as intended.Before this PR, I'd tried alternate approaches (#30397, #30786) that were not nearly as simple.
Explainer
The intended behavior depends on testing that the focused element is inside of the dropdown component:
gutenberg/packages/components/src/dropdown/index.js
Line 68 in 7453998
The UAs in which the current logic fails do not focus buttons when pressed. Instead, focus goes to the closest focusable containing element and ends up outside of the component. The change here ensures that focus won't leave the component and thus the current logic will work.
Extra
I threw in an extraneous but related change b67dbcf to remove a workaround that had been made due to the buggy dropdown behavior.
How has this been tested?
Manually in Chrome, Firefox and Safari on macOS. In the post editor and site editor, toggling all the dropdowns.
Types of changes
Bug fix #29746
Screenshots
Before: the broken toggling of various dropdowns in Safari on macOS.
dropdowns-in-safari.mp4
Checklist:
*.native.js
files for terms that need renaming or removal).