Skip to content

Commit 092cb2d

Browse files
author
eshaan Sood
committed
fix(accessibility): correct control announcements and sidebar traversal
1 parent f61f979 commit 092cb2d

9 files changed

Lines changed: 240 additions & 23 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import type { ReactNode } from "react";
2+
import { renderToStaticMarkup } from "react-dom/server";
3+
import { describe, expect, it, vi } from "vite-plus/test";
4+
5+
vi.mock("react-native", () => ({
6+
View: ({ children }: { children: ReactNode }) => <div>{children}</div>,
7+
}));
8+
vi.mock("../../components/AppText", () => ({
9+
AppText: ({
10+
accessibilityElementsHidden,
11+
importantForAccessibility,
12+
children,
13+
}: {
14+
accessibilityElementsHidden?: boolean;
15+
importantForAccessibility?: string;
16+
children: ReactNode;
17+
}) => (
18+
<span
19+
aria-hidden={
20+
accessibilityElementsHidden || importantForAccessibility === "no-hide-descendants"
21+
}
22+
>
23+
{children}
24+
</span>
25+
),
26+
AppTextInput: ({ accessibilityLabel }: { accessibilityLabel?: string }) => (
27+
<input aria-label={accessibilityLabel} />
28+
),
29+
}));
30+
31+
import { ConnectionFormField } from "./ConnectionFormField";
32+
33+
describe("ConnectionFormField accessibility", () => {
34+
it.each(["Host", "Pairing code"])("exposes %s once as the input name", (label) => {
35+
const markup = renderToStaticMarkup(
36+
<ConnectionFormField label={label} placeholder="Not an accessible name" />,
37+
);
38+
39+
expect(markup).toContain(`<span aria-hidden="true">${label}</span>`);
40+
expect(markup).toContain(`<input aria-label="${label}"/>`);
41+
});
42+
});

‎apps/mobile/src/features/connection/ConnectionFormField.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { View } from "react-native";
33
import { AppText, AppTextInput, type AppTextInputProps } from "../../components/AppText";
44
import { cn } from "../../lib/cn";
55

