Skip to content

Commit

Permalink
Image: Fix Lightbox display bug in Classic Themes. (#54837)
Browse files Browse the repository at this point in the history
* If current theme is not a block theme add a default value for $background_color and $close_button_color.

* Set lightbox buttons' background & border to none on hover & focus

* Change logic to support lightbox in classic themes

* Update logic to avoid unnecessary calls

* Add style fixes

* Remove unnecessary code

* Fix close button color

---------

Co-authored-by: Mario Santos <santosguillamot@gmail.com>
Co-authored-by: Ricardo Artemio Morales <ric.morales22@gmail.com>
  • Loading branch information
3 people authored Oct 5, 2023
1 parent af6cb47 commit 9ef96c5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/block-library/src/image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,22 @@ function block_core_image_render_lightbox( $block_content, $block ) {
$q->set_attribute( 'data-wp-style--object-fit', 'selectors.core.image.lightboxObjectFit' );
$enlarged_image_content = $q->get_updated_html();

$background_color = esc_attr( wp_get_global_styles( array( 'color', 'background' ) ) );
// If the current theme does NOT have a `theme.json`, or the colors are not defined,
// we need to set the background color & close button color to some default values
// because we can't get them from the Global Styles.
$background_color = '#fff';
$close_button_color = '#000';
if ( wp_theme_has_theme_json() ) {
$global_styles_color = wp_get_global_styles( array( 'color' ) );
if ( ! empty( $global_styles_color['background'] ) ) {
$background_color = esc_attr( $global_styles_color['background'] );
}
if ( ! empty( $global_styles_color['text'] ) ) {
$close_button_color = esc_attr( $global_styles_color['text'] );
}
}

$close_button_icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="15" height="15" 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>';
$close_button_color = esc_attr( wp_get_global_styles( array( 'color', 'text' ) ) );
$dialog_label = $alt_attribute ? esc_attr( $alt_attribute ) : esc_attr__( 'Image' );
$close_button_label = esc_attr__( 'Close' );

Expand Down
14 changes: 14 additions & 0 deletions packages/block-library/src/image/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@
outline: 5px auto -webkit-focus-ring-color;
outline-offset: 5px;
}

&:hover,
&:focus,
&:not(:hover):not(:active):not(.has-background) {
background: none;
border: none;
}
}
}

Expand All @@ -191,6 +198,13 @@
padding: 0;
cursor: pointer;
z-index: 5000000;

&:hover,
&:focus,
&:not(:hover):not(:active):not(.has-background) {
background: none;
border: none;
}
}

.lightbox-image-container {
Expand Down

1 comment on commit 9ef96c5

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 9ef96c5.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6416668533
📝 Reported issues:

Please sign in to comment.