Skip to content

Gallery Lightbox: Prevent image click from closing the dialog when navigation is enabled#78898

Open
i-am-chitti wants to merge 1 commit into
WordPress:trunkfrom
i-am-chitti:GH-78869
Open

Gallery Lightbox: Prevent image click from closing the dialog when navigation is enabled#78898
i-am-chitti wants to merge 1 commit into
WordPress:trunkfrom
i-am-chitti:GH-78869

Conversation

@i-am-chitti

Copy link
Copy Markdown
Contributor

What?

Closes #78869

Prevents clicking or tapping the expanded image from closing the lightbox when navigation controls are present in a gallery lightbox.

Why?

When a gallery lightbox is open, clicking anywhere on the overlay — including directly on the expanded image — closes it. For a standalone image lightbox this is a reasonable affordance, but in a gallery with navigation controls it causes unexpected dismissals.

On touch devices the impact is significant: the only visible controls are the navigation buttons, so a user tapping the image to inspect detail, or slightly mis-tapping while reaching for a nav button, loses their place in the gallery with no recovery other than reopening and navigating back.

The behavior was inherited from the single-image lightbox implementation when gallery navigation was introduced in #62906, without being re-evaluated in the context of a navigable gallery.

How?

Added a handleImageContainerClick action in view.js that calls event.stopPropagation() when state.hasNavigation is true. This follows the same pattern the Previous/Next navigation buttons already use to prevent accidental closes.

The handler is attached to both .lightbox-image-container elements in the PHP template. A has-navigation CSS class is also toggled on the overlay to reset cursor: zoom-out to cursor: default on the image container, so the cursor no longer implies the image is clickable-to-close.

  • Single-image lightboxes (no navigation) are unaffected — clicking
    the image still closes the dialog.
  • The Close button, Escape key, and clicking the background (scrim)
    continue to close the gallery lightbox.

Testing Instructions

  1. Create a new post or page.
  2. Insert a Gallery block with two or more images.
  3. In the block settings, enable Lightbox.
  4. Save/preview the post.
  5. Click an image to open the lightbox.
  6. Click or tap directly on the expanded image.
    Expected: Nothing happens. The lightbox stays open.
  7. Click the × Close button.
    Expected: Lightbox closes.
  8. Reopen the lightbox, then press Escape.
    Expected: Lightbox closes.
  9. Reopen the lightbox, then click the dark background area outside
    the image.
    Expected: Lightbox closes.
  10. Repeat steps 5–9 on a touch device or with browser DevTools in
    mobile emulation

Single-image regression check:
11. Insert a standalone Image block (not in a Gallery) and enable
Lightbox.
12. Open the lightbox and click the image.
Expected: Lightbox still closes (existing behavior unchanged).

Testing Instructions for Keyboard

  1. Open the gallery lightbox using Enter or Space on a focused
    image thumbnail.
  2. Press Arrow Left / Arrow Right to navigate between images.
  3. Press Escape → lightbox should close.
  4. Use Tab to cycle focus between the Close button and navigation
    buttons; confirm focus is trapped inside the overlay.

Screenshots or screencast

Before

Screen.Recording.2026-06-03.at.12.44.45.PM.mp4

After

Screen.Recording.2026-06-03.at.12.45.54.PM.mp4

Use of AI Tools

This PR was developed with the assistance of GitHub Copilot. Each change was reviewed and validated by me.

@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Jun 3, 2026
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: i-am-chitti <iamchitti@git.wordpress.org>
Co-authored-by: JosVelasco <josvelasco@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano t-hamano added [Type] Enhancement A suggestion for improvement. [Block] Gallery Affects the Gallery Block - used to display groups of images labels Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Gallery Affects the Gallery Block - used to display groups of images [Package] Block library /packages/block-library [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gallery lightbox: clicking the expanded image should not close the dialog when navigation is enabled

2 participants