From c16eccaecb09e24667afff349b5e18c991315321 Mon Sep 17 00:00:00 2001 From: jeffvli Date: Wed, 18 Mar 2026 02:17:31 -0700 Subject: [PATCH] fix tab index on command palette play buttons --- .../search/components/command-palette.tsx | 26 +++++++++++ .../library-command-item.module.css | 11 +++++ .../components/library-command-item.tsx | 44 +++++++++++++++++-- 3 files changed, 77 insertions(+), 4 deletions(-) diff --git a/src/renderer/features/search/components/command-palette.tsx b/src/renderer/features/search/components/command-palette.tsx index 3f4de942b..826918c6b 100644 --- a/src/renderer/features/search/components/command-palette.tsx +++ b/src/renderer/features/search/components/command-palette.tsx @@ -134,6 +134,7 @@ export const CommandPalette = ({ modalProps }: CommandPaletteProps) => { const [pages, setPages] = useState([CommandPalettePages.HOME]); const activePage = pages[pages.length - 1]; const isHome = activePage === CommandPalettePages.HOME; + const commandRootRef = useRef(null); const searchInputRef = useRef(null); const popPage = useCallback(() => { @@ -189,8 +190,33 @@ export const CommandPalette = ({ modalProps }: CommandPaletteProps) => { if (e.key === 'ArrowDown' || e.key === 'ArrowUp') { searchInputRef.current?.focus(); } + + if (e.key === 'Tab' && !e.shiftKey) { + const root = commandRootRef.current; + if (!root) return; + + const selectedItem = root.querySelector( + '[cmdk-item][aria-selected="true"]', + ) as HTMLElement | null; + + if (!selectedItem) return; + + const focusTarget = selectedItem.querySelector( + 'button:not([disabled]), [tabindex]:not([tabindex="-1"])', + ) as HTMLElement | null; + + if (!focusTarget) return; + + e.preventDefault(); + e.stopPropagation(); + + requestAnimationFrame(() => { + focusTarget.focus(); + }); + } }} onValueChange={setValue} + ref={commandRootRef} value={value} > void, +) => { + return (e: React.KeyboardEvent) => { + if (e.key === ' ' || e.key === 'Enter') { + e.preventDefault(); + e.stopPropagation(); + if (!disabled) { + onPlay(playType); + } + } else if (e.key === 'Tab') { + e.stopPropagation(); + } + }; +}; + interface LibraryCommandItemProps { disabled?: boolean; explicitStatus?: ExplicitStatus | null; @@ -119,29 +137,47 @@ export const LibraryCommandItem = ({ {showControls && ( - +