Repository navigation
fix(ui): keep keyboard focus inside open dialogs - #5632
Conversation
Tab could leave an open modal and land on the page behind it: in Settings, 26 presses reached the sidebar's resize handle under the overlay, so keyboard and screen-reader users ended up operating a page they couldn't see. Memory's beta-confirm trap moves into a shared useFocusTrap hook, and every modal that sets aria-modal now uses it: Settings, Document library, Scheduled tasks, File browser, Mobile access, Version picker, Context panel, both change reviews, the commit/PR dialog, the folder picker, and the session panel while it is an overlay. Tab and Shift+Tab wrap at either end, the focusable list is re-read on each key press, and when dialogs nest only the innermost one acts. Escape and focus-return are unchanged.
|
Verdict: Request changes. The only blocker is proof that this works in the real app. The code itself looks ready to merge. This PR stops Tab and Shift+Tab from leaving an open dialog and landing on the page behind it. It does that with one shared hook, wired into every modal in the Agent UI, and the old hand-rolled trap in Memory now uses the same hook. The hook handles nested dialogs, disabled and hidden controls, and content that changes while a dialog is open, and the tests cover each of those cases. I found no bugs.
Real-world evidenceN/A: no evidence bundle was produced for this run, and this is an Agent UI change whose rendered check needs a real browser. I couldn't run the new vitest suites here because the webui dependencies aren't installed. So this verdict rests on reading the code plus the test results the PR reports (146 files, 1532 tests, 🔍 Technical detailsIssues 🟡 No real-browser evidence for an Agent UI change. Per the rubric, an Agent UI change needs a Playwright before→after screenshot embedded in the PR description. The jsdom tests are good at gating the logic, but 🟢 Content inside a closed 🟢 Every Tab press re-scans the whole dialog ( Strengths
|
|
Checked live in the desktop app. Settings held focus through 60 Tabs and 30 Shift+Tabs; before this change, focus escaped to the sidebar after 26. The Document library and Scheduled tasks held it through 40 Tabs each. Escape still closes Settings and puts focus back in the message box. |
Controls inside a closed <details> counted as tabbable, so a hidden last button could make the trap step aside and let Tab leave the dialog. Only the summary of a closed <details> is a stop now. Each Tab press is also cheaper: checkVisibility() replaces the per-ancestor style walk where the browser has it, and the radio-group filter is one pass instead of O(n^2).
|
Both 🟢 items from the last review are fixed.
🔍 Technical details
|
Tab could walk out of an open dialog and onto the page hidden behind it. In Settings, 26 presses landed on the sidebar's resize handle under the overlay, so a keyboard or screen-reader user ended up operating a page they couldn't see. Now Tab and Shift+Tab wrap inside every modal in the Agent UI, including when its content changes while open. Escape and returning focus to the opener work exactly as before.
aria-modal. Docked, it sits alongside the page and sets noaria-modal, so it is left alone. Noaria-modalattribute needed correcting.Test plan
npx vitest run src/hooks/__tests__/useFocusTrap.test.tsx: wraps forward and back, skips disabled and hidden elements, re-reads changed content, pulls focus in from outside, only the innermost of nested traps acts, inactive does nothingnpx vitest run src/components/settings/__tests__/SettingsDialogFocus.test.tsx: Tab from the last control in Settings returns to the first section buttonMemoryDashboard.a11y.test.tsxstill passes on the shared hooknpx vitest run(146 files, 1532 tests) andnpx tsc --noEmitpassreasonably sized component files): none of the touched files is close to the cap. On a Windows CRLF checkout the check fails on main forChatView.tsx(101,751 bytes in git, 103,725 on disk), which this PR doesn't touch. Confirm it is green in CI.