-
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
Enabling lightbox on images in a Gallery block breaks the gallery layout #51068
Comments
cc @luisherranz |
Thanks @ndiego. I was worried that extra @artemiomorales, what do you need to get rid of it? Can you place the directives directly in the |
@luisherranz I think it's possible to get rid of it. But to do so, we'd need to use the Tag Processor to place the directives directly on the Here is the lightbox markup; the <div class="wp-lightbox-container"
data-wp-island
data-wp-context='{ "core": { "image": { "initialized": false, "lightboxEnabled": false } } }'>
$body_content
<div data-wp-body="" class="wp-lightbox-overlay"
data-wp-bind.role="selectors.core.image.roleAttribute"
aria-label="$dialog_label"
data-wp-class.initialized="context.core.image.initialized"
data-wp-class.active="context.core.image.lightboxEnabled"
data-wp-bind.aria-hidden="!context.core.image.lightboxEnabled"
data-wp-bind.aria-modal="context.core.image.lightboxEnabled"
data-wp-effect="effects.core.image.initLightbox"
data-wp-on.keydown="actions.core.image.handleKeydown"
data-wp-on.mousewheel="actions.core.image.hideLightbox"
data-wp-on.click="actions.core.image.hideLightbox"
>
<button type="button" aria-label="$close_button_label" class="close-button" data-wp-on.click="actions.core.image.hideLightbox">
$close_button_icon
</button>
$content
<div class="scrim" style="background-color: $background_color"></div>
</div>
</div> And by the time the lightbox logic runs inside of the function render_block_core_image( $attributes, $content ) {
$processor = new WP_HTML_Tag_Processor( $content );
/// ... Lightbox code continues here
} Options:
I'm inclined to take option 4 and even start exploring solutions for the lightbox gallery relatively soon. Thoughts? |
Asking from a lack of knowledge: cannot we just use the Tag Processor to add the directives to the figure parsing the I mean at this point adding something like this: $content = $processor->get_updated_html();
$w = new WP_HTML_Tag_Processor( $content );
$w->next_tag(
array(
'tag_name' => 'FIGURE',
)
);
$w->add_class( 'wp-lightbox-container' );
$w->set_attribute( 'data-wp-island', '' );
$w->set_attribute( 'data-wp-context', '{ "core": { "image": { "initialized": false, "lightboxEnabled": false } } }' );
$content = $w->get_updated_html(); Then the HTML returned could remain the same and just remove the parent <<<HTML
$body_content
<div data-wp-body="" class="wp-lightbox-overlay"
data-wp-bind.role="selectors.core.image.roleAttribute"
aria-label="$dialog_label"
data-wp-class.initialized="context.core.image.initialized"
data-wp-class.active="context.core.image.lightboxEnabled"
data-wp-bind.aria-hidden="!context.core.image.lightboxEnabled"
data-wp-bind.aria-modal="context.core.image.lightboxEnabled"
data-wp-effect="effects.core.image.initLightbox"
data-wp-on.keydown="actions.core.image.handleKeydown"
data-wp-on.mousewheel="actions.core.image.hideLightbox"
data-wp-on.click="actions.core.image.hideLightbox"
>
<button type="button" aria-label="$close_button_label" class="close-button" data-wp-on.click="actions.core.image.hideLightbox">
$close_button_icon
</button>
$content
<div class="scrim" style="background-color: $background_color"></div>
</div>
HTML; Wouldn't an approach similar to this work? I guess it would also need some CSS changes if the parent EDIT: Oh okay, I just realized that we are missing a wrapper and that can be an issue. I think I understand your point now better. Maybe we can use something like the following and just return $body_content? $body_content = preg_replace( '/<\/figure>/', $lightbox_html . '</figure>', $body_content ); |
$body_content = preg_replace( '/<\/figure>/', $lightbox_html . '</figure>', $body_content ); This is what I was thinking as well, although I have the impression that we already tried that 🤔 Anyway, is this worth a try, @artemiomorales? |
Sure thing, pull request created here. It works as far as I can tell. I suppose it should work for most use cases, though would break if users say include the string |
Closed by #51089 |
Description
Enabling the new lightbox behavior on Image blocks inside of a Gallery block breaks the gallery's layout.
Step-by-step reproduction instructions
div
around eachfigure
.Screenshots, screen recording, code snippet
Editor:
Front end:
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: