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

Image lightbox: Remove duplicate image when lightbox is opened #63381

Merged
merged 6 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 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 Down
36 changes: 36 additions & 0 deletions packages/block-library/src/image/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,30 @@
box-sizing: border-box;
}

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm unsure if we should put the styles to hide/show the caption here or in the gallery styles. My inclination is to put them here because we need to animate the caption with the same timing as the image. What do you think?

Note that we need to restrict these caption styles to the gallery to prevent hiding captions in other circumstances when they don't overlay the image.

Copy link
Contributor

Choose a reason for hiding this comment

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

What is the desired behavior with captions here? Should they be handled different for gallery vs normal images?

Right now this is how galleries are working in this pull request:

Lightbox.lightbox.-.18.July.2024.mp4

And this is how normal images work:

Lightbox.caption.1.mp4

This is how they would work if we hide the caption as in the galleries:

Lightbox.gallery.mp4

So, what is the expected UX? Should we even add a "fade-in" effect for the caption as well?

Copy link
Member

Choose a reason for hiding this comment

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

It is a separate issue to handle the captions correctly. I'm also wondering what the rationale was for omitting the caption in the expanded image. There are reports that the caption should be included for legal reasons on some websites #60469 (comment). So that at least should be an option to configure for the lightbox.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, what is the expected UX? Should we even add a "fade-in" effect for the caption as well?

Ok got it, so we need to account for the caption in galleries in two scenarios:

  1. When the caption overlays the image
  2. When the caption does not overlay the image

I only took into account the first issue, not the second.

In the first scenario, like in the latest fix, I think we could make the caption disappear immediately when the lightbox opens, then make it reappear at the proper time when the lightbox is closed. We could also introduce a fade and sequence it properly with the zooming animation to make it more elegant.

For the second scenario, the caption should fade out and fade in smoothly like the rest of the content outside of the image.

I'm also wondering what the rationale was for omitting the caption in the expanded image. There are reports that the caption should be included for legal reasons on some websites #60469 (comment). So that at least should be an option to configure for the lightbox.

I believe there was conversation with design that the experience of a single image lightbox doesn't require a caption because one already has the context to understand what's being displayed. This is in contrast to a lightbox gallery, in which you don't have as much context.

It is a separate issue to handle the captions correctly.

Ok, I'll revert the most recent change, merge, and open a separate issue 👍

// The following style maintains border radius application for deprecated
// image blocks that applied border radius to the outer `figure` element.
//
Expand Down Expand Up @@ -319,6 +343,18 @@
}
}

@keyframes show-content-image {
0% {
visibility: hidden;
}
99% {
visibility: hidden;
}
100% {
visibility: visible;
}
}

@keyframes turn-on-visibility {
0% {
opacity: 0;
Expand Down
15 changes: 14 additions & 1 deletion packages/block-library/src/image/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ const { state, actions, callbacks } = store(
const { imageId } = getContext();
return state.metadata[ imageId ].imageButtonTop;
},
get isContentHidden() {
const ctx = getContext();
return (
state.overlayEnabled && state.currentImageId === ctx.imageId
luisherranz marked this conversation as resolved.
Show resolved Hide resolved
);
},
get isContentVisible() {
const ctx = getContext();
return (
! state.overlayEnabled &&
state.currentImageId === ctx.imageId
);
},
},
actions: {
showLightbox() {
Expand All @@ -75,8 +88,8 @@ const { state, actions, callbacks } = store(
state.scrollLeftReset = document.documentElement.scrollLeft;

// Sets the current expanded image in the state and enables the overlay.
state.currentImageId = imageId;
state.overlayEnabled = true;
state.currentImageId = imageId;

// Computes the styles of the overlay for the animation.
callbacks.setOverlayStyles();
Expand Down
Loading