Repository navigation
Image Block: Get lightbox trigger button ref via data-wp-init - #57089
Merged
Merged
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
|
Member
Yeah, that is perfectly fine 🙂 |
michalczaplinski
approved these changes
Dec 18, 2023
michalczaplinski
left a comment
Contributor
There was a problem hiding this comment.
Totally makes sense.
Thanks @t-hamano ! 🙂
Contributor
Author
|
Thanks for the review, @luisherranz, @michalczaplinski! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #56541
What?
This PR uses the
wp-initdirective to get therefof 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 theimgelement 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
querySelectorvia thewp-initdirective 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/imagehook, 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-initdirective 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-initdirective 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.
Tabkey to focus on the trigger button at the top right of the image block.Enterkey to open Lightbox.Escapekey to close the Lightbox.Screenshots or screencast
c1dc680d3e8770c01b171010098c8921.mp4