Fix select-name in Next.js
Next.js App Router storefronts and SaaS dashboards frequently implement URL-driven sort/filter controls (useSearchParams + router.replace) as bare <select> tags inside a header bar. Pairing each <select> with a <label htmlFor> (or useId()) guarantees screen readers announce the exact filter dimension before and after navigation.
Before and after
// app/components/CatalogSortSelect.tsx (Broken Next.js URL sort dropdown)
"use client";
import { useRouter, useSearchParams } from "next/navigation";
export function CatalogSortSelect() {
const router = useRouter();
const params = useSearchParams();
const current = params.get("sort") ?? "featured";
return (
<select
value={current}
onChange={(e) => router.replace(`?sort=${encodeURIComponent(e.target.value)}`)}
>
<option value="featured">Featured</option>
<option value="newest">Newest</option>
<option value="price-asc">Price: Low to High</option>
</select>
);
}// app/components/CatalogSortSelect.tsx (Fixed Next.js dropdown with useId() label)
"use client";
import { useId } from "react";
import { useRouter, useSearchParams } from "next/navigation";
export function CatalogSortSelect() {
const selectId = useId();
const router = useRouter();
const params = useSearchParams();
const current = params.get("sort") ?? "featured";
return (
<div className="flex items-center gap-2">
<label htmlFor={selectId} className="text-sm font-medium text-slate-900">
Sort catalog
</label>
<select
id={selectId}
name="sort"
value={current}
onChange={(e) => router.replace(`?sort=${encodeURIComponent(e.target.value)}`)}
>
<option value="featured">Featured</option>
<option value="newest">Newest</option>
<option value="price-asc">Price: Low to High</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("Next.js catalog sort dropdown passes axe-core select-name", async ({ page }) => {
await page.goto("/catalog");
await expect(page.getByLabel("Sort catalog")).toBeVisible();
const results = await new AxeBuilder({ page })
.withRules(["select-name"])
.analyze();
expect(results.violations).toEqual([]);
});Template deduplication tip
A shared Next.js <WorkspaceSwitcher /> or <CatalogSortSelect /> mounted inside a layout segment repeats across dozens of routes. Adding one <label htmlFor> clears every route cluster at once.
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
Why wrap components using useSearchParams() in <Suspense> in Next.js App Router?
Can a Next.js Server Component render an accessible <select> inside a <form method='get'>?
<form method='get'> with <label htmlFor='sort'> + <select id='sort' name='sort'> + a Submit button works with zero client JavaScript and passes select-name out of the box.How do I test select-name across dynamic Next.js [category] routes?
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 Next.js weekly? Block new select-name regressions in PRs with our baseline-diff GitHub Action PR gate (≤20 URLs/PR).