Next.js fix

Before and after

Broken — before
// app/components/HeaderLink.tsx (Broken: "active" is not a valid aria-current token)
"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";

export function HeaderLink({ href, children }: { href: string; children: React.ReactNode }) {
  const pathname = usePathname();
  const isActive = pathname === href;
  return (
    <Link href={href} aria-current={isActive ? ("active" as never) : undefined}>
      {children}
    </Link>
  );
}
Fixed — after
// app/components/HeaderLink.tsx (Fixed: valid WAI-ARIA token aria-current="page")
"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";

export function HeaderLink({ href, children }: { href: string; children: React.ReactNode }) {
  const pathname = usePathname();
  const isActive = pathname === href;
  return (
    <Link href={href} aria-current={isActive ? "page" : undefined}>
      {children}
    </Link>
  );
}
Live preview

Fixed vs. broken example

Passes aria-valid-attr-value
Accessibility tree: role="button", expanded=true, controls=#demo-shipping-panel (valid WAI-ARIA 1.2 state & live DOM IDREF)

Never interpolate unvalidated booleans, undefined IDs, or custom strings like 'open'/'closed' into ARIA attributes; only render aria-controls when the controlled ID exists in the DOM.

Automated test

Playwright + axe-core check

tests/a11y-aria-valid-attr-value.spec.ts
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";

test("Next.js header links and mobile drawers pass aria-valid-attr-value", async ({ page }) => {
  await page.goto("/pricing");
  await expect(page.locator('a[aria-current="page"]')).toHaveCount(1);
  const results = await new AxeBuilder({ page })
    .withRules(["aria-valid-attr-value"])
    .analyze();
  expect(results.violations).toEqual([]);
});

Template deduplication tip

An invalid aria-current='active' or broken aria-controls inside app/layout.tsx fires across every page of your Next.js app. A11yDrift collapses the entire site to one header cluster so one prop fix resolves all routes.

Screen readers

What NVDA and VoiceOver announce

Invalid ARIA tokens (like aria-expanded='open'), broken IDREFs (aria-controls pointing to a nonexistent or unmounted ID), or mistyped booleans cause browsers and screen readers to silently drop interactive state announcements.

NVDA (Windows)

Broken

"Shipping & Returns FAQ, button" (collapsed/expanded state omitted due to invalid token)


Fixed

"Shipping & Returns FAQ, button, expanded"

VoiceOver (macOS / iOS)

Broken

"Shipping & Returns FAQ, button" (state not exposed)


Fixed

"Shipping & Returns FAQ, expanded, button"

Common questions

Why does next/dynamic lazy loading cause aria-controls violations in Next.js?
If a trigger button renders in SSR HTML with aria-controls='search-modal' while the modal is loaded via next/dynamic({ ssr: false }), the target ID does not exist until opened. Only render aria-controls once the modal is mounted.
Can aria-labelledby point to multiple space-separated IDs in Next.js?
Yes, aria-labelledby accepts an IDREFS list ('title-id subtitle-id'), but EVERY referenced ID must exist in the rendered DOM or axe-core flags aria-valid-attr-value.
How do I validate ARIA attribute types in Next.js TypeScript projects?
Avoid casting ARIA props with as any or as never—@types/react already enforces exact WAI-ARIA 1.2 union types for aria-current, aria-live, aria-haspopup, and aria-sort.