Skip to content
TypeScript

fix(accessibility): correct control announcements and sidebar traversal (#13491)

blinding-pixels393d595984f6
diff --git a/apps/mobile/src/features/connection/ConnectionFormField.test.tsx b/apps/mobile/src/features/connection/ConnectionFormField.test.tsx
new file mode 100644
index 00000000000..343d44cf376
--- /dev/null
+++ b/apps/mobile/src/features/connection/ConnectionFormField.test.tsx
@@ -0,0 +1,42 @@
+import type { ReactNode } from "react";
+import { renderToStaticMarkup } from "react-dom/server";
+import { describe, expect, it, vi } from "vite-plus/test";
+
+vi.mock("react-native", () => ({
+ View: ({ children }: { children: ReactNode }) => <div>{children}</div>,
+}));
+vi.mock("../../components/AppText", () => ({
+ AppText: ({
+ accessibilityElementsHidden,
+ importantForAccessibility,
+ children,
+ }: {
+ accessibilityElementsHidden?: boolean;
+ importantForAccessibility?: string;
+ children: ReactNode;
+ }) => (
+ <span
+ aria-hidden={
+ accessibilityElementsHidden || importantForAccessibility === "no-hide-descendants"
+ }
+ >
+ {children}
+ </span>
+ ),
+ AppTextInput: ({ accessibilityLabel }: { accessibilityLabel?: string }) => (
+ <input aria-label={accessibilityLabel} />
+ ),
+}));
+
+import { ConnectionFormField } from "./ConnectionFormField";
+
+describe("ConnectionFormField accessibility", () => {
+ it.each(["Host", "Pairing code"])("exposes %s once as the input name", (label) => {
+ const markup = renderToStaticMarkup(
+ <ConnectionFormField label={label} placeholder="Not an accessible name" />,
+ );
+
+ expect(markup).toContain(`<span aria-hidden="true">${label}</span>`);
+ expect(markup).toContain(`<input aria-label="${label}"/>`);
+ });
+});
diff --git a/apps/mobile/src/features/connection/ConnectionFormField.tsx b/apps/mobile/src/features/connection/ConnectionFormField.tsx
index 0d5e21148e5..b492dd9ce43 100644
--- a/apps/mobile/src/features/connection/ConnectionFormField.tsx
+++ b/apps/mobile/src/features/connection/ConnectionFormField.tsx
@@ -3,7 +3,7 @@ import { View } from "react-native";
import { AppText, AppTextInput, type AppTextInputProps } from "../../components/AppText";
import { cn } from "../../lib/cn";
-type ConnectionFormFieldProps = Omit<AppTextInputProps, "className"> & {
+type ConnectionFormFieldProps = Omit<AppTextInputProps, "accessibilityLabel" | "className"> & {
readonly label: string;
readonly className?: string;
};
@@ -12,12 +12,16 @@ type ConnectionFormFieldProps = Omit<AppTextInputProps, "className"> & {
export function ConnectionFormField({ label, className, ...inputProps }: ConnectionFormFieldProps) {
return (
<View collapsable={false} className={cn("gap-1.5", className)}>
- <AppText className="text-2xs font-t3-bold tracking-[0.8px] uppercase text-foreground-muted">
+ <AppText
+ accessibilityElementsHidden
+ importantForAccessibility="no-hide-descendants"
+ className="text-2xs font-t3-bold tracking-[0.8px] uppercase text-foreground-muted"
+ >
{label}
</AppText>
<AppTextInput
- accessibilityLabel={label}
{...inputProps}
+ accessibilityLabel={label}
className="rounded-[14px] px-4 py-3.5"
/>
</View>
diff --git a/apps/web/src/components/AppSidebarLayout.tsx b/apps/web/src/components/AppSidebarLayout.tsx
index 7e3eaad1125..05d965d95d0 100644
--- a/apps/web/src/components/AppSidebarLayout.tsx
+++ b/apps/web/src/components/AppSidebarLayout.tsx
@@ -304,6 +304,8 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) {
side="left"
collapsible="offcanvas"
data-app-sidebar=""
+ role="navigation"
+ aria-label={isOnSettings ? "Settings" : "Threads"}
resizable={{
maxWidth: sidebarMaximumWidth,
minWidth: THREAD_SIDEBAR_MIN_WIDTH,
diff --git a/apps/web/src/components/Sidebar.logic.test.ts b/apps/web/src/components/Sidebar.logic.test.ts
index b4b07805596..fede3c18344 100644
--- a/apps/web/src/components/Sidebar.logic.test.ts
+++ b/apps/web/src/components/Sidebar.logic.test.ts
@@ -23,6 +23,7 @@ import {
isTrailingDoubleClick,
orderItemsByPreferredIds,
resolveProjectStatusIndicator,
+ resolveSidebarRowAccessibility,
resolveSidebarThreadStatus,
resolveThreadStatusPill,
resolveWorkingStartedAt,
@@ -69,6 +70,35 @@ import {
const localEnvironmentId = EnvironmentId.make("environment-local");
+describe("resolveSidebarRowAccessibility", () => {
+ it.each([
+ {
+ title: "Can you audit the UI?",
+ statusLabel: "Working",
+ projectDisplayName: "T3 Code",
+ isActive: true,
+ expected: { label: "Can you audit the UI?, Working, T3 Code", current: "page" },
+ },
+ {
+ title: "The audit is done",
+ statusLabel: null,
+ projectDisplayName: "T3 Code",
+ isActive: false,
+ expected: { label: "The audit is done, T3 Code", current: undefined },
+ },
+ {
+ title: "Untitled task",
+ statusLabel: null,
+ projectDisplayName: null,
+ isActive: false,
+ expected: { label: "Untitled task", current: undefined },
+ },
+ ])("leads with the title without folding row actions into its name: %j", (input) => {
+ const { expected, ...state } = input;
+ expect(resolveSidebarRowAccessibility(state)).toEqual(expected);
+ });
+});
+
describe("animateSidebarLayoutChanges", () => {
const baseArgs: Parameters<AnimateLayoutChanges>[0] = {
active: null,
diff --git a/apps/web/src/components/Sidebar.logic.ts b/apps/web/src/components/Sidebar.logic.ts
index 3e12090f322..2796b2f7f88 100644
--- a/apps/web/src/components/Sidebar.logic.ts
+++ b/apps/web/src/components/Sidebar.logic.ts
@@ -42,6 +42,21 @@ export function shouldNavigateAfterThreadPark(input: {
const THREAD_SELECTION_SAFE_SELECTOR = "[data-thread-item], [data-thread-selection-safe]";
export const THREAD_JUMP_HINT_SHOW_DELAY_MS = 200;
+
+export function resolveSidebarRowAccessibility(input: {
+ readonly title: string;
+ readonly statusLabel: string | null;
+ readonly projectDisplayName: string | null;
+ readonly isActive: boolean;
+}): { readonly label: string; readonly current: "page" | undefined } {
+ return {
+ // The title is the row's identity and must lead when users scan tasks.
+ // Only static context belongs here; nested action labels remain separate controls.
+ label: [input.title, input.statusLabel, input.projectDisplayName].filter(Boolean).join(", "),
+ current: input.isActive ? "page" : undefined,
+ };
+}
+
// Visible sidebar rows are prewarmed into the thread-detail cache so opening a
// nearby thread usually reuses an already-hot subscription. Each prewarmed
// thread holds a live, fully hydrated detail subscription (all messages and
diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx
index 4926df4948a..90f65ea2b94 100644
--- a/apps/web/src/components/Sidebar.tsx
+++ b/apps/web/src/components/Sidebar.tsx
@@ -173,6 +173,7 @@ import {
resolveAdjacentThreadId,
resolveSidebarDropTarget,
resolveSidebarDropVerb,
+ resolveSidebarRowAccessibility,
type SidebarDropVerb,
resolveSidebarThreadStatus,
searchSidebarThreads,
@@ -728,6 +729,12 @@ const SidebarDraftRow = memo(function SidebarDraftRow(props: {
promptPreview.length > 0
? promptPreview
: `${attachmentCount} attachment${attachmentCount === 1 ? "" : "s"}`;
+ const accessibility = resolveSidebarRowAccessibility({
+ title: preview,
+ statusLabel: "Unsent draft",
+ projectDisplayName: props.projectDisplayName,
+ isActive: props.isActive,
+ });
const handleActivate = useCallback(() => onNavigate(draftId), [draftId, onNavigate]);
const handleKeyDown = useCallback(
(event: ReactKeyboardEvent) => {
@@ -755,6 +762,8 @@ const SidebarDraftRow = memo(function SidebarDraftRow(props: {
<div
role="button"
tabIndex={0}
+ aria-label={accessibility.label}
+ aria-current={accessibility.current}
data-testid="sidebar-draft-row"
className={cn(
"group/sidebar-row relative w-full cursor-pointer overflow-hidden rounded-md text-left text-sidebar-foreground outline-none select-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
@@ -763,6 +772,7 @@ const SidebarDraftRow = memo(function SidebarDraftRow(props: {
onClick={handleActivate}
onKeyDown={handleKeyDown}
>
+ <span className="sr-only">{preview}</span>
<div className="relative z-10 h-[4.875rem] px-(--sidebar-row-content-inset) py-(--sidebar-content-inset)">
<div className="flex h-5 min-w-0 items-center gap-1.5">
<SquarePenIcon aria-hidden className={draftPenClassName} />
@@ -790,7 +800,9 @@ const SidebarDraftRow = memo(function SidebarDraftRow(props: {
</Tooltip>
</span>
</div>
- <div className="mt-0.5 truncate text-sm font-medium text-foreground/90">{preview}</div>
+ <div aria-hidden className="mt-0.5 truncate text-sm font-medium text-foreground/90">
+ {preview}
+ </div>
</div>
</div>
</li>
@@ -1447,6 +1459,13 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
</span>
) : null;
+ const accessibility = resolveSidebarRowAccessibility({
+ title: thread.title,
+ statusLabel: topStatus?.label ?? null,
+ projectDisplayName: props.projectDisplayName,
+ isActive: props.isActive,
+ });
+
const title = isRenaming ? (
<input
autoFocus
@@ -1462,6 +1481,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
/>
) : (
<span
+ aria-hidden
className={cn(
"min-w-0 flex-1 text-sm transition-opacity motion-reduce:transition-none",
shouldRecede ? "font-normal" : "font-medium",
@@ -1492,6 +1512,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
{thread.title}
</span>
);
+ const accessibleTitle = isRenaming ? null : <span className="sr-only">{thread.title}</span>;
// Stacks show their layer count; multiple unrelated links show their total count.
// Plain clicks open T3; individual PR links also support opening the host in a new tab.
@@ -1593,6 +1614,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
ref={rowRef}
role="button"
tabIndex={0}
+ aria-label={accessibility.label}
+ aria-current={accessibility.current}
data-testid="sidebar-row-slim"
aria-busy={isRegeneratingTitle || undefined}
className={cn(rowSurfaceClassName, "flex h-9 items-center gap-2.5 px-2.5")}
@@ -1603,6 +1626,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
/>
}
>
+ {accessibleTitle}
{/* Settled history recedes: dimmed favicon at rest, restored on
hover so the tail stays scannable when you're hunting. */}
<span
@@ -1746,6 +1770,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
ref={rowRef}
role="button"
tabIndex={0}
+ aria-label={accessibility.label}
+ aria-current={accessibility.current}
data-testid="sidebar-row-card"
aria-busy={isRegeneratingTitle || undefined}
className={rowSurfaceClassName}
@@ -1756,6 +1782,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
/>
}
>
+ {accessibleTitle}
<div className="relative z-10 h-[4.875rem] px-(--sidebar-row-content-inset) py-(--sidebar-content-inset)">
<div className="flex h-5 min-w-0 items-center gap-1.5">
{draftIndicator}
@@ -2008,6 +2035,12 @@ const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props: {
onFileDropThreads: (threadRef: ScopedThreadRef, files: File[]) => void;
}) {
const { thread } = props;
+ const accessibility = resolveSidebarRowAccessibility({
+ title: thread.title,
+ statusLabel: null,
+ projectDisplayName: props.projectDisplayName,
+ isActive: props.isRouteActive,
+ });
const threadRef = useMemo(
() => scopeThreadRef(thread.environmentId, thread.id),
[thread.environmentId, thread.id],
@@ -2084,12 +2117,8 @@ const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props: {
// which owns all keyboard interaction for the listbox.
tabIndex={-1}
aria-selected={props.isHighlighted}
- aria-current={props.isRouteActive ? "page" : undefined}
- aria-label={
- props.projectDisplayName
- ? `${thread.title}, ${props.projectDisplayName}`
- : thread.title
- }
+ aria-current={accessibility.current}
+ aria-label={accessibility.label}
onMouseMove={props.onHighlight}
onClick={props.onSelect}
className={cn(
@@ -4573,7 +4602,7 @@ export default function Sidebar() {
</SidebarGroup>
}
>
- <SidebarGroup className="flex-1">
+ <SidebarGroup className="flex-1" role="presentation">
{isSearchingThreads ? (
threadSearchResults.length > 0 ? (
<TooltipProvider
@@ -4664,7 +4693,11 @@ export default function Sidebar() {
<SortableContext items={sortableIds} strategy={sidebarSortingStrategy}>
<ul
ref={attachListMotionRef}
- role="list"
+ // VoiceOver treats an exposed list as an interaction boundary,
+ // which hides its rows from ordinary linear navigation. A
+ // presentational list also makes its implicit listitems
+ // presentational while preserving every descendant control.
+ role="presentation"
className={cn(
"relative flex flex-col gap-px",
sidebarListItems.length > 0 && "flex-1",
diff --git a/apps/web/src/components/ui/scroll-area.tsx b/apps/web/src/components/ui/scroll-area.tsx
index 7792b9606e4..ce9d41edaa5 100644
--- a/apps/web/src/components/ui/scroll-area.tsx
+++ b/apps/web/src/components/ui/scroll-area.tsx
@@ -30,6 +30,7 @@ function ScrollArea({
hideScrollbars = false,
chainVerticalScroll = false,
radius = "inherit",
+ viewportTabIndex,
...props
}: ScrollAreaPrimitive.Root.Props & {
scrollFade?: boolean;
@@ -41,6 +42,8 @@ function ScrollArea({
chainVerticalScroll?: boolean;
/** The viewport clips to the parent's radius; "none" for a region flush to an edge. */
radius?: "inherit" | "none";
+ /** Override Base UI's focusable viewport when focusable descendants provide scroll access. */
+ viewportTabIndex?: number;
}) {
return (
<ScrollAreaPrimitive.Root
@@ -52,6 +55,7 @@ function ScrollArea({
{...props}
>
<ScrollAreaPrimitive.Viewport
+ {...(viewportTabIndex === undefined ? {} : { tabIndex: viewportTabIndex })}
className={cn(
"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",
chainVerticalScroll && "overscroll-y-auto",
diff --git a/apps/web/src/components/ui/sidebar.tsx b/apps/web/src/components/ui/sidebar.tsx
index c3759f2c059..58957b1477d 100644
--- a/apps/web/src/components/ui/sidebar.tsx
+++ b/apps/web/src/components/ui/sidebar.tsx
@@ -233,7 +233,7 @@ function Sidebar({
if (isMobile) {
return (
<SidebarInstanceContext value={instanceContextValue}>
- <Sheet onOpenChange={setOpenMobile} open={openMobile} {...props}>
+ <Sheet onOpenChange={setOpenMobile} open={openMobile}>
<SheetPopup
className={cn(
"w-(--sidebar-width) max-w-none bg-sidebar surface-grain p-0 text-sidebar-foreground",
@@ -259,6 +259,7 @@ function Sidebar({
"flex h-full w-full flex-col pb-safe pt-safe",
side === "left" ? "pl-safe" : "pr-safe",
)}
+ {...props}
>
{children}
</div>
@@ -597,6 +598,10 @@ function SidebarContent({
hideScrollbars
scrollFade
scrollFadePadding={false}
+ // Thread rows provide keyboard access to this scroll region. Keeping
+ // Base UI's viewport out of the tab order lets its presentational role
+ // flatten in WebKit instead of becoming a VoiceOver interaction group.
+ viewportTabIndex={-1}
className="h-auto min-h-0 flex-1 [&>[data-slot=scroll-area-viewport]]:[--fade-size:0.75rem]"
>
<div
diff --git a/apps/web/src/components/ui/switch.test.tsx b/apps/web/src/components/ui/switch.test.tsx
index b63fa79e384..4b21d7018d4 100644
--- a/apps/web/src/components/ui/switch.test.tsx
+++ b/apps/web/src/components/ui/switch.test.tsx
@@ -1,20 +1,80 @@
-import { renderToStaticMarkup } from "react-dom/server";
-import { describe, expect, it } from "vite-plus/test";
+// @vitest-environment jsdom
+
+import { act, useState } from "react";
+import { createRoot, type Root } from "react-dom/client";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
import { Switch } from "./switch";
-function renderSwitchRoot(props: Partial<Parameters<typeof Switch>[0]>) {
- const html = renderToStaticMarkup(<Switch aria-label="Enable Claude Code" {...props} />);
- return html.match(/<span[^>]*role="switch"[^>]*>/)?.[0] ?? "";
+let root: Root;
+let container: HTMLDivElement;
+
+beforeEach(() => {
+ vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
+ container = document.createElement("div");
+ document.body.append(container);
+ root = createRoot(container);
+});
+
+afterEach(async () => {
+ await act(async () => root.unmount());
+ container.remove();
+ vi.unstubAllGlobals();
+});
+
+function ControlledSwitch({
+ initialChecked,
+ initialMixed = false,
+}: {
+ initialChecked: boolean;
+ initialMixed?: boolean;
+}) {
+ const [checked, setChecked] = useState(initialChecked);
+ const [mixed, setMixed] = useState(initialMixed);
+
+ return (
+ <Switch
+ aria-label="Enable Claude Code"
+ checked={checked}
+ mixed={mixed}
+ onCheckedChange={(nextChecked) => {
+ setMixed(false);
+ setChecked(nextChecked);
+ }}
+ />
+ );
}
-describe("Switch accessibility", () => {
- it("exposes the checked state to assistive tech", () => {
- expect(renderSwitchRoot({ checked: true })).toContain('aria-checked="true"');
- expect(renderSwitchRoot({ checked: false })).toContain('aria-checked="false"');
+function switchRoot() {
+ const element = container.querySelector<HTMLElement>('[role="switch"]');
+ if (!element) throw new Error("Switch was not rendered");
+ return element;
+}
+
+async function clickSwitch() {
+ await act(async () => switchRoot().click());
+}
+
+async function renderSwitch(initialChecked: boolean, initialMixed = false) {
+ await act(async () => {
+ root.render(<ControlledSwitch {...{ initialChecked, initialMixed }} />);
});
+}
+
+describe("Switch accessibility", () => {
+ it.each([
+ { initialChecked: false, initialMixed: false, before: false, after: true },
+ { initialChecked: true, initialMixed: false, before: true, after: false },
+ { initialChecked: false, initialMixed: true, before: "mixed", after: true },
+ ])("exposes $before before activation and $after after activation", async (state) => {
+ await renderSwitch(state.initialChecked, state.initialMixed);
+ expect(switchRoot().getAttribute("aria-checked")).toBe(String(state.before));
+
+ await clickSwitch();
- it("exposes the mixed state", () => {
- expect(renderSwitchRoot({ checked: false, mixed: true })).toContain('aria-checked="mixed"');
+ expect(switchRoot().getAttribute("aria-checked")).toBe(String(state.after));
+ expect(container.querySelector<HTMLInputElement>('input[type="checkbox"]')?.checked).toBe(
+ state.after,
+ );
});
});