diff --git a/apps/host/src/app/Sidebar.tsx b/apps/host/src/app/Sidebar.tsx index 5d15bc49..7415ec07 100644 --- a/apps/host/src/app/Sidebar.tsx +++ b/apps/host/src/app/Sidebar.tsx @@ -89,13 +89,13 @@ export function Sidebar({ containerRef }: { const rows = matching.filter(s => s.workspace === w.path || !!w.aliases?.includes(s.workspace)); const shown = q ? rows : rows.slice(0, 20); return
-
{ setWsName(w.name); setRenameWsId(w.id); }}/>{tr(w.id !== 'root' ? setRemoveWorkspaceId(w.id)}/> : null)}
+
{ setWsName(w.name); setNavOpen(false); setRenameWsId(w.id); }}/>{tr(w.id !== 'root' ? { setNavOpen(false); setRemoveWorkspaceId(w.id); }}/> : null)}
{tr(expanded ?
{tr(shown.map(s =>
selectSession(s.id)} onContextMenu={e => { e.preventDefault(); openMenu(s.id, e.currentTarget); }} title={sessionTitle(s)}>{sessionTitle(s)}{tr(s.pinned ? : {tr(relTime(s.updatedAt))})}{tr(isUnread(s, activeSession) ? : null)}{tr(s.archived ? {tr("Archived")} : null)}
))} {tr(!shown.length ?

{tr(q ? 'No matching chats' : 'No chats yet')}

: null)} - {tr(!q && rows.length > shown.length ? : null)} + {tr(!q && rows.length > shown.length ? : null)}
: null)}
; })} @@ -110,9 +110,9 @@ export function Sidebar({ containerRef }: { {tr(menuId && menuSession ? - + - + : null)} setRenameId(null)} actions={<> setRenameId(null)}>{tr("Cancel")} { if (renameId) @@ -190,5 +190,5 @@ function MoreMenu({ current }: { const [quitOpen, setQuitOpen] = useState(false); const appMode = useAppMode(); const ref = useRef(null); - return <>{tr(open ? { setOpen(false); ref.current?.focus(); }}>{tr(([{ route: 'serving', label: 'Serving', icon: 'link' }, { route: 'settings', label: 'Settings', icon: 'settings' }] as const).map(d => setOpen(false)}>{tr(d.label)}))}{appMode.canQuit ? : null} : null)} setQuitOpen(false)}/>; + return <>{tr(open ? { setOpen(false); ref.current?.focus(); }}>{tr(([{ route: 'serving', label: 'Serving', icon: 'link' }, { route: 'settings', label: 'Settings', icon: 'settings' }] as const).map(d => setOpen(false)}>{tr(d.label)}))}{appMode.canQuit ? : null} : null)} setQuitOpen(false)}/>; } diff --git a/apps/host/src/app/TaskTree.tsx b/apps/host/src/app/TaskTree.tsx index 6d20b04c..f24b29d4 100644 --- a/apps/host/src/app/TaskTree.tsx +++ b/apps/host/src/app/TaskTree.tsx @@ -5,7 +5,7 @@ import { api } from '../lib/client'; import { navigate, href, useLocation } from '../lib/router'; import { blankTask, type Task } from '../lib/tasks'; import { TaskEditor } from '../components/TaskEditor'; -import { pushToast } from '../lib/store'; +import { pushToast, setNavOpen } from '../lib/store'; type TaskLeaf = Task & { id: string; }; @@ -67,12 +67,17 @@ export function TaskTree({ collapsed }: { setBusy(false); } } - if (collapsed) - return null; - return
-
setEditor(blankTask())}/>
- {tr(open ?
{tr(tasks.map(t =>
{t.title}{tr(!t.enabled ? : null)}
))}{tr(!tasks.length ?

{tr("No tasks yet")}

: null)}{tr(error && !remove ?

{tr("Couldn\u2019t load tasks.")}

: null)}
: null)} + // A dialog opened from the narrow-window menu closes the menu first (QA F03: the form opened behind it and the keyboard stayed there). The dialogs + // live here, so they stay mounted while the menu is closed. + const dialogs = <> {tr(editor ? setEditor(null)}/> : null)} !busy && setRemove(null)} actions={<> setRemove(null)}>{tr("Keep task")} void deleteTask()}>{tr(busy ? 'Removing…' : 'Remove task')}}>

