Skip to content

The agent that grows with you

fix(desktop): drop SSH host refocus effect, assert custom input is typeable

Brooklyn Nicholsoncb07391753b6
diff --git a/apps/desktop/src/app/settings/gateway-settings.test.tsx b/apps/desktop/src/app/settings/gateway-settings.test.tsx
index e33cf269b48..187c786b708 100644
--- a/apps/desktop/src/app/settings/gateway-settings.test.tsx
+++ b/apps/desktop/src/app/settings/gateway-settings.test.tsx
@@ -537,7 +537,7 @@ describe('GatewaySettings', () => {
})
})
- it('focuses the custom SSH host input on the first "Custom" selection', async () => {
+ it('opens a focused, typeable custom SSH host input on the first "Custom" selection', async () => {
getConnectionConfig.mockResolvedValue({
...localConnection,
mode: 'ssh',
@@ -554,16 +554,22 @@ describe('GatewaySettings', () => {
render(<GatewaySettings />)
// With ~/.ssh/config aliases available the host field is a dropdown.
- const trigger = await screen.findByRole('combobox')
- fireEvent.click(trigger)
+ fireEvent.click(await screen.findByRole('combobox'))
fireEvent.click(screen.getByRole('option', { name: 'Custom (enter manually)…' }))
- // The dropdown is swapped for a free-text input that must be focused and
- // immediately typeable on the FIRST selection (no round-trip through
- // another option) — Radix's deferred focus restoration must not steal it.
+ // The FIRST pick swaps the dropdown for a free-text input, no round-trip
+ // through another option needed.
const hostRow = screen.getByText('Host').closest('.grid') as HTMLElement
const input = within(hostRow).getByRole('textbox') as HTMLInputElement
await waitFor(() => expect(document.activeElement).toBe(input))
+ fireEvent.change(input, { target: { value: 'build-box' } })
+ expect(input.value).toBe('build-box')
+
+ // Clearing it and leaving the field backs out of Custom to the dropdown.
+ fireEvent.change(input, { target: { value: '' } })
+ fireEvent.blur(input)
+ expect(await within(hostRow).findByRole('combobox')).toBeTruthy()
+ expect(within(hostRow).queryByRole('textbox')).toBeNull()
})
})
diff --git a/apps/desktop/src/app/settings/gateway-settings.tsx b/apps/desktop/src/app/settings/gateway-settings.tsx
index a39358d6b97..dee26655ef3 100644
--- a/apps/desktop/src/app/settings/gateway-settings.tsx
+++ b/apps/desktop/src/app/settings/gateway-settings.tsx
@@ -271,7 +271,6 @@ function GatewayConnectionSettings({ embedded, standalone }: { embedded: boolean
const [lastTest, setLastTest] = useState<null | string>(null)
const [sshHostSuggestions, setSshHostSuggestions] = useState<string[]>([])
const [sshCustomHost, setSshCustomHost] = useState(false)
- const sshHostInputRef = useRef<HTMLInputElement>(null)
const sshResolveSeq = useRef(0)
const sshTestSeq = useRef(0)
const saveSeq = useRef(0)
@@ -513,23 +512,6 @@ function GatewayConnectionSettings({ embedded, standalone }: { embedded: boolean
return () => void (cancelled = true)
}, [state.mode])
- // Radix Select restores focus to its trigger when the popover closes. That
- // restoration runs after `onValueChange` has swapped the Select out for the
- // custom-host Input, so it races with the Input's `autoFocus` and steals
- // focus from the freshly mounted field (the trigger is already unmounted, so
- // focus lands on <body>). Re-focus on the next frame, once the Select's
- // deferred focus restoration has settled, so the first "Custom" selection
- // yields a field that immediately accepts typing.
- useEffect(() => {
- if (!sshCustomHost) {
- return
- }
-
- const frame = requestAnimationFrame(() => sshHostInputRef.current?.focus())
-
- return () => cancelAnimationFrame(frame)
- }, [sshCustomHost])
-
// eslint-disable-next-line no-restricted-syntax -- monotonic request-sequence counters, not an atom mirror
useEffect(() => {
contextSeq.current += 1
@@ -1381,7 +1363,6 @@ function GatewayConnectionSettings({ embedded, standalone }: { embedded: boolean
void resolveSshHost(state.sshHost)
}}
onChange={event => setState(current => selectSshHost(current, event.target.value))}
- ref={sshHostInputRef}
value={state.sshHost}
/>
}