-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 focus loss happening when installing blocks from the directory #40340
Conversation
Size Change: +19 B (0%) Total Size: 1.23 MB
ℹ️ View Unchanged
|
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.
Thanks Riad! Looks good!
I'm not 100% sure it's an issue with the plugin as of today. It sounds more specific to React 18. Anyway, we can backport all 3 fixes if @youknowriad confirms, we should include it in WordPress 6.0 Beta 2. |
I think it's not crucial to backport these fixes because they're not "very" visible unless you use React 18 but they're small fixes anyway. I'm ok without backporting them :) |
This was cherry-picked to |
Extracted from #32765
What?
For some reason, in the React 18 upgrade PR #32765,
useFocusOutside
works better than trunk (I don't know why yet). Which means there were some failing e2e tests that actually show real bugs we have on trunk, more precisely "focus loss" bugs.One of them is in the inserter when installing blocks from the directory: On trunk, on chrome, you can try installing a block from there, you'll notice that when you click a block, the button becomes disabled and the focus is lost (but for some reason the inserter remains open).
This PR solves the focus loss.
Why?
Focus loss is an a11y issue even if the inserter is kept open right now.
How?
We already have a solution for buttons that switch from enabled to disabled to avoid focus loss. We rely on
aria-disabled
instead of really disabling the buttons which keeps the button focusable even if it's disabled temporarily. The button component has a dedicated__experimentalIsFocusable
for these use-cases. We may consider making this API stable separately.Testing Instructions
1- Open the inserter
2- Search for a block in the directory (like masonry)
3- Click the button
4- The focus should stay in the button during and after the installation completes and the inserter stays open.
(We already have an e2e test that covers this but it's passing in trunk because of the mystery bug in useFocusOutside, it will start failing in the React 18 upgrade if we do nothing :) )