Skip to content
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

Bug fix: Vertical images in experimental lightbox #51164

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/block-library/src/image/index.php
Expand Up @@ -75,6 +75,13 @@ function render_block_core_image( $attributes, $content ) {
'</div>';
$body_content = preg_replace( '/<img[^>]+>/', $button, $body_content );

// Add directive to expand modal image if appropriate.
$m = new WP_HTML_Tag_Processor( $content );
$m->next_tag( 'img' );
$m->set_attribute( 'data-wp-context', '{ "core": { "image": { "imageSrc": "' . wp_get_attachment_url( $attributes['id'] ) . '"} } }' );
$m->set_attribute( 'data-wp-bind--src', 'selectors.core.image.imageSrc' );
$modal_content = $m->get_updated_html();

$background_color = esc_attr( wp_get_global_styles( array( 'color', 'background' ) ) );
$close_button_icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="30" height="30" aria-hidden="true" focusable="false"><path d="M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z"></path></svg>';

Expand All @@ -97,7 +104,7 @@ function render_block_core_image( $attributes, $content ) {
<button type="button" aria-label="$close_button_label" class="close-button" data-wp-on--click="actions.core.image.hideLightbox">
$close_button_icon
</button>
$content
$modal_content
<div class="scrim" style="background-color: $background_color"></div>
</div>
HTML;
Expand Down
6 changes: 6 additions & 0 deletions packages/block-library/src/image/interactivity.js
Expand Up @@ -89,13 +89,19 @@ store( {
roleAttribute: ( { context } ) => {
return context.core.image.lightboxEnabled ? 'dialog' : '';
},
imageSrc: ( { context } ) => {
return context.core.image.initialized
? context.core.image.imageSrc
: '';
},
},
},
},
effects: {
core: {
image: {
initLightbox: async ( { context, ref } ) => {
context.core.image.imageRef = ref.querySelector( 'img' );
if ( context.core.image.lightboxEnabled ) {
const focusableElements =
ref.querySelectorAll( focusableSelectors );
Expand Down
20 changes: 16 additions & 4 deletions packages/block-library/src/image/style.scss
Expand Up @@ -195,14 +195,26 @@
}

.wp-block-image {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
z-index: 3000000;
position: absolute;
z-index: 3000000;
box-sizing: border-box;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;

figcaption {
margin: 10px 0 0 0;
display: none;
}

img {
max-width: 100%;
max-height: 100%;
width: auto;
}
}

button {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/specs/editor/blocks/image.spec.js
Expand Up @@ -828,11 +828,11 @@ test.describe( 'Image - interactivity', () => {
const lightbox = page.locator( '.wp-lightbox-overlay' );
await expect( lightbox ).toBeHidden();

await page.getByRole( 'button', { name: 'Enlarge image' } ).click();

const image = lightbox.locator( 'img' );
await expect( image ).toHaveAttribute( 'src', new RegExp( filename ) );

await page.getByRole( 'button', { name: 'Enlarge image' } ).click();

await expect( lightbox ).toBeVisible();

const closeButton = lightbox.getByRole( 'button', {
Expand Down