From 939da11722c198eef0a43afd935df3dd35d07fe1 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Wed, 15 Apr 2026 16:18:28 -0500 Subject: [PATCH] Do proper tab handling --- src/components/images/Gallery/index.tsx | 6 ++++++ src/components/images/Gallery/useKeyboardHandlers.web.ts | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/images/Gallery/index.tsx b/src/components/images/Gallery/index.tsx index ec93e0c188..6c4de9876d 100644 --- a/src/components/images/Gallery/index.tsx +++ b/src/components/images/Gallery/index.tsx @@ -178,6 +178,11 @@ export function Gallery({ const onSettle = (index: number) => { setCurrentIndex(index) if (!IS_WEB) return + // Update tabIndex: only the active image is tab-focusable + itemRefsRef.current.forEach((node, i) => { + const el = node as unknown as HTMLElement + el.tabIndex = i === index ? 0 : -1 + }) const el = itemRefsRef.current.get(index) as unknown as HTMLElement | null el?.focus({preventScroll: true}) } @@ -409,6 +414,7 @@ function GalleryImage({ aria-label={image.alt || l`Image ${index + 1} of ${imageCount}`}> setFocused(true)} diff --git a/src/components/images/Gallery/useKeyboardHandlers.web.ts b/src/components/images/Gallery/useKeyboardHandlers.web.ts index 4bde6da4e5..62cf79c287 100644 --- a/src/components/images/Gallery/useKeyboardHandlers.web.ts +++ b/src/components/images/Gallery/useKeyboardHandlers.web.ts @@ -35,11 +35,11 @@ export function useKeyboardHandlers({ const current = pendingIndex ?? currentIndexRef.current let targetIndex: number | undefined - if (e.key === 'ArrowRight' || (e.key === 'Tab' && !e.shiftKey)) { + if (e.key === 'ArrowRight') { if (current < imageCount - 1) { targetIndex = current + 1 } - } else if (e.key === 'ArrowLeft' || (e.key === 'Tab' && e.shiftKey)) { + } else if (e.key === 'ArrowLeft') { if (current > 0) { targetIndex = current - 1 }