WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.42k stars 4.17k forks source link

Image block lightbox: do not overlay the image with a transparent button #55097

Closed afercia closed 11 months ago

afercia commented 1 year ago

Description

When an image block is set to open the image in the lightbox, a transparent button entirely overlays the image.

This button is necessary to open the modal dialog. However, it entirely overlays the image. With the current implementation I see a couple problems that I'd consider pretty serious.

1 The browsers contextual menu that opens on right-click is different depending on the browser in use.

This surprised me. I would have expected to always get the same contextual menu. I have no idea whether this is a browser bug or a 'feature'. Regardless:

Regardless which browser is right and which one is wrong, the current implementation triggers a behavior that breaks am expected browsers feature. Also, the user experience is pretty confusing in at least two of the major browsers:

2 There is no visual indication at all that the image can be enlarged in a modal dialog

Visually, the image with the lightbox looks exactly like a normal image. There's no visual indication or any other hint to communicate that the image can be clicked and enlarged in the lightbox. The only subtle visual indications are only visible when hovering or tabbing:

Seems to me both cases are insufficient indications.

Step-by-step reproduction instructions

Screenshots, screen recording, code snippet

In the screenshots below, I altered the transparent button to better illustrate the issue:

macOS Chrome and Opera: right-click on the image shows the image contextual menu, as expected:

chrome opera 01

macOS Chrome and Opera: right-click on the button shows the image contextual menu, this is not expected:

chrome opera 02

macOS Firefox and Safari: right-click on the image shows the image contextual menu, as expected:

firefox safari 01

macOS Firefox and Safari: right-click on the button shows the button contextual menu, as expected:

firefox safari 02

Proposal

I'd think the simplest and most effective solution would be to just not entirely overlay the transparent button over the image. A visible button with an appropriate icon and labelling (preferably an icon + visible text for a11y reasons) would solve both issues:

I think a button in the top right is a pretty common pattern I've seen being used around on the web. Basically, a button placed in the red spot highlighted in the screenshot below:

Screenshot 2023-10-03 at 16 28 13

Ideally, the buton should have visible text:

Enlarge {icon here}

In all cases, the button size should be at least 44 by 44 pixels.

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

afercia commented 1 year ago

One more reason why overlaying the transparent button over the image is less than ideal, it's that there's no guarantee the image will be actually rendered with the same size of the figure element. Some themes do actually alter the original image size depending on the alignment settings.

For example, Twenty Sixteen does it. It uses negative margins. As such, the transparent button may overlay only a part of the image, so clicking on the rest of the visible image doesn't do anything. Other themes may do crazy things with images and seems to me there's absolutely no guarantee the button will overlay the image correctly.

In the screenshot below, I highlighted the transparent button with a red background and some opacity to better illustreate. - - Areas of the page that look empty but are actually clickable are very confusign and something we should really avoid.

I think the positioning of the button would be way simpler and more reliable if it as just a normal button overlaid in one of the image corners.

Screenshot from Twenty Sixteen:

localhost_8889_2023_09_lightbox-test_

afercia commented 1 year ago

Overall, I think this is something that should be prioritized for the incoming release. Cc @annezazu for consideraing some high priority.

afercia commented 1 year ago

One more feature that will break with the lightbox is the image title attribute.

Although title attributes aren't great as they're only available to some users, the editor gives the ability to add a title attribute to images. The title attribute is expected to show on hover in a native browseer 'tooltip'.

Given the image is entirely overlaid with a transparent button, the actual hover happens on the button: browsers won't show any tooltip. To reproduce:

artemiomorales commented 1 year ago

Pinging @jasmussen @SaxonF @jameskoster for feedback.

artemiomorales commented 1 year ago

Here I'll post previous feedback regarding the image and lightbox trigger to inform the current discussion:

To summarise, and https://github.com/WordPress/gutenberg/pull/49621#issuecomment-1509040080, while the interaction might seem simple and straightforward, and the user experience not that of a typical modal dialog, semantically it essentially just that. Which means we should be careful to provide appropriate functionality.

