-
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
Get active element within the iframe when restoring focus #68060
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +10 B (0%) Total Size: 1.84 MB
ℹ️ View Unchanged
|
@@ -34,7 +30,6 @@ function ButtonBlockAppender( | |||
if ( onSelect && typeof onSelect === 'function' ) { | |||
onSelect( ...args ); | |||
} | |||
inserterButtonRef.current?.focus(); |
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.
This file is undoing work from https://github.com/WordPress/gutenberg/pull/64877/files#diff-4cdcf916fb8cf5f88b98cd9e95ab532d90369cd768334f7896720a2b85c018bbR37 which fixed moving focus to the appender, but did it without addressing the root issue.
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.
I had the thought that this could be recursive for nested iframes, but we probably don't need that for now.
Just had one suggestion for cleaner, more robust code.
Co-authored-by: Alex Lende <alex+github.com@lende.xyz>
Flaky tests detected in 0c834eb. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12398561057
|
Thanks for the fix! Would it be worth backporting this PR to WP 6.7.2? Because #67809 is an issue that first appeared in WP 6.7. |
…ocus (#68060) Co-authored-by: Alex Lende <alex+github.com@lende.xyz>
I think so, provided no bugs pop up as a result of it :) |
Fixes #67809
What?
useFocusReturn
doesn't work for items within the editor canvas iframe. Focus is sent to theiframe
canvas instead of the active element within it. This PR allows for focus to get restored to the active element within the canvas.Why?
This root focus loss issue has caused a lot of fragile hotfixes. After this is merged, we can remove them. Here's a list of ones I know about:
How?
The
useFocusReturn
hook stores theactiveElement
asfocusedBeforeMount.current
, and then when popover/modal/etc closes, it returns focus to thefocusedBeforeMount.current
.This works well unless the
activeElement
is within aniframe
(like the editor canvas). If the element is within aniframe
, then thefocusedBeforeMount.current
is set as the iframe itself, not theactiveElement
within theiframe
.This PR checks to see if the
activeElement
is aniframe
and if theiframe
has anactiveElement
itself. If so, it sets theactiveElement
within theiframe
as thefocusedBeforeMount.current
.Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast