The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 23:30 UTC
fix(web): screen readers can browse and Tab through the settings sections again (#30841)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 11, 2026 at 11:56 UTC
940b7a416039b0831360b4dc6984be7600fb61ae
7 files changed
+125
-104
apps/web/src/components/settings/SettingsSidebarNav.composition.browser.test.tsx
+41
-2
@@ -4,6 +4,7 @@ import { page, userEvent } from "vite-plus/test/browser";
4
import { act, render } from "../../../test/render";
5
import { SidebarProvider } from "../ui/sidebar";
6
import { SettingsSidebarNav } from "./SettingsSidebarNav";
7
+import { SETTINGS_NAV_GROUPS, SETTINGS_SECTION_LABELS } from "./settingsSearch";
8
9
vi.mock("./useAvailableSettingsSearchItems", () => ({
10
useAvailableSettingsSearchItems: () => [
@@ -43,13 +44,17 @@ it("ignores composing keys in the search", async () => {
44
);
45
});
46
46
-it("opens search from the physical Slash and F keys on non-US layouts", async () => {
47
- await using _screen = await render(
47
+function renderNav() {
48
+ return render(
49
<SidebarProvider defaultOpen>
50
<SettingsSidebarNav pathname="/settings/general" />
51
</SidebarProvider>,
52
{ router: "/settings/general" },
53
);
54
+}
55
+
56
+it("opens search from the physical Slash and F keys on non-US layouts", async () => {
57
+ await using _screen = await renderNav();
58
const search = page.getByRole("combobox", { name: "Search settings" });
59
60
for (const { init, opens } of [
@@ -65,3 +70,37 @@ it("opens search from the physical Slash and F keys on non-US layouts", async ()
70
if (opens) await expect.element(search).toHaveFocus();
71
}
72
});
73
+
74
+it("moves Tab through every settings section", async () => {
75
+ await page.viewport(1280, 800);
76
+ await using _screen = await renderNav();
77
+ await userEvent.click(page.getByRole("combobox", { name: "Search settings" }));
78
+
79
+ const sections = SETTINGS_NAV_GROUPS.flatMap((group) => group.paths).map(
80
+ (to) => SETTINGS_SECTION_LABELS[to],
81
+ );
82
+ const tabbed: string[] = [];
83
+ for (let step = 0; step < sections.length; step += 1) {
84
+ await userEvent.tab();
85
+ const section = document.activeElement?.closest("[data-settings-section]");
86
+ if (!section) break;
87
+ tabbed.push(section.textContent ?? "");
88
+ }
89
+ expect(tabbed).toEqual(sections);
90
+});
91
+
92
+it.each([1280, 390])("names each group by a heading outside it at %ipx wide", async (width) => {
93
+ await page.viewport(width, 800);
94
+ await using _screen = await renderNav();
95
+
96
+ for (const name of ["Agents", "Code", "Connections"]) {
97
+ const heading = page.getByRole("heading", { name, level: 3 });
98
+ await expect.element(heading).toBeInTheDocument();
99
+ const group = page.getByRole("group", { name }).element();
100
+ expect(group.getAttribute("aria-labelledby")).toBe(heading.element().id);
101
+ expect(group.contains(heading.element()), `the ${name} heading is inside its group`).toBe(
102
+ false,
103
+ );
104
+ }
105
+ expect(page.getByRole("tree").query()).toBeNull();
106
+});
apps/web/src/components/settings/SettingsSidebarNav.tsx
+35
-43
@@ -58,7 +58,7 @@ import {
58
type SettingsSearchItem,
59
} from "./settingsSearch";
60
import { useAvailableSettingsSearchItems } from "./useAvailableSettingsSearchItems";
61
-import { useSettingsSectionNavigation } from "./useSettingsSectionNavigation";
61
+import { handleSettingsSectionKeyDown } from "./settingsSectionNavigation";
62
import { workspaceAreaProps } from "../../lib/workspaceFocus";
63
64
const SnapShotIcon = createLucideIcon("snap-shot", [
@@ -133,12 +133,6 @@ export function SettingsSidebarNav({ pathname }: { pathname: string }) {
133
const navigate = useNavigate();
134
const currentHash = useLocation({ select: (location) => location.hash });
135
const activePath = SETTINGS_DETAIL_PAGE_PARENTS[pathname] ?? pathname;
136
- const navPaths = SETTINGS_NAV_GROUPS.flatMap((group) => group.paths);
137
- const sectionNavigation = useSettingsSectionNavigation(
138
- navPaths.find((to) => activePath === to || activePath.startsWith(`${to}/`)) ??
139
- navPaths[0] ??
140
- "",
141
- );
136
const searchInputRef = useRef<HTMLInputElement>(null);
137
const [query, setQuery] = useState("");
138
// Below md the nav is an icon rail; searching expands it over the page.
@@ -380,57 +374,55 @@ export function SettingsSidebarNav({ pathname }: { pathname: string }) {
374
</SidebarMenuItem>
375
</SidebarMenu>
376
)}
383
- <div
384
- {...sectionNavigation.containerProps}
385
- role="tree"
386
- aria-label="Settings sections"
387
- className="flex flex-col gap-4"
388
- >
377
+ <div onKeyDown={handleSettingsSectionKeyDown} className="flex flex-col gap-4">
378
{SETTINGS_NAV_GROUPS.map((group, index) => (
379
<div
380
key={group.heading ?? index}
392
- role="group"
393
- aria-label={group.heading ?? undefined}
381
className="flex flex-col gap-1 max-md:border-t max-md:border-sidebar-border max-md:pt-4 max-md:first:border-t-0 max-md:first:pt-0"
382
>
383
{group.heading ? (
397
- // The group carries this label; a heading is not a valid tree child.
384
<h3
399
- aria-hidden="true"
385
+ id={`settings-nav-group-${index}`}
386
className={cn(
387
"px-2 text-xs font-medium text-sidebar-muted-foreground/80",
402
- !compactSearchOpen && "max-md:hidden",
388
+ !compactSearchOpen && "max-md:sr-only",
389
)}
390
>
391
{group.heading}
392
</h3>
393
) : null}
408
- <SidebarMenu role="presentation">
409
- {group.paths.map((to) => {
410
- const Icon = SETTINGS_SECTION_ICONS[to];
411
- const isActive = activePath === to || activePath.startsWith(`${to}/`);
412
- return (
413
- <SidebarMenuItem key={to} role="presentation">
414
- <SidebarMenuButton
415
- data-settings-section={to}
416
- role="treeitem"
417
- tabIndex={sectionNavigation.tabIndexFor(to)}
418
- aria-selected={isActive}
419
- aria-current={isActive ? "page" : undefined}
420
- isActive={isActive}
421
- onClick={() => handleSectionClick(to)}
422
- >
423
- <Icon />
424
- <span
425
- className={cn("truncate", !compactSearchOpen && "max-md:sr-only")}
394
+ {/* The heading stays outside the group it names so NVDA does not read the name twice. */}
395
+ <div
396
+ role="group"
397
+ aria-labelledby={group.heading ? `settings-nav-group-${index}` : undefined}
398
+ >
399
+ <SidebarMenu>
400
+ {group.paths.map((to) => {
401
+ const Icon = SETTINGS_SECTION_ICONS[to];
402
+ const isActive = activePath === to || activePath.startsWith(`${to}/`);
403
+ return (
404
+ <SidebarMenuItem key={to}>
405
+ <SidebarMenuButton
406
+ data-settings-section={to}
407
+ aria-current={isActive ? "page" : undefined}
408
+ isActive={isActive}
409
+ onClick={() => handleSectionClick(to)}
410
>
427
- {SETTINGS_SECTION_LABELS[to]}
428
- </span>
429
- </SidebarMenuButton>
430
- </SidebarMenuItem>
431
- );
432
- })}
433
- </SidebarMenu>
411
+ <Icon />
412
+ <span
413
+ className={cn(
414
+ "truncate",
415
+ !compactSearchOpen && "max-md:sr-only",
416
+ )}
417
+ >
418
+ {SETTINGS_SECTION_LABELS[to]}
419
+ </span>
420
+ </SidebarMenuButton>
421
+ </SidebarMenuItem>
422
+ );
423
+ })}
424
+ </SidebarMenu>
425
+ </div>
426
</div>
427
))}
428
</div>
apps/web/src/components/settings/settingsSectionNavigation.ts
new
+33
@@ -0,0 +1,33 @@
1
+import type { KeyboardEvent } from "react";
2
+
3
+const SECTION = "[data-settings-section]";
4
+
5
+/** Arrow keys move focus between settings sections without opening them. */
6
+export function handleSettingsSectionKeyDown(event: KeyboardEvent<HTMLElement>) {
7
+ if (
8
+ event.defaultPrevented ||
9
+ event.altKey ||
10
+ event.ctrlKey ||
11
+ event.metaKey ||
12
+ !(event.target instanceof HTMLElement) ||
13
+ !event.target.matches(SECTION)
14
+ )
15
+ return;
16
+ const items = Array.from(event.currentTarget.querySelectorAll<HTMLElement>(SECTION));
17
+ const index = items.indexOf(event.target);
18
+ const next =
19
+ event.key === "ArrowDown"
20
+ ? Math.min(index + 1, items.length - 1)
21
+ : event.key === "ArrowUp"
22
+ ? Math.max(index - 1, 0)
23
+ : event.key === "Home"
24
+ ? 0
25
+ : event.key === "End"
26
+ ? items.length - 1
27
+ : undefined;
28
+ const target = next === undefined ? undefined : items[next];
29
+ if (!target) return;
30
+ event.preventDefault();
31
+ target.scrollIntoView({ block: "nearest" });
32
+ target.focus({ preventScroll: true });
33
+}
apps/web/src/components/settings/useSettingsSectionNavigation.ts
deleted
-56
@@ -1,56 +0,0 @@
1
-import { useState, type FocusEvent, type KeyboardEvent } from "react";
2
-
3
-const SECTION = "[data-settings-section]";
4
-
5
-/**
6
- * Settings sections share one Tab stop, and arrows move focus without opening a section.
7
- * The Tab stop follows the last focused section until the open section changes.
8
- */
9
-export function useSettingsSectionNavigation(currentSection: string) {
10
- const [focused, setFocused] = useState<{ section: string; page: string } | null>(null);
11
- const tabStop = focused?.page === currentSection ? focused.section : currentSection;
12
- const remember = (element: HTMLElement) => {
13
- const section = element.dataset.settingsSection;
14
- if (section) setFocused({ section, page: currentSection });
15
- };
16
- const onFocus = (event: FocusEvent<HTMLElement>) => {
17
- if (event.target instanceof HTMLElement && event.target.matches(SECTION))
18
- remember(event.target);
19
- };
20
- const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {
21
- if (
22
- event.defaultPrevented ||
23
- event.altKey ||
24
- event.ctrlKey ||
25
- event.metaKey ||
26
- !(event.target instanceof HTMLElement) ||
27
- !event.target.matches(SECTION)
28
- )
29
- return;
30
- // Every section is a root leaf; Left and Right have no tree action.
31
- if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
32
- event.preventDefault();
33
- return;
34
- }
35
- const items = Array.from(event.currentTarget.querySelectorAll<HTMLElement>(SECTION));
36
- const index = items.indexOf(event.target);
37
- const next =
38
- event.key === "ArrowDown"
39
- ? Math.min(index + 1, items.length - 1)
40
- : event.key === "ArrowUp"
41
- ? Math.max(index - 1, 0)
42
- : event.key === "Home"
43
- ? 0
44
- : event.key === "End"
45
- ? items.length - 1
46
- : undefined;
47
- const target = next === undefined ? undefined : items[next];
48
- if (!target) return;
49
- event.preventDefault();
50
- remember(target);
51
- target.scrollIntoView({ block: "nearest" });
52
- target.focus({ preventScroll: true });
53
- };
54
- const tabIndexFor = (section: string) => (section === tabStop ? 0 : -1);
55
- return { containerProps: { onFocus, onKeyDown }, tabIndexFor };
56
-}
apps/web/src/lib/workspaceFocus.browser.test.ts
+13
@@ -132,6 +132,19 @@ describe("workspace area focus", () => {
132
expect(document.activeElement).toBe(nav.button);
133
});
134
135
+ it("enters the Settings sections on the open section", () => {
136
+ using fixture = setup();
137
+ const nav = fixture.area("settings-nav", 0);
138
+ const content = fixture.area("settings", 1);
139
+ nav.element.insertAdjacentHTML(
140
+ "beforeend",
141
+ '<button data-settings-section="/settings/general">General</button><button data-settings-section="/settings/chat" aria-current="page">Chat</button>',
142
+ );
143
+ content.button.focus();
144
+ fixture.controller.move(-1);
145
+ expect(document.activeElement).toBe(nav.element.querySelector('[aria-current="page"]'));
146
+ });
147
+
148
it("keeps moving while a shortcut recorder is on the page but not focused", () => {
149
using fixture = setup();
150
const nav = fixture.area("settings-nav", 0);
apps/web/src/lib/workspaceFocus.ts
+1
-1
@@ -143,7 +143,7 @@ export function createWorkspaceFocusController(doc: Document) {
143
// panel focuses it, but F6 visits that area on its own, so it moves past it here.
144
const preferred = Array.from(
145
area.querySelectorAll<HTMLElement>(
146
- '[data-workspace-focus-default], [data-sidebar-row][aria-current="page"], [data-settings-section][tabindex="0"], .xterm-helper-textarea, [contenteditable="true"]',
146
+ '[data-workspace-focus-default], [data-sidebar-row][aria-current="page"], [data-settings-section][aria-current="page"], .xterm-helper-textarea, [contenteditable="true"]',
147
),
148
).find(nested ? usable : belongs);
149
const fallback = Array.from(area.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)).find(
docs/user/keyboard-focus.md
+2
-2
@@ -33,5 +33,5 @@ expand and collapse groups. `F2` renames the focused thread.
33
Press `Shift+F10` or the Context Menu key to open the focused thread's menu. Use the arrow
34
keys to move through it, Enter to choose, and Escape to close it.
35
36
-The Settings section list works the same way: Up and Down move between sections, and Enter
37
-opens one.
36
+The Settings section list works the same way: Tab moves through each section, Up and Down
37
+also move between sections without opening them, and Enter opens one.