diff --git a/ui/src/App.test.tsx b/ui/src/App.test.tsx index 7462735..4c296cc 100644 --- a/ui/src/App.test.tsx +++ b/ui/src/App.test.tsx @@ -264,6 +264,26 @@ describe('where focus goes when the screen is replaced', () => { }) }) + it('lands on the first screen when the legal gate is accepted', async () => { + // Found in the installed build: *Continue* is unmounted with the gate, the shell appears + // behind it, and the tab has not changed — so the very first screen of a first run had focus + // on nothing. + legalConsentGet.mockResolvedValue({ current: false, docsHash: 'a1b2c3d4e5f60718' }) + useLegalStore.setState({ accepted: false, review: false }) + render() + const accept = await screen.findByRole('button', { name: 'Continue' }) + accept.focus() + + act(() => { + useLegalStore.setState({ accepted: true }) + }) + + await waitFor(() => { + expect(heading()).toHaveFocus() + }) + expect(heading()).toHaveTextContent('Installed') + }) + it('does not take focus from a control that is still there', async () => { // The rule is "focus was lost", not "the phase changed": moving it on every phase would pull // a keyboard user off *Console* each time a run advanced. diff --git a/ui/src/App.tsx b/ui/src/App.tsx index c4feb3c..d057592 100644 --- a/ui/src/App.tsx +++ b/ui/src/App.tsx @@ -154,7 +154,10 @@ export function App() { if (target === null || target === undefined) return if (target.tagName === 'H1') target.setAttribute('tabindex', '-1') target.focus() - }, [panelPhase, depsOpen, envOpen]) + // `accepted` and `review`: the legal gate is rendered *instead of* the shell, so accepting it + // or closing a review is a fifth way the screen is replaced with `nav` unchanged — and the + // first screen of a first run had focus on nothing. Found in the installed build. + }, [panelPhase, depsOpen, envOpen, accepted, review]) // UI-SPEC §8: Ctrl+1..9 select tabs, positionally over NAV_KEYS. useEffect(() => { diff --git a/ui/src/components/PdDialog.tsx b/ui/src/components/PdDialog.tsx index 5518926..7e65cf8 100644 --- a/ui/src/components/PdDialog.tsx +++ b/ui/src/components/PdDialog.tsx @@ -81,9 +81,14 @@ export function PdDialog({ return (