From 5da9a8c5dacf4d6454ec50bba022cf64716e8899 Mon Sep 17 00:00:00 2001 From: jessicanath Date: Mon, 1 Jun 2026 07:14:57 +0000 Subject: [PATCH] fix(#683): trap focus within AnchorSelector dropdown Intercept Tab/Shift+Tab when the dropdown is open to cycle focus through options instead of allowing it to escape the dropdown. Closes #683 --- frontend/src/components/AnchorSelector.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/AnchorSelector.tsx b/frontend/src/components/AnchorSelector.tsx index 98626c84..f9cd06cc 100644 --- a/frontend/src/components/AnchorSelector.tsx +++ b/frontend/src/components/AnchorSelector.tsx @@ -162,9 +162,14 @@ export const AnchorSelector: React.FC = ({ triggerRef.current?.focus(); break; case 'Tab': - // Close on tab and allow default behavior - setIsOpen(false); - setFocusedIndex(-1); + // Trap focus: cycle through options instead of leaving the dropdown + e.preventDefault(); + if (anchors.length === 0) break; + if (e.shiftKey) { + setFocusedIndex(prev => (prev > 0 ? prev - 1 : anchors.length - 1)); + } else { + setFocusedIndex(prev => (prev < anchors.length - 1 ? prev + 1 : 0)); + } break; } }, [isOpen, focusedIndex, anchors, selectedAnchor]);