-
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
Image Block: Get lightbox trigger button ref via data-wp-init #57089
Conversation
Size Change: -4 B (0%) Total Size: 1.71 MB
ℹ️ View Unchanged
|
Flaky tests detected in 8da2285. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7217756589
|
Yeah, that is perfectly fine 🙂 |
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.
Totally makes sense.
Thanks @t-hamano ! 🙂
Thanks for the review, @luisherranz, @michalczaplinski! |
Fixes #56541
What?
This PR uses the
wp-init
directive to get theref
of the image block's lightbox trigger button. As a result, as reported in #56541, the trigger button's ref can now be correctly retrieved even if theimg
element is wrapped with an element from somewhere else.Why?
The trigger button ref is used to solve focus issues in Firefox, as described in this comment. The current implementation attempts to locate this ref using
querySelector
via thewp-init
directive callback of the img element.This query operates on the assumption that the img element and the trigger button exist in parallel, so if the img element is wrapped with some element by the
render_block_core/image
hook, for example, the trigger button cannot be found.How?
In order to be able to obtain the trigger button ref more stably, I added
wp-init
directive to the trigger button itself, without relying on a query, and obtained the ref in its callback function. As a result, no matter what level the button is placed in, it should be possible to obtain the ref.However, I'm not sure if using the
wp-init
directive just to get the ref is a recommended implementation, so I would appreciate any advice on this point.Testing Instructions
Add the following hook to the gutenberg.php file to temporarily wrap the image block's img element with a picture element.
Tab
key to focus on the trigger button at the top right of the image block.Enter
key to open Lightbox.Escape
key to close the Lightbox.Screenshots or screencast
c1dc680d3e8770c01b171010098c8921.mp4