Skip to content

Image: fix focus management and accessibility of the Lightbox #55414

@afercia

Description

@afercia

Description

Follow-up to #55212

#55212 improved the Lightbox implementation by changing the button that overlid the entire image to a smaller button placed at the top right of the image. That's a welcome change that solves a couple important issues. It also introduced a different implementation of focus handling of the modal dialog that needs to be fiexed.

Please refer the inline review on #55212
Quoting from the last comment there:

  • The implementation based on event.pointerType is buggy, as Chrome and Opera return an empty string (as expected) when using the keyboard while Firefox and Safari return undefined.
  • Regardless, differentiating the behavior depending on pointing device vs. 'other' is not OK for accessibility. The modal dialog focus management should always have the same behaevior regardless of mouse, touch, keyboard, other.
  • The assumption that users are always either using a pointing device or other is incorrect. For example, I may want to open the modal dialog with a click and close it by pewssing the Escape key.

Depending on the flow used to open the dialog and on the browser in use, this is what I observed when testing:

  • When opening the dialog, focus is not transferred to the dialog. As such:
    • Focus stays on the page behind the dialog. Tabbing will navigate the page content behing the modal dialog.
    • The dialgo is not announced by screen readers because focus is elsewhere.
    • The dialog doesn't close on Escape.
    • When closing the dialog, focus should always return to the trigger button, instead this is not the case.
    • As such, there is a full focus loss: tabbing again will restart the tab order from the document root.
  • The trigger button doesn't visually expose its accessible name. This is a broadeer issue with all icon buttons ued on the front end and should be addressed holistically.
  • The trigger button is only 24 by 24 pixels. While this is compliant with the current WCAG 2.2, I would like to see the button target size a little larger.
  • When opening the modal dialog, Initial focus should go to the element with role=dialog instead of the Close button.
  • The clickable image is problematic. I'm not sure why we want to make a HTML element have a non-native behavior. I'm not sure that would make it more usable in the first place, as it is a non expected beheavi, especially considering the following point. It is even more problematic on mobile.
  • Still, there is no visual hint that the image can be enlarged. It looks like a normal image and only when hovered or focusd shows a visual hint. As a user, looking at a page with a Lightbox image, I wouldn't have any clue that the image can be enlarged. See screnshot below: how users are supposed to understand the image can be enlarged?

Screenshot 2023-10-17 at 13 12 47

Step-by-step reproduction instructions

Testing on macOS:

  • Add an image block and set the image to open in the Lightbox.
  • Publish and view the front end.
  • Makes sure full keyboard navigation is enabled in your macOS settings under Keyboard. See screenshot:

Screenshot 2023-10-17 at 15 42 46

  • With macOS Chrome:
    • Tab to the button that opens the image modal dialog.
    • Press Enter or Spacebar.
    • Observe that focus is moved to the modal dialog Close button, as expected.
  • With macOS Firefox:
    • Repeat the steps above.
    • Observe focus is not moved to the modal dialog.

Screenshots, screen recording, code snippet

No response

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

Metadata

Metadata

Labels

[Block] ImageAffects the Image Block[Focus] Accessibility (a11y)Changes that impact accessibility and need corresponding review (e.g. markup changes).[Type] BugAn existing feature does not function as intended

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions