From abcecd1c0c2ab2b5dc92da50c1afb64e7ddd6dbe Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Thu, 15 Oct 2026 16:36:23 -0400 Subject: [PATCH] fix(sessions): keep search focus when switching picker tabs --- .../session/SessionPickerDialog.test.tsx | 26 +++++++++++++++++++ .../session/SessionPickerDialog.tsx | 7 +++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/session/SessionPickerDialog.test.tsx b/frontend/src/components/session/SessionPickerDialog.test.tsx index 1edfca4a..747c7abf 100644 --- a/frontend/src/components/session/SessionPickerDialog.test.tsx +++ b/frontend/src/components/session/SessionPickerDialog.test.tsx @@ -514,6 +514,32 @@ describe('SessionPickerDialog', () => { expect(screen.queryByRole('tabpanel', { name: 'Sessions' })).not.toBeInTheDocument() }) + it('focuses the projects search input after clicking the Projects tab and filters on typing', async () => { + 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' })) + + await waitFor(() => expect(screen.getByPlaceholderText('Search projects...')).toHaveFocus()) + + await user.keyboard('beta') + + expect(screen.getByRole('option', { name: /beta/ })).toBeInTheDocument() + expect(screen.queryByRole('option', { name: /alpha/ })).not.toBeInTheDocument() + }) + + it('focuses the projects search input after switching tabs with the shortcut', async () => { + 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('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 1305a76e..02d76003 100644 --- a/frontend/src/components/session/SessionPickerDialog.tsx +++ b/frontend/src/components/session/SessionPickerDialog.tsx @@ -734,8 +734,11 @@ export function SessionPickerDialog({ useEffect(() => { if (!open || !hasFinePointer) return - if (tab === 'projects') projectSearchInputRef.current?.focus() - else searchInputRef.current?.focus() + const frame = requestAnimationFrame(() => { + if (tab === 'projects') projectSearchInputRef.current?.focus() + else searchInputRef.current?.focus() + }) + return () => cancelAnimationFrame(frame) }, [open, tab, hasFinePointer]) return (