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 and mikachan committed Oct 5, 2023
1 parent d0630d0 commit ae40d77
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

0 comments on commit ae40d77

Please sign in to comment.