Any trigger that opens the image overlay should (semantically) present as a button, and be labelled appropriately to explain what it does. This means we cannot use the image itself as the trigger, because that should (semantically) present as an image, and have a label reflecting what it actually is ('alt text').

We could hide the trigger button until it receives focus, or the image is hovered, but that brings its own discovery issues and cognitive accessibility questions. Ideally it would be present at all times.

artemiomorales commented 1 year ago

@afercia How about if we put the button into the corner as you've suggested, but only make it available on focus and on hover?

I understand that this approach introduces its own discoverability issues, but it also seems like a reasonable compromise between maintaining a minimal UI, keeping things accessible, and preserving browser behavior.

Thanks for putting together this well-detailed issue and catching these scenarios by the way. We've put in a good amount of work to get the button to render correctly in many, but apparently not all, cases, and it appears the full button overlay is not the best approach.

afercia commented 1 year ago

How about if we put the button into the corner as you've suggested, but only make it available on focus and on hover?

The discoverability problem is in my opinion pretty important. Without any visual hint that the image can be enlarged in a lightbox, how I'm supposed (as a user) to understand the presence of such a feature?

Also, as said earlier, on touch devices there's no hover.

Im not sure I understand what is the advantage with hiding the button. A 'minimal' UI is nice to hav ebut should never come at the expense of user experience. In design, form should follow function, not the other way around.

jasmussen commented 1 year ago

I would echo Artemio's suggestion that a button visible on hover can be a solution. This works well for Substack. The zoom cursor on mouseover instead of the hand cursor provides sufficient context.

Poliuk commented 1 year ago

How about if we put the button into the corner as you've suggested, but only make it available on focus and on hover?

The discoverability problem is in my opinion pretty important. Without any visual hint that the image can be enlarged in a lightbox, how I'm supposed (as a user) to understand the presence of such a feature?

This is, of course, my personal opinion, but I don't think discoverability is such a big deal for a feature like this. Other relevant platforms like Medium or Substack already have an "expand on click" for images, and many people are familiar with this feature.

It's not as if we were launching a never-seen-before feature. For those who are not familiar, I think that the feature is simple enough to get discovered as they browse, and even for the small minority that will learn how to use it later, their UX won't get deeply impacted before they learn.

artemiomorales commented 1 year ago

Thanks all for the input! I’ve thought about this a bit more, and have some additional reflections.

The discoverability problem is in my opinion pretty important. Without any visual hint that the image can be enlarged in a lightbox, how I'm supposed (as a user) to understand the presence of such a feature?

@afercia WordPress allows users to configure links on images, and images are commonly clickable as links throughout the web, including on news websites, site logos, and advertisements. These images as links don’t contain any visual indication to show they’re interactable aside from being able to receive focus and the cursor showing as a pointer when they’re hovered over.

I think a lightbox button then, appearing on hover and on focus, offers the same level of discoverability as in the above cases.

Im not sure I understand what is the advantage with hiding the button. A 'minimal' UI is nice to hav ebut should never come at the expense of user experience. In design, form should follow function, not the other way around.

Thinking of non-technical users who are, in my experience, often overwhelmed by the number of elements on web pages, I think it also makes sense to hide the UI for something that’s not immediately necessary.

There are many different kinds of use cases, but if we take news websites and blogs as an example, the primary function here is to deliver a seamless reading experience. I’d consider that having a small visual obstruction on every image would actually draw attention to itself and away from the content and an image's composition, in particular if we’re considering photography or artwork.

Also, as said earlier, on touch devices there's no hover.

Here we start dealing with tradeoffs. Having a button always visible on mobile overlaid on the image, to the above point, especially one that's large enough to be easily interacted with, could distract from the composition of the image, and I believe having other always-visible UI just on mobile strictly for images would also distract from the experience of consuming the content.

I would echo Artemio's suggestion that a button visible on hover can be a solution. This works well for Substack. The zoom cursor on mouseover instead of the hand cursor provides sufficient context.

@jasmussen Ok got it 👍 I’ve gone ahead and opened a PR.

Happy to hear further thoughts on any of this! 😄 🙏