fix(sessions): keep search focus when switching picker tabs

This commit is contained in:
Chris Scott committed 2026-10-15 16:36:23 -04:00
1 parent 87f28fbc6d
commit abcecd1c0c
2 files changed
+31 -2

No files matched your search

@@ -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()
@@ -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 (