mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
fix(sessions): keep search focus when switching picker tabs
This commit is contained in:
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 (
|
||||
|
||||
Reference in new issue
Block a user