Repository navigation
fix(web): window focus no longer pulls keyboard focus off sidebar links into the composer - #5
Merged
Merged
Conversation
…ks into the composer Cause: on chat routes the window focus listener refocuses the composer unless focus sits somewhere deliberate. A plain link or button counted as not deliberate, so when a keyboard user Tabbed out to the browser chrome and Tabbed back in, focus landed on the first sidebar link, the window focus event fired, and the composer took focus. Tab could never reach the sidebar or header (WCAG 2.1.1 Keyboard, 2.4.3 Focus Order). Fix: remember document.activeElement at window blur. On window focus, leave focus alone when it moved to a different element while the window was away and that element matches :focus-visible (keyboard focus). Window activation restores the same element, so the original behaviour stays: the composer is refocused from the body or a clicked button, including after a stray key makes the clicked button match :focus-visible. Tests: new case in ChatView.logic.browser.test.ts fails on main (Tabbed link returned true) and passes with the fix; the file passes 5/5 and ChatView.logic.test.ts passes 61/61. Real-browser before/after against a dev server: Tab-in focus on the sidebar "T3 Code home" link moved to the composer before, stays on the link after; body focus still returns to the composer.
… does not Review follow-up to the window-focus composer fix. The first version kept focus only when it landed on a different element than the one focused at window blur. That missed keyboard users whose focus returns to the same element (Ctrl+L to the address bar or Cmd+Tab away, then back), and it treated any script focus while away, such as a dialog returning focus to its trigger, as a Tab-in. Now window blur records the focused element and whether it matched :focus-visible. On return, keyboard focus (:focus-visible) stays put when the window blurred with nothing focused (Tab out to the browser chrome clears focus first) or when it is the element that had keyboard focus at blur. Anything else still yields to the composer. Before any blur is seen, the old behaviour applies. In Chromium a lone Cmd, Alt or Ctrl press does not make a clicked button match :focus-visible, so a clicked pull request tab still yields after Cmd+Tab. Tests: the browser test is reduced to one case with four assertions; it fails on main and passes here (5/5 in the file; ChatView.logic.test.ts 61/61). Real-browser runs: Tab-in to the sidebar link and a keyboard round trip on that link both moved focus to the composer before and stay on the link after; body focus still refocuses the composer.
Thread transfer impact
This comment will update automatically after the next completed run. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On chat routes a keyboard user cannot Tab to the sidebar or header. Tabbing past the last control moves focus to the browser chrome; Tabbing back in lands on the first focusable element (the sidebar's "T3 Code home" link). The window then gets a
focusevent, and the listener inChatView.tsxmoves focus into the composer, becauseshouldRefocusComposerOnWindowFocustreats a plain link or button as yielding to the composer. The same happens when a link has keyboard focus and the user goes to the address bar (Ctrl+L) or another app (Cmd+Tab) and comes back.WCAG 2.2 failures: SC 2.1.1 Keyboard (A) and SC 2.4.3 Focus Order (A).
Fix
ChatView.tsx: the window-focus effect also listens for windowblurand records the focused element and whether it matched:focus-visible.ChatView.logic.ts: on return, keyboard focus (:focus-visible) stays where it is when either:Everything else behaves as before, so the refocus from pingdotgg#10463 still works:
:focus-visible; checked with Playwright.Test evidence
apps/web/src/components/ChatView.logic.browser.test.ts: one new case. It fails on main at the Tab-in assertion and passes with the fix. File: 5/5 passed.ChatView.logic.test.ts: 61/61 passed.check:changed: format, lint, knip, typecheck and react compiler pass. The test step fails one case,ChatView.browser.test.tsx > a shortcut conditioned on rightPanelOpen sees the thread's open right panel, which times out at 15 s on unmodified main as well.document.activeElementafter the window focus event, same result on 3 runs each:Surfaces
Web and desktop share this code path. Mobile and coarse-pointer layouts skip the listener entirely, so they are unchanged.
Follow-ups
blur, Tabs from a sentinel at the top of the body, then dispatches windowfocus. A manual check in desktop Electron and a headed browser would confirm the real event order.:focus-visiblebefore the window returns, that focus is kept.blurdoes not cancel a pending refocus from a windowfocusin the last two frames, so a very quick return and leave can still move focus into the composer in the background.:focus-visibleinmatches()andclosest()throws on Safari before 15.4. The existing selector already depends on it.rightPanelOpenshortcut browser test times out on main in this environment; worth a separate look.Built with Claude Opus 5.5 in Claude Code.