Skip to content

Commit 5b9731c

Browse files
nibarAhmednibarAhmedclaudeshivamhwp
authored
fix(web): screen readers can browse and Tab through the threads sidebar again without going into focus mode (pingdotgg#26690)
Co-authored-by: nibarAhmed <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: shivam <[email protected]>
1 parent 71646e0 commit 5b9731c

11 files changed

Lines changed: 99 additions & 209 deletions

‎apps/web/src/components/ChatView.logic.browser.test.ts‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ import { userEvent } from "vite-plus/test/browser";
33
import { shouldRefocusComposerOnWindowFocus } from "./ChatView.logic";
44

55
it("keeps keyboard focus on a sidebar row on window return, but not a clicked row", async () => {
6-
const tree = document.createElement("div");
7-
tree.setAttribute("role", "tree");
8-
const row = (name: string, tabIndex: number) => {
6+
const list = document.createElement("ul");
7+
const row = (name: string) => {
98
const element = document.createElement("div");
10-
element.setAttribute("role", "treeitem");
11-
element.tabIndex = tabIndex;
9+
element.setAttribute("role", "button");
10+
element.tabIndex = 0;
11+
element.dataset.sidebarRow = name;
1212
element.textContent = name;
13-
tree.append(element);
13+
list.append(element);
1414
return element;
1515
};
16-
const clicked = row("Clicked thread", -1);
17-
const tabbed = row("Tabbed thread", 0);
18-
document.body.append(tree);
19-
using _tree = { [Symbol.dispose]: () => tree.remove() };
16+
const clicked = row("Clicked thread");
17+
const tabbed = row("Tabbed thread");
18+
document.body.append(list);
19+
using _list = { [Symbol.dispose]: () => list.remove() };
2020

2121
await userEvent.click(clicked);
2222
expect(document.activeElement).toBe(clicked);

‎apps/web/src/components/ChatView.logic.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ export function shouldRefocusComposerOnWindowFocus(
11661166
}
11671167
return (
11681168
activeElement.closest(
1169-
'[data-workspace-area]:focus-visible, [role="treeitem"]:focus-visible, [role="dialog"], [role="alertdialog"], [role="application"], [role="menu"], [role="listbox"], [data-slot$="-popup"], [data-terminal-owner]',
1169+
'[data-workspace-area]:focus-visible, [data-sidebar-row]:focus-visible, [role="dialog"], [role="alertdialog"], [role="application"], [role="menu"], [role="listbox"], [data-slot$="-popup"], [data-terminal-owner]',
11701170
) === null
11711171
);
11721172
}

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { liveShellEnvironmentIdsAtom } from "../state/shell";
2-
import { attachSidebarTree, SIDEBAR_TREE_PROPS } from "../lib/sidebarTree";
2+
import { attachSidebarTree } from "../lib/sidebarTree";
33
import { type EnvironmentId, type ScopedProjectRef } from "@t3tools/contracts";
44
import type { EnvironmentServerConfig } from "@t3tools/client-runtime/connection";
55
import { ThreadContextDragGhost } from "./chat/ThreadContextDragGhost";
@@ -3292,8 +3292,10 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
32923292
>
32933293
<SortableContext items={sortableIds} strategy={sidebarSortingStrategy}>
32943294
<ul
3295-
{...SIDEBAR_TREE_PROPS}
32963295
ref={attachTreeRef}
3296+
// Presentation flattens VoiceOver's list interaction boundary while preserving descendant
3297+
// controls.
3298+
role="presentation"
32973299
className={cn(
32983300
"relative flex flex-col gap-px",
32993301
sidebarListItems.length > 0 && "flex-1",
@@ -3581,8 +3583,6 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
35813583
<li className="list-none">
35823584
<button
35833585
type="button"
3584-
role="treeitem"
3585-
tabIndex={-1}
35863586
data-sidebar-row="settled:more"
35873587
data-sidebar-parent="shelf:settled"
35883588
disabled={olderSettledShelf.loading}

‎apps/web/src/components/sidebar/SidebarDraftBlock.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ const SidebarDraftRow = memo(function SidebarDraftRow(props: {
8282
return (
8383
<li className="list-none py-0.5">
8484
<div
85-
role="treeitem"
86-
tabIndex={-1}
85+
role="button"
86+
tabIndex={0}
8787
data-sidebar-row={`draft:${draftId}`}
8888
aria-label={accessibility.label}
8989
aria-current={accessibility.current}

‎apps/web/src/components/sidebar/SidebarListMarkers.tsx‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ export function SidebarSectionHeader(props: {
130130
className={cn("relative mx-0.5 h-8", props.className)}
131131
>
132132
<CollapsibleSectionHeader
133-
role="treeitem"
134-
tabIndex={-1}
135133
data-sidebar-row={`shelf:${shelf}`}
136134
onClick={props.toggle.onToggle}
137135
expanded={props.toggle.expanded}

‎apps/web/src/components/sidebar/SidebarProjectFolderHeader.tsx‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ export const SidebarProjectFolderHeader = memo(function SidebarProjectFolderHead
6666
>
6767
<button
6868
type="button"
69-
role="treeitem"
70-
tabIndex={-1}
7169
data-sidebar-row={rowId}
7270
aria-expanded={!collapsed}
7371
onClick={() => props.onToggle(group)}

‎apps/web/src/components/sidebar/SidebarThreadRow.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,8 +1208,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
12081208
render={
12091209
<div
12101210
ref={rowRef}
1211-
role="treeitem"
1212-
tabIndex={-1}
1211+
role="button"
1212+
tabIndex={0}
12131213
data-sidebar-row={threadKey}
12141214
data-sidebar-parent={props.navigationParent}
12151215
aria-label={accessibility.label}
@@ -1404,8 +1404,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
14041404
render={
14051405
<div
14061406
ref={rowRef}
1407-
role="treeitem"
1408-
tabIndex={-1}
1407+
role="button"
1408+
tabIndex={0}
14091409
data-sidebar-row={threadKey}
14101410
data-sidebar-parent={props.navigationParent}
14111411
aria-label={accessibility.label}

‎apps/web/src/lib/sidebarTree.browser.test.ts‎

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ import { installSidebarTree } from "./sidebarTree";
44

55
function setup() {
66
const root = document.createElement("div");
7-
root.setAttribute("role", "tree");
87
document.body.append(root);
98
let dispose: (() => void) | undefined;
109
const row = (id: string, parent?: string) => {
1110
const element = document.createElement("button");
1211
element.dataset.sidebarRow = id;
1312
if (parent) element.dataset.sidebarParent = parent;
14-
element.setAttribute("role", "treeitem");
1513
element.textContent = id;
1614
root.append(element);
1715
return element;
@@ -36,7 +34,7 @@ function press(target: HTMLElement, key: string, init: KeyboardEventInit = {}) {
3634
}
3735

3836
describe("sidebar keyboard navigation", () => {
39-
it("moves focus without activating rows, clamps at the ends, and keeps one Tab stop", () => {
37+
it("moves focus without activating rows, clamps at the ends, and keeps every row in the Tab order", () => {
4038
using tree = setup();
4139
const first = tree.row("first");
4240
const second = tree.row("second");
@@ -54,10 +52,10 @@ describe("sidebar keyboard navigation", () => {
5452
press(last, "Home");
5553
expect(document.activeElement).toBe(first);
5654
expect(activate).not.toHaveBeenCalled();
57-
expect(tree.root.querySelectorAll('[tabindex="0"]')).toHaveLength(1);
55+
expect([first.tabIndex, second.tabIndex, last.tabIndex]).toEqual([0, 0, 0]);
5856
});
5957

60-
it("expands a group before entering its first child and returns to the parent", async () => {
58+
it("expands a group before entering its first child and returns to the parent", () => {
6159
using tree = setup();
6260
const group = tree.row("project");
6361
group.setAttribute("aria-expanded", "false");
@@ -72,12 +70,6 @@ describe("sidebar keyboard navigation", () => {
7270
press(group, "ArrowRight");
7371
expect(group.getAttribute("aria-expanded")).toBe("true");
7472
expect(document.activeElement).toBe(group);
75-
// The tree picks up the new child from its mutation observer.
76-
await vi.waitFor(() =>
77-
expect(
78-
tree.root.querySelector('[data-sidebar-parent="project"]')?.getAttribute("aria-level"),
79-
).toBe("2"),
80-
);
8173
press(group, "ArrowRight");
8274
const child = document.activeElement as HTMLElement;
8375
expect(child.dataset.sidebarRow).toBe("thread");
@@ -104,7 +96,7 @@ describe("sidebar keyboard navigation", () => {
10496
expect(document.activeElement).toBe(selected);
10597
});
10698

107-
it("lets Tab reach only the focused row's buttons", () => {
99+
it("leaves every row's buttons in the Tab order", () => {
108100
using tree = setup();
109101
const first = tree.row("first");
110102
const second = tree.row("second");
@@ -119,10 +111,10 @@ describe("sidebar keyboard navigation", () => {
119111
const secondAction = action("second");
120112
tree.install();
121113
first.focus();
122-
expect([firstAction.tabIndex, secondAction.tabIndex]).toEqual([0, -1]);
114+
expect([firstAction.tabIndex, secondAction.tabIndex]).toEqual([0, 0]);
123115
press(first, "ArrowDown");
124116
expect(document.activeElement).toBe(second);
125-
expect([firstAction.tabIndex, secondAction.tabIndex]).toEqual([-1, 0]);
117+
expect([firstAction.tabIndex, secondAction.tabIndex]).toEqual([0, 0]);
126118
});
127119

128120
it("keeps a rendered row under a collapsed group reachable", () => {
@@ -152,26 +144,6 @@ describe("sidebar keyboard navigation", () => {
152144
expect(undo.tabIndex).toBe(0);
153145
});
154146

155-
it("gives row buttons back their own tab order when the tree reinstalls", () => {
156-
using tree = setup();
157-
tree.row("first");
158-
const second = tree.row("second");
159-
const action = (owner: string) => {
160-
const button = document.createElement("button");
161-
button.dataset.sidebarActionFor = owner;
162-
tree.root.append(button);
163-
return button;
164-
};
165-
const firstAction = action("first");
166-
const secondAction = action("second");
167-
const dispose = installSidebarTree(tree.root);
168-
second.focus();
169-
dispose();
170-
expect([firstAction.tabIndex, secondAction.tabIndex]).toEqual([0, 0]);
171-
tree.install();
172-
expect([firstAction.tabIndex, secondAction.tabIndex]).toEqual([-1, 0]);
173-
});
174-
175147
it("keeps the scroll position when focus follows a row that moved away", async () => {
176148
using tree = setup();
177149
Object.assign(tree.root.style, { height: "100px", overflow: "auto" });
@@ -191,24 +163,26 @@ describe("sidebar keyboard navigation", () => {
191163
expect(tree.root.scrollTop).toBe(0);
192164
});
193165

194-
it("does not pull focus back after a click outside the tree", async () => {
166+
it("does not pull focus back after a click outside the rows", async () => {
195167
using tree = setup();
196168
const first = tree.row("first");
197169
tree.install();
198170
const text = document.createElement("p");
199171
text.textContent = "Chat text";
200172
document.body.append(text);
201173
using _text = { [Symbol.dispose]: () => text.remove() };
202-
first.focus();
203-
await userEvent.click(text);
204-
expect(document.activeElement).toBe(document.body);
205-
// A status change re-renders the tree while the user works elsewhere.
206-
tree.row("second");
207-
await vi.waitFor(() =>
208-
expect(
209-
tree.root.querySelector('[data-sidebar-row="second"]')?.getAttribute("aria-posinset"),
210-
).toBe("2"),
211-
);
212-
expect(document.activeElement).toBe(document.body);
174+
const spacer = document.createElement("div");
175+
spacer.textContent = "Empty list space";
176+
tree.root.append(spacer);
177+
for (const target of [text, spacer]) {
178+
first.focus();
179+
await userEvent.click(target);
180+
expect(document.activeElement).toBe(document.body);
181+
// A status change re-renders the list while the user works elsewhere.
182+
tree.row(`second-${target.tagName}`);
183+
// The list's mutation observer callback is queued ahead of this continuation.
184+
await Promise.resolve();
185+
expect(document.activeElement).toBe(document.body);
186+
}
213187
});
214188
});

0 commit comments

Comments
 (0)