Fix select-name in React
React filter bars and data tables commonly drop <select value={sort} onChange={...}> straight into a flex toolbar without a <label> or aria-label. Building a reusable <SelectField> powered by useId() enforces accessible naming on every dropdown across the app.
Before and after
// Broken React dropdown: bare <select> with no <label> or aria-label
export function SortSelect({ value, onChange }: { value: string; onChange: (v: string) => void }) {
return (
<select value={value} onChange={(e) => onChange(e.target.value)}>
<option value="impact">Sort by impact</option>
<option value="pages">Sort by affected pages</option>
</select>
);
}// Fixed React SelectField: useId() binds <label htmlFor> to <select id>
import { useId } from "react";
interface SelectOption {
value: string;
label: string;
}
interface SelectFieldProps {
label: string;
value: string;
options: readonly SelectOption[];
onChange: (value: string) => void;
}
export function SelectField({ label, value, options, onChange }: SelectFieldProps) {
const selectId = useId();
return (
<div className="select-field">
<label htmlFor={selectId}>{label}</label>
<select id={selectId} value={value} onChange={(e) => onChange(e.target.value)}>
{options.map((opt) => (
<option key={opt.value} value={opt.value}>
{opt.label}
</option>
))}
</select>
</div>
);
}Fixed vs. broken example
Avoid relying on a dummy first <option> like "Sort by..." as the sole label; once a user picks an option, the purpose disappears for everyone.
Playwright + axe-core check
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";
test("React filter and sort <select> controls pass select-name", async ({ page }) => {
await page.goto("/dashboard/clusters");
await expect(page.getByRole("combobox", { name: "Sort clusters by" })).toBeVisible();
const results = await new AxeBuilder({ page })
.withRules(["select-name"])
.analyze();
expect(results.violations).toEqual([]);
});Template deduplication tip
Fixing one shared <SelectField /> or <TablePageSizeSelect /> component resolves select-name clusters across every table, report, and catalog view in your React application.
What NVDA and VoiceOver announce
E-commerce variant pickers (Size, Color), collection sort dropdowns, and country selectors without a programmatic <label> or aria-label announce only the first option ('Featured' or 'Small'), hiding what the dropdown controls.
NVDA (Windows)
"combo box, Featured, collapsed" (purpose of selector unknown)
"Sort products by, combo box, Featured, collapsed"
VoiceOver (macOS / iOS)
"Featured, pop-up button"
"Sort products by, Featured, pop-up button"
Common questions
When is aria-label acceptable instead of a visible <label> on a React <select>?
Why does Playwright query <select> with getByRole('combobox')?
Should a React <select> auto-navigate immediately onChange?
Test a URL for select-name
Enter any public URL for a free WCAG 2.2 AA check—no account or credit card required.
Shipping React weekly? Block new select-name regressions in PRs with our baseline-diff GitHub Action PR gate (≤20 URLs/PR).