-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
Size Change: +1.01 kB (+0.06%) Total Size: 1.75 MB
ℹ️ View Unchanged
|
Flaky tests detected in 40c28b9. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9980916405
|
@@ -191,6 +191,7 @@ function block_core_image_render_lightbox( $block_content, $block ) { | |||
'data-wp-context', | |||
wp_json_encode( | |||
array( | |||
'animationId' => uniqid(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to set a unique value in the context to make sure we only hide the content image that is currently being clicked. Is uniqid()
a good way to do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is more like unique id of the image, better name would be imageId
.
It is being introduced in this change https://github.com/WordPress/gutenberg/pull/63348/files#diff-1e4aa29ea183efda9c795271dc1acf6e8049355db104d0dca5b0ea5caf7f619cR218
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imageId
is also an existing attribute, so I would recommend using something more tied to the behavior of the overlay that is getting animated.
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes tests great. Double image or a blink while switching between visible states isn't observed.
🚢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, but let's wait until this other pull request is merged and do this one on top:
Additionally, let's try to reuse the unique ID that we are already generating in that pull request.
The pull request that adds unique ids to the images has already been merged: @artemiomorales, can you refactor this pull request on top of the other and see if we can use the unique id we are already generating? |
39fe590
to
72b3688
Compare
@luisherranz Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be working on my testing 🙂 I just left a couple of small comments to understand it better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works good with image and gallery block.
Not directly related to this,
Observed a small issue with images that have a caption, in a gallery block.
There is a slight shadow left on the background.
Steps:
- Add a gallery block and set captions for few images.
- Set the scroll position of the page to a place where image bottom is near window bottom.
- Now click on the image (with caption)
- Observe that there is a shadow in place of original image.
Was this introduced in this pull request or did it exist before? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested it, but codewise it looks good to me 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this introduced in this pull request or did it exist before?
@luisherranz @madhusudhand Previously, the caption faded out at the same rate as the duplicate image, so it wasn't an issue. Effectively, this pull request is introducing the problem.
I've updated the code, putting the class name on the parent figure
instead. I've also highlighted part of the fix below, though I'm unsure if this is the best approach. Would appreciate any feedback 🙏
lightbox-gallery-caption-fix.mp4
@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; | ||
} | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
- When the caption overlays the image
- 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 👍
This reverts commit 40c28b9.
@madhusudhand @gziolo @SantosGuillamot I opened a new issue to continue the discussion regarding the caption behavior. |
…ress#63381) * Hide content image when lightbox is opened * Handle duplicate image when closing lightbox as well * Remove styling for prefers reduced motion * Rename state getters * Hide captions in galleries when opening lightbox * Revert "Hide captions in galleries when opening lightbox" This reverts commit 40c28b9.
What?
This PR hides the duplicate image that shows when the lightbox is opened, reported in #55960
Why?
It's a better user experience if the image is not duplicated.
How?
It sets the visibility to
hidden
on the content image when the lightbox is opened, and uses CSS keyframes to set the visibility back tovisible
at the appropriate time when the lightbox is closed.Testing Instructions
Expand on Click
Please also test on mobile and in different browsers.
Screenshots or screencast
Before
lightbox-duplicate-image-bug.mp4
After
lightbox-duplicate-image-fix.mp4