6-
type ConnectionFormFieldProps = Omit<AppTextInputProps, "className"> & {
6+
type ConnectionFormFieldProps = Omit<AppTextInputProps, "accessibilityLabel" | "className"> & {
77
readonly label: string;
88
readonly className?: string;
99
};
@@ -12,12 +12,16 @@ type ConnectionFormFieldProps = Omit<AppTextInputProps, "className"> & {
1212
export function ConnectionFormField({ label, className, ...inputProps }: ConnectionFormFieldProps) {
1313
return (
1414
<View collapsable={false} className={cn("gap-1.5", className)}>
15-
<AppText className="text-2xs font-t3-bold tracking-[0.8px] uppercase text-foreground-muted">
15+
<AppText
16+
accessibilityElementsHidden
17+
importantForAccessibility="no-hide-descendants"
18+
className="text-2xs font-t3-bold tracking-[0.8px] uppercase text-foreground-muted"
19+
>
1620
{label}
1721
</AppText>
1822
<AppTextInput
19-
accessibilityLabel={label}
2023
{...inputProps}
24+
accessibilityLabel={label}
2125
className="rounded-[14px] px-4 py-3.5"
2226
/>
2327
</View>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) {
296296
side="left"
297297
collapsible="offcanvas"
298298
data-app-sidebar=""
299+
role="navigation"
300+
aria-label={isOnSettings ? "Settings" : "Threads"}
299301
resizable={{
300302
maxWidth: sidebarMaximumWidth,
301303
minWidth: THREAD_SIDEBAR_MIN_WIDTH,

‎apps/web/src/components/Sidebar.logic.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
isTrailingDoubleClick,
2424
orderItemsByPreferredIds,
2525
resolveProjectStatusIndicator,
26+
resolveSidebarRowAccessibility,
2627
resolveSidebarThreadStatus,
2728
resolveThreadStatusPill,
2829
resolveWorkingStartedAt,
@@ -69,6 +70,35 @@ import {
6970

7071
const localEnvironmentId = EnvironmentId.make("environment-local");
7172

73+
describe("resolveSidebarRowAccessibility", () => {
74+
it.each([
75+
{
76+
title: "Can you audit the UI?",
77+
statusLabel: "Working",
78+
projectDisplayName: "T3 Code",
79+
isActive: true,
80+
expected: { label: "Can you audit the UI?, Working, T3 Code", current: "page" },
81+
},
82+
{
83+
title: "The audit is done",
84+
statusLabel: null,
85+
projectDisplayName: "T3 Code",
86+
isActive: false,
87+
expected: { label: "The audit is done, T3 Code", current: undefined },
88+
},
89+
{
90+
title: "Untitled task",
91+
statusLabel: null,
92+
projectDisplayName: null,
93+
isActive: false,
94+
expected: { label: "Untitled task", current: undefined },
95+
},
96+
])("leads with the title without folding row actions into its name: %j", (input) => {
97+
const { expected, ...state } = input;
98+
expect(resolveSidebarRowAccessibility(state)).toEqual(expected);
99+
});
100+
});
101+
72102
describe("animateSidebarLayoutChanges", () => {
73103
const baseArgs: Parameters<AnimateLayoutChanges>[0] = {
74104
active: null,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ export function shouldNavigateAfterThreadPark(input: {
4444

4545
const THREAD_SELECTION_SAFE_SELECTOR = "[data-thread-item], [data-thread-selection-safe]";
4646
export const THREAD_JUMP_HINT_SHOW_DELAY_MS = 200;
47+
48+
export function resolveSidebarRowAccessibility(input: {
49+
readonly title: string;
50+
readonly statusLabel: string | null;
51+
readonly projectDisplayName: string | null;
52+
readonly isActive: boolean;
53+
}): { readonly label: string; readonly current: "page" | undefined } {
54+
return {
55+
// The title is the row's identity and must lead when users scan tasks.
56+
// Only static context belongs here; nested action labels remain separate controls.
57+
label: [input.title, input.statusLabel, input.projectDisplayName].filter(Boolean).join(", "),
58+
current: input.isActive ? "page" : undefined,
59+
};
60+
}
61+
4762
// Visible sidebar rows are prewarmed into the thread-detail cache so opening a
4863
// nearby thread usually reuses an already-hot subscription. Each prewarmed
4964
// thread holds a live, fully hydrated detail subscription (all messages and

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

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ import {
170170
resolveAdjacentThreadId,
171171
resolveSidebarDropTarget,
172172
resolveSidebarDropVerb,
173+
resolveSidebarRowAccessibility,
173174
type SidebarDropVerb,
174175
resolveSidebarThreadStatus,
175176
searchSidebarThreads,
@@ -725,6 +726,12 @@ const SidebarDraftRow = memo(function SidebarDraftRow(props: {
725726
promptPreview.length > 0
726727
? promptPreview
727728
: `${attachmentCount} attachment${attachmentCount === 1 ? "" : "s"}`;
729+
const accessibility = resolveSidebarRowAccessibility({
730+
title: preview,
731+
statusLabel: "Unsent draft",
732+
projectDisplayName: props.projectDisplayName,
733+
isActive: props.isActive,
734+
});
728735
const handleActivate = useCallback(() => onNavigate(draftId), [draftId, onNavigate]);
729736
const handleKeyDown = useCallback(
730737
(event: ReactKeyboardEvent) => {
@@ -752,6 +759,8 @@ const SidebarDraftRow = memo(function SidebarDraftRow(props: {
752759
<div
753760
role="button"
754761
tabIndex={0}
762+
aria-label={accessibility.label}
763+
aria-current={accessibility.current}
755764
data-testid="sidebar-draft-row"
756765
className={cn(
757766
"group/sidebar-row relative w-full cursor-pointer overflow-hidden rounded-md text-left text-sidebar-foreground outline-none select-none",
@@ -760,6 +769,7 @@ const SidebarDraftRow = memo(function SidebarDraftRow(props: {
760769
onClick={handleActivate}
761770
onKeyDown={handleKeyDown}
762771
>
772+
<span className="sr-only">{preview}</span>
763773
<div className="relative z-10 h-[4.875rem] px-(--sidebar-row-content-inset) py-(--sidebar-content-inset)">
764774
<div className="flex h-5 min-w-0 items-center gap-1.5">
765775
<SquarePenIcon aria-hidden className={draftPenClassName} />
@@ -787,7 +797,9 @@ const SidebarDraftRow = memo(function SidebarDraftRow(props: {
787797
</Tooltip>
788798
</span>
789799
</div>
790-
<div className="mt-0.5 truncate text-sm font-medium text-foreground/90">{preview}</div>
800+
<div aria-hidden className="mt-0.5 truncate text-sm font-medium text-foreground/90">
801+
{preview}
802+
</div>
791803
</div>
792804
</div>
793805
</li>
@@ -1439,6 +1451,13 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
14391451
</span>
14401452
) : null;
14411453

1454+
const accessibility = resolveSidebarRowAccessibility({
1455+
title: thread.title,
1456+
statusLabel: topStatus?.label ?? null,
1457+
projectDisplayName: props.projectDisplayName,
1458+
isActive: props.isActive,
1459+
});
1460+
14421461
const title = isRenaming ? (
14431462
<input
14441463
autoFocus
@@ -1454,6 +1473,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
14541473
/>
14551474
) : (
14561475
<span
1476+
aria-hidden
14571477
className={cn(
14581478
"min-w-0 flex-1 text-sm transition-opacity motion-reduce:transition-none",
14591479
shouldRecede ? "font-normal" : "font-medium",
@@ -1484,6 +1504,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
14841504
{thread.title}
14851505
</span>
14861506
);
1507+
const accessibleTitle = isRenaming ? null : <span className="sr-only">{thread.title}</span>;
14871508

14881509
// Stacks show their layer count; multiple unrelated links show their total count.
14891510
// Plain clicks open T3; individual PR links also support opening the host in a new tab.
@@ -1582,6 +1603,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
15821603
ref={rowRef}
15831604
role="button"
15841605
tabIndex={0}
1606+
aria-label={accessibility.label}
1607+
aria-current={accessibility.current}
15851608
data-testid="sidebar-row-slim"
15861609
aria-busy={isRegeneratingTitle || undefined}
15871610
className={cn(rowSurfaceClassName, "flex h-9 items-center gap-2.5 px-2.5")}
@@ -1592,6 +1615,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
15921615
/>
15931616
}
15941617
>
1618+
{accessibleTitle}
15951619
{/* Settled history recedes: dimmed favicon at rest, restored on
15961620
hover so the tail stays scannable when you're hunting. */}
15971621
<span
@@ -1735,6 +1759,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
17351759
ref={rowRef}
17361760
role="button"
17371761
tabIndex={0}
1762+
aria-label={accessibility.label}
1763+
aria-current={accessibility.current}
17381764
data-testid="sidebar-row-card"
17391765
aria-busy={isRegeneratingTitle || undefined}
17401766
className={rowSurfaceClassName}
@@ -1745,6 +1771,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
17451771
/>
17461772
}
17471773
>
1774+
{accessibleTitle}
17481775
<div className="relative z-10 h-[4.875rem] px-(--sidebar-row-content-inset) py-(--sidebar-content-inset)">
17491776
<div className="flex h-5 min-w-0 items-center gap-1.5">
17501777
{draftIndicator}
@@ -1997,6 +2024,12 @@ const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props: {
19972024
onFileDropThreads: (threadRef: ScopedThreadRef, files: File[]) => void;
19982025
}) {
19992026
const { thread } = props;
2027+
const accessibility = resolveSidebarRowAccessibility({
2028+
title: thread.title,
2029+
statusLabel: null,
2030+
projectDisplayName: props.projectDisplayName,
2031+
isActive: props.isRouteActive,
2032+
});
20002033
const threadRef = useMemo(
20012034
() => scopeThreadRef(thread.environmentId, thread.id),
20022035
[thread.environmentId, thread.id],
@@ -2073,12 +2106,8 @@ const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props: {
20732106
// which owns all keyboard interaction for the listbox.
20742107
tabIndex={-1}
20752108
aria-selected={props.isHighlighted}
2076-
aria-current={props.isRouteActive ? "page" : undefined}
2077-
aria-label={
2078-
props.projectDisplayName
2079-
? `${thread.title}, ${props.projectDisplayName}`
2080-
: thread.title
2081-
}
2109+
aria-current={accessibility.current}
2110+
aria-label={accessibility.label}
20822111
onMouseMove={props.onHighlight}
20832112
onClick={props.onSelect}
20842113
className={cn(
@@ -4537,7 +4566,7 @@ export default function Sidebar() {
45374566
</SidebarGroup>
45384567
}
45394568
>
4540-
<SidebarGroup className="flex-1">
4569+
<SidebarGroup className="flex-1" role="presentation">
45414570
{isSearchingThreads ? (
45424571
threadSearchResults.length > 0 ? (
45434572
<TooltipProvider
@@ -4628,7 +4657,11 @@ export default function Sidebar() {
46284657
<SortableContext items={sortableIds} strategy={sidebarSortingStrategy}>
46294658
<ul
46304659
ref={attachListMotionRef}
4631-
role="list"
4660+
// VoiceOver treats an exposed list as an interaction boundary,
4661+
// which hides its rows from ordinary linear navigation. A
4662+
// presentational list also makes its implicit listitems
4663+
// presentational while preserving every descendant control.
4664+
role="presentation"
46324665
className={cn(
46334666
"relative flex flex-col gap-px",
46344667
sidebarListItems.length > 0 && "flex-1",

‎apps/web/src/components/ui/scroll-area.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function ScrollArea({
3030
hideScrollbars = false,
3131
chainVerticalScroll = false,
3232
radius = "inherit",
33+
viewportTabIndex,
3334
...props
3435
}: ScrollAreaPrimitive.Root.Props & {
3536
scrollFade?: boolean;
@@ -41,6 +42,8 @@ function ScrollArea({
4142
chainVerticalScroll?: boolean;
4243
/** The viewport clips to the parent's radius; "none" for a region flush to an edge. */
4344
radius?: "inherit" | "none";
45+
/** Override Base UI's focusable viewport when focusable descendants provide scroll access. */
46+
viewportTabIndex?: number;
4447
}) {
4548
return (
4649
<ScrollAreaPrimitive.Root
@@ -52,6 +55,7 @@ function ScrollArea({
5255
{...props}
5356
>
5457
<ScrollAreaPrimitive.Viewport
58+
{...(viewportTabIndex === undefined ? {} : { tabIndex: viewportTabIndex })}
5559
className={cn(
5660
"h-full max-h-[inherit] overflow-auto overscroll-contain rounded-[inherit] outline-none transition-shadow focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background data-has-overflow-x:overscroll-x-contain",
5761
chainVerticalScroll && "overscroll-y-auto",

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,10 @@ function SidebarContent({
597597
hideScrollbars
598598
scrollFade
599599
scrollFadePadding={false}
600+
// Thread rows provide keyboard access to this scroll region. Keeping
601+
// Base UI's viewport out of the tab order lets its presentational role
602+
// flatten in WebKit instead of becoming a VoiceOver interaction group.
603+
viewportTabIndex={-1}
600604
className="h-auto min-h-0 flex-1 [&>[data-slot=scroll-area-viewport]]:[--fade-size:0.75rem]"
601605
>
602606
<div

0 commit comments

Comments
 (0)