Skip to content

[a11y] Lightbox: Focus leaks outside the overlay during keyboard navigation (Tab key) #75801

Closed

Description

@Gierand

Description

When navigating a lightbox gallery using keyboard (Tab / Shift+Tab), focus escapes outside the lightbox overlay and becomes invisible — the focus indicator disappears entirely, leaving the user with no visual feedback on where they are on the page.

Expected behavior:

Focus cycles only within the lightbox (close button, navigation arrows). When the last focusable element is reached, focus should wrap back to the first one.

Step-by-step reproduction instructions

  1. Add a Gallery block to a page/post.
  2. Enable the lightbox option for the gallery.
  3. Open the published page and open the lightbox by clicking on an image.
  4. Navigate using the Tab key repeatedly.

Screenshots, screen recording, code snippet

No response

Environment info

  • Gutenberg version: 22.6 RC1, 22.8.-nightly
  • Active theme: TT5

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

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Activity

  1. added
    [Type] Bug
    on Feb 21, 2026
  2. added
    [Block] Gallery
    on Feb 23, 2026
  3. added
    [Status] In Progress
    on Feb 24, 2026
  4. namankhare commented on Feb 24, 2026

    @namankhare
    Contributor

    Thanks @Gierand for raising the issue, I was able to replicate the issue on Gutenberg 22.6 RC2 with TT5.

    Video:

    75801.-.Issue.Replication.mov

    Root Cause

    The lightbox overlay is rendered once per lightbox-enabled image instead of once per page. Each call to block_core_image_render_lightbox() registers a new wp_footer callback using an anonymous closure. WordPress treats each closure as a unique callback, so the overlay HTML is printed multiple times.

    For a gallery with 3 images, you get 3 identical .wp-lightbox-overlay divs in the DOM:

    Screenshot:

    Image

    This was introduced in #62906 (676fabe8cd), which changed the original named function reference to an anonymous closure during the gallery lightbox work. The previous code was already correct:

    // Before #62906 — correct, idempotent (WordPress deduplicates string callbacks)
    add_action( 'wp_footer', 'block_core_image_print_lightbox_overlay' );
    
    // After #62906 — broken (each closure is a unique callback → duplicates)
    $overlay_callback = function () {
        block_core_image_print_lightbox_overlay();
    };
    add_action( 'wp_footer', $overlay_callback );

    Fix

    1. PHP — Restore the named function reference (1-line change):
    add_action( 'wp_footer', 'block_core_image_print_lightbox_overlay' );

    Working video:

    75801.-.Fix.mov

    I have raised a PR with above changes: #75852

    cc: @t-hamano

  5. Gierand commented on Feb 24, 2026

    @Gierand
    Author

    @namankhare,
    Thank you for taking care of this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Block] Gallery[Status] In Progress[Type] Bug

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions