Skip to content

Commit 0bb0559

Browse files
committed
fix(a11y): give the remaining flagged elements real roles and keyboard paths
The accessibility rules flagged the same two shapes in the files the earlier a11y commits did not reach. S6848 and S6845: clickable wrappers with no role, no focus stop and no keyboard path. Each becomes a native button, or takes role=presentation when it only forwards a pointer event to its parent. The message bubble becomes role=group with aria-label instead of a tabbable click target, and the terminal view switcher becomes a real tablist. S9379: the raw-DOM autoFocus attributes are replaced by useAutoFocusRef, a stable callback ref that focuses on every attach. autoFocus only fires on a field's first render, so a field swapped in at a later step was never focused. Custom components keep their autoFocus prop, which the rule does not grade. a11y.config.mjs mirrors the jsx-a11y rules SonarCloud maps to, and scan-a11y.mjs runs them. Both report zero findings across the first-party tsx tree.
1 parent a694c69 commit 0bb0559

35 files changed

Lines changed: 240 additions & 84 deletions

‎a11y.config.mjs‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import tseslint from '@typescript-eslint/parser';
2+
import jsxA11y from 'eslint-plugin-jsx-a11y';
3+
4+
// Mirrors the jsx-a11y rules SonarCloud's accessibility findings map to:
5+
// S6848 -> no-static-element-interactions
6+
// S6845 -> no-noninteractive-tabindex
7+
// S6852 -> interactive-supports-focus
8+
// S6853 -> label-has-associated-control
9+
// S6825 -> no-aria-hidden-on-focusable
10+
// S9379 -> no-autofocus
11+
// allowExpressionValues matches Sonar, which resolves a role written as a
12+
// ternary between two literals instead of treating it as unknown.
13+
// ignoreNonDOM matches Sonar too: it only grades real DOM elements, so a
14+
// custom <SearchInput autoFocus> is not a finding there and must not be here.
15+
const config = [
16+
{
17+
files: ['**/*.tsx'],
18+
languageOptions: { parser: tseslint, parserOptions: { ecmaFeatures: { jsx: true }, ecmaVersion: 2022, sourceType: 'module' } },
19+
plugins: { 'jsx-a11y': jsxA11y },
20+
rules: {
21+
'jsx-a11y/no-static-element-interactions': ['error', { allowExpressionValues: true }],
22+
'jsx-a11y/no-noninteractive-tabindex': ['error', { allowExpressionValues: true }],
23+
'jsx-a11y/interactive-supports-focus': ['error', { allowExpressionValues: true }],
24+
'jsx-a11y/label-has-associated-control': 'error',
25+
'jsx-a11y/no-aria-hidden-on-focusable': 'error',
26+
'jsx-a11y/no-autofocus': ['error', { ignoreNonDOM: true }],
27+
},
28+
},
29+
];
30+
31+
export default config;

‎components/ui/button.tsx‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,14 @@ const stateAriaProps = ({
306306
});
307307

308308
/**
309-
* Where an anchor points, and how it stands aside when it cannot act.
309+
* How an anchor stands aside when it cannot act, plus the button role it takes when the
310+
* href is only a placeholder.
310311
*
311-
* An anchor has no `disabled` attribute, so the state travels as the missing href, the
312-
* button role it takes when the href is a placeholder, and a negative tab index.
312+
* An anchor has no `disabled` attribute, so the state travels as the missing href and a
313+
* negative tab index. The `href` itself stays a literal attribute at the call site, because
314+
* the linter reads interactivity from the element's own attributes and a spread hides them.
313315
*/
314316
const anchorTargetProps = (href: string, ariaDisabled: boolean) => ({
315-
href: ariaDisabled ? undefined : href,
316317
role: href === "#" ? ("button" as const) : undefined,
317318
tabIndex: ariaDisabled ? -1 : 0,
318319
});
@@ -525,6 +526,7 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
525526
return (
526527
<a
527528
ref={ref as React.Ref<HTMLAnchorElement>}
529+
href={ariaDisabled ? undefined : href}
528530
{...anchorTargetProps(href, ariaDisabled)}
529531
className={classes}
530532
{...stateAriaProps({ busy, pressed, blocked: ariaDisabled, ariaDisabled })}

‎components/ui/combobox.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export function Combobox({
143143
{headerText ? <DropdownMenuLabel>{headerText}</DropdownMenuLabel> : null}
144144
{searchable ? (
145145
<div
146+
role="presentation"
146147
className="px-1 pb-1"
147148
onPointerDown={(e) => e.stopPropagation()}
148149
onKeyDown={(e) => e.stopPropagation()}

‎features/agent/chrome.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ const SidebarPeekToggle = ({
199199
onHoverEnd?: () => void;
200200
}) => (
201201
<div
202+
role="presentation"
202203
data-sidebar-peek-toggle=""
203204
className="relative z-10 flex shrink-0 items-center pl-1"
204205
data-no-drag

‎features/agent/layout.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ function SidebarPeek({
7777
return (
7878
<div
7979
ref={attachHost}
80+
role="presentation"
8081
data-sidebar-peek=""
8182
className={cn(
8283
"fixed z-30 flex w-82 flex-col overflow-visible origin-left",

‎features/agent/sidebar/collection-dialog.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
AlertDialogTitle,
4545
} from "@/components/ui/alert-dialog";
4646
import { cn } from "@/lib/utils";
47+
import { useAutoFocusRef } from "@/lib/ui/use-auto-focus-ref";
4748
import {
4849
CHAT_COLORS,
4950
CHAT_COLOR_HEX,
@@ -103,6 +104,8 @@ export function CollectionDialog({
103104
const [icon, setIcon] = useState<CollectionIcon>(existing?.icon ?? "star");
104105
const [color, setColor] = useState<ChatColor>(existing?.color ?? "blue");
105106
const [query, setQuery] = useState("");
107+
const nameRef = useAutoFocusRef<HTMLInputElement>();
108+
const queryRef = useAutoFocusRef<HTMLInputElement>();
106109
const icons = useMemo(() => {
107110
const needle = query.trim().toLowerCase();
108111
return COLLECTION_ICONS.filter((id) => !needle || id.includes(needle));
@@ -129,7 +132,7 @@ export function CollectionDialog({
129132
<AlertDialogBody>
130133
{step === 0 ? (
131134
<input
132-
autoFocus
135+
ref={nameRef}
133136
value={name}
134137
placeholder="Collection name"
135138
onChange={(event) => setName(event.target.value)}
@@ -144,7 +147,7 @@ export function CollectionDialog({
144147
<div className="flex items-center gap-2 rounded-md px-2 ring-1 ring-border">
145148
<Icon icon={Search20Regular} className="icon-sm text-text-muted" />
146149
<input
147-
autoFocus
150+
ref={queryRef}
148151
value={query}
149152
placeholder="Search icons"
150153
onChange={(event) => setQuery(event.target.value)}

‎features/agent/workspace/multi-diff.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ function LazyFileDiff({
137137
<section
138138
ref={hostRef}
139139
id={domId}
140+
role="presentation"
140141
onMouseEnter={() => setHover(true)}
141142
onMouseLeave={() => setHover(false)}
142143
>

‎features/agent/workspace/tabs.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ function SortableWorkspaceTab({
8585
style={style}
8686
{...attributes}
8787
{...listeners}
88+
role="tab"
89+
aria-selected={isActive}
90+
tabIndex={0}
8891
onClick={() => onSelect(tab.id)}
8992
className={cn(workbenchTabItemClass(isActive, isDragging), "max-w-44")}
9093
>

‎features/chat/ui/blocks/gallery.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,12 @@ export function DesignPreviewGallery({
327327
aria-modal="true"
328328
aria-label={item.name || "Component preview"}
329329
>
330-
<div className="absolute inset-0 bg-black/60" onClick={() => setOpen(false)} />
330+
<button
331+
type="button"
332+
aria-label="Close preview"
333+
className="absolute inset-0 bg-black/60"
334+
onClick={() => setOpen(false)}
335+
/>
331336
<div className="relative flex max-h-full w-full max-w-[920px] flex-col overflow-hidden rounded-2xl bg-surface-1 p-2 pt-0 shadow-[0_24px_80px_rgba(0,0,0,0.45)]">
332337
<div className="flex h-11 shrink-0 items-center justify-between gap-3 px-1.5">
333338
<span className="truncate text-sm font-semibold text-text-primary">

‎features/chat/ui/blocks/lightbox.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export function MediaLightbox({
8989
onClick={onClose}
9090
>
9191
<div
92+
role="presentation"
9293
className="relative flex max-h-[85vh] max-w-[92vw] flex-col overflow-hidden rounded-xl bg-white shadow-md"
9394
onClick={(e) => e.stopPropagation()}
9495
>
@@ -122,13 +123,13 @@ export function MediaLightbox({
122123
</div>
123124

124125
{design ? (
125-
<p className="max-w-[90vw] truncate text-sm text-white/90" onClick={(e) => e.stopPropagation()}>
126+
<p role="presentation" className="max-w-[90vw] truncate text-sm text-white/90" onClick={(e) => e.stopPropagation()}>
126127
{design.name}
127128
</p>
128129
) : null}
129130

130131
{designs && designs.length > 1 ? (
131-
<div className="flex items-center gap-2.5" onClick={(e) => e.stopPropagation()}>
132+
<div role="presentation" className="flex items-center gap-2.5" onClick={(e) => e.stopPropagation()}>
132133
{designs.map((item, i) => (
133134
<button
134135
key={item.id}

0 commit comments

Comments
 (0)