“{remove?.title}”{tr(" will stop running and be removed.")}

{tr(error ?

{tr(error)}

: null)}
+ ; + if (collapsed) + return dialogs; + return
+
{ setNavOpen(false); setEditor(blankTask()); }}/>
+ {tr(open ?
{tr(tasks.map(t =>
{t.title}{tr(!t.enabled ? : null)}
))}{tr(!tasks.length ?

{tr("No tasks yet")}

: null)}{tr(error && !remove ?

{tr("Couldn\u2019t load tasks.")}

: null)}
: null)} + {dialogs}
; } diff --git a/apps/host/src/lib/focus.ts b/apps/host/src/lib/focus.ts index 47d0cb16..36e616cf 100644 --- a/apps/host/src/lib/focus.ts +++ b/apps/host/src/lib/focus.ts @@ -104,7 +104,10 @@ export function useSurfaceFocus( target?.focus(); }; frame = requestAnimationFrame(attempt); - return () => cancelAnimationFrame(frame); + // A page that is not being painted (a window that is covered or in the background) holds animation frames back, and then focus would stay + // on whatever opened the surface, behind it (QA F03). A timer is not held back, so it moves focus in if the frame did not. + const fallback = setTimeout(() => { const el = ref.current; if (el && !el.contains(document.activeElement) && isTopSurface(el)) attempt(); }, 80); + return () => { cancelAnimationFrame(frame); clearTimeout(fallback); }; }, [open, ref, initial]); // Keep Tab inside while open. diff --git a/apps/host/tests/split-qa2-dialogs.test.mjs b/apps/host/tests/split-qa2-dialogs.test.mjs new file mode 100644 index 00000000..8a53775f --- /dev/null +++ b/apps/host/tests/split-qa2-dialogs.test.mjs @@ -0,0 +1,23 @@ +// QA report F03: a dialog opened from the narrow-window menu closes the menu and takes the keyboard. +// (The real behaviour is checked in a browser by scripts/qa2-flows.mjs; these keep the pieces from being taken out again.) +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { readFile } from 'node:fs/promises'; + +const read = path => readFile(new URL(path, import.meta.url), 'utf8').then(s => s.replace(/\r\n/g, '\n')); + +test('every dialog the menu opens closes the menu first, and the task dialogs stay mounted while it is closed', async () => { + const tree = await read('../src/app/TaskTree.tsx'); + assert.match(tree, /import \{ pushToast, setNavOpen \} from '\.\.\/lib\/store'/); + for (const opener of ['setEditor(blankTask())', 'setEditor({ ...t })', 'setRemove(t)']) assert.ok(tree.includes(`setNavOpen(false); ${opener}`), `${opener} closes the menu`); + assert.match(tree, /if \(collapsed\)\n\s+return dialogs;/, 'a closed menu still renders the dialogs'); + const side = await read('../src/app/Sidebar.tsx'); + for (const opener of ['setRenameId(menuId)', 'setDeleteId(menuId)', 'setRecentOpen(true)', 'setRemoveWorkspaceId(w.id)', 'setRenameWsId(w.id)', 'setQuitOpen(true)']) assert.ok(side.includes(`setNavOpen(false); ${opener}`), `${opener} closes the menu`); +}); + +test('a surface that opens moves the keyboard in even when animation frames are held back', async () => { + const focus = await read('../src/lib/focus.ts'); + assert.match(focus, /const fallback = setTimeout\(/); + assert.match(focus, /clearTimeout\(fallback\)/); + assert.match(focus, /!el\.contains\(document\.activeElement\) && isTopSurface\(el\)/); +});