Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix lightbox focus management during keyboard navigation
  • Loading branch information
namankhare committed Feb 24, 2026
commit c7d874a0cae53464352b9fb11dd98c5ab02ec7b0
10 changes: 8 additions & 2 deletions packages/block-library/src/image/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,17 @@ const { state, actions, callbacks } = store(
// Traps focus within the overlay.
const focusableElements = Array.from(
document.querySelectorAll( focusableSelectors )
);
).filter( ( element ) => ! element.hidden );
const firstFocusableElement = focusableElements[ 0 ];
const lastFocusableElement =
focusableElements[ focusableElements.length - 1 ];
if (
// If focus is not on any of the known focusable
// elements (e.g. on the overlay div itself),
// move it to the first focusable element.
if ( ! focusableElements.includes( event.target ) ) {
event.preventDefault();
firstFocusableElement.focus();
} else if (
event.shiftKey &&
event.target === firstFocusableElement
) {
Expand Down