From afc95039a83068ddebddc47eb59fe9eee40e79a2 Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Thu, 15 Oct 2026 16:45:08 -0400 Subject: [PATCH] fix(sessions): focus picker search after the tab shortcut on touch devices --- .../session/SessionPickerDialog.test.tsx | 23 +++++++++++++++++++ .../session/SessionPickerDialog.tsx | 9 +++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/session/SessionPickerDialog.test.tsx b/frontend/src/components/session/SessionPickerDialog.test.tsx index 747c7abf..d0b607f7 100644 --- a/frontend/src/components/session/SessionPickerDialog.test.tsx +++ b/frontend/src/components/session/SessionPickerDialog.test.tsx @@ -540,6 +540,29 @@ describe('SessionPickerDialog', () => { await waitFor(() => expect(screen.getByPlaceholderText('Search projects...')).toHaveFocus()) }) + it('focuses the projects search input after the switch shortcut on a coarse pointer device', async () => { + stubMatchMedia(false) + mocks.repos = [repo(1, 'alpha', '/w/a'), repo(2, 'beta', '/w/b')] + const user = userEvent.setup() + renderPicker() + + await user.click(screen.getByPlaceholderText('Search sessions...')) + await user.keyboard('{Control>}s{/Control}') + + await waitFor(() => expect(screen.getByPlaceholderText('Search projects...')).toHaveFocus()) + }) + + it('does not focus the projects search input when switching tabs by pointer on a coarse pointer device', async () => { + stubMatchMedia(false) + mocks.repos = [repo(1, 'alpha', '/w/a'), repo(2, 'beta', '/w/b')] + const user = userEvent.setup() + renderPicker() + + await user.click(screen.getByRole('tab', { name: 'Projects' })) + + expect(await screen.findByPlaceholderText('Search projects...')).not.toHaveFocus() + }) + it('lists repos in the projects tab and opens the cursor repo on Enter', async () => { mocks.repos = [repo(1, 'alpha', '/w/a'), repo(2, 'beta', '/w/b')] const { onSelectRepo } = renderPicker() diff --git a/frontend/src/components/session/SessionPickerDialog.tsx b/frontend/src/components/session/SessionPickerDialog.tsx index 02d76003..1d7ee8fb 100644 --- a/frontend/src/components/session/SessionPickerDialog.tsx +++ b/frontend/src/components/session/SessionPickerDialog.tsx @@ -705,6 +705,7 @@ export function SessionPickerDialog({ }: SessionPickerDialogProps) { const searchInputRef = useRef(null) const projectSearchInputRef = useRef(null) + const focusSearchAfterSwitchRef = useRef(false) const hasFinePointer = useMediaQuery(FINE_POINTER_MEDIA_QUERY) const { preferences } = useSettings() const switchHint = useMemo( @@ -727,14 +728,20 @@ export function SessionPickerDialog({ } const toggleTab = useCallback(() => { + focusSearchAfterSwitchRef.current = true setTab((current) => (current === 'sessions' ? 'projects' : 'sessions')) }, []) useShortcutActions({ switchPickerTab: open ? toggleTab : undefined }) useEffect(() => { - if (!open || !hasFinePointer) return + if (!open) { + focusSearchAfterSwitchRef.current = false + return + } + if (!hasFinePointer && !focusSearchAfterSwitchRef.current) return const frame = requestAnimationFrame(() => { + focusSearchAfterSwitchRef.current = false if (tab === 'projects') projectSearchInputRef.current?.focus() else searchInputRef.current?.focus() })