Skip to content

Commit

Permalink
Hide captions in galleries when opening lightbox
Browse files Browse the repository at this point in the history
  • Loading branch information
artemiomorales committed Jul 17, 2024
1 parent 72b3688 commit 40c28b9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/block-library/src/image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ function block_core_image_render_lightbox( $block_content, $block ) {
JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP
)
);
$p->set_attribute( 'data-wp-class--hide-content', 'state.isContentHidden' );
$p->set_attribute( 'data-wp-class--show-content', 'state.isContentVisible' );

// Image.
$p->next_tag( 'img' );
Expand All @@ -230,8 +232,6 @@ function block_core_image_render_lightbox( $block_content, $block ) {
// contain a caption, and we don't want to trigger the lightbox when the
// caption is clicked.
$p->set_attribute( 'data-wp-on-async--click', 'actions.showLightbox' );
$p->set_attribute( 'data-wp-class--hide', 'state.isContentHidden' );
$p->set_attribute( 'data-wp-class--show', 'state.isContentVisible' );

$body_content = $p->get_updated_html();

Expand Down
20 changes: 17 additions & 3 deletions packages/block-library/src/image/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,29 @@
max-width: 100%;
vertical-align: bottom;
box-sizing: border-box;
}

@media (prefers-reduced-motion: no-preference) {
&.hide {
@media (prefers-reduced-motion: no-preference) {
&.hide-content {
img {
visibility: hidden;
}
figcaption {
.wp-block-gallery & {
visibility: hidden;
}
}
}

&.show {
&.show-content {
img {
animation: show-content-image 0.4s;
}
figcaption {
.wp-block-gallery & {
animation: show-content-image 0.4s;
}
}
}
}

Expand Down

0 comments on commit 40c28b9

Please sign in to comment.