Next.js fix

Before and after

Broken — before
// 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>
  );
}
Fixed — after
// 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>
  );
}
Live preview

Fixed vs. broken example

Passes select-name
Accessibility tree: role="combobox", accessible name="Sort products by", value="Featured"

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.

Automated test

Playwright + axe-core check

tests/a11y-select-name.spec.ts
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.

Screen readers

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)

Broken

"combo box, Featured, collapsed" (purpose of selector unknown)


Fixed

"Sort products by, combo box, Featured, collapsed"

VoiceOver (macOS / iOS)

Broken

"Featured, pop-up button"


Fixed

"Sort products by, Featured, pop-up button"

Common questions

Why wrap components using useSearchParams() in <Suspense> in Next.js App Router?
Wrapping client filter dropdowns in <Suspense fallback={<SelectSkeleton />}> prevents the route from opting out of static generation while keeping the rendered <label> + <select> accessible once streamed.
Can a Next.js Server Component render an accessible <select> inside a <form method='get'>?
Yes—native <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?
Include representative dynamic routes in your Playwright test suite or A11yDrift CI PR gate URL list so every template variant is scanned before merge.