React fix

Before and after

Broken — before
// Broken React Accordion: invalid string value & dangling aria-controls when closed
import { useState } from "react";

export function FaqAccordion({ question, answer }: { question: string; answer: string }) {
  const [open, setOpen] = useState(false);
  return (
    <div>
      <button
        type="button"
        aria-expanded={open ? ("yes" as unknown as boolean) : ("no" as unknown as boolean)}
        aria-controls="faq-answer"
        onClick={() => setOpen((o) => !o)}
      >
        {question}
      </button>
      {open && <div id="faq-answer">{answer}</div>}
    </div>
  );
}
Fixed — after
// Fixed React Accordion: strict boolean aria-expanded + valid mounted IDREF via useId()
import { useId, useState } from "react";

export function FaqAccordion({ question, answer }: { question: string; answer: string }) {
  const [open, setOpen] = useState(false);
  const panelId = useId();
  return (
    <div>
      <button
        type="button"
        aria-expanded={open}
        aria-controls={panelId}
        onClick={() => setOpen((o) => !o)}
      >
        {question}
      </button>
      <div id={panelId} hidden={!open}>
        {answer}
      </div>
    </div>
  );
}
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("React accordions expose valid aria-expanded and live aria-controls IDs", async ({ page }) => {
  await page.goto("/pricing");
  const results = await new AxeBuilder({ page })
    .withRules(["aria-valid-attr-value"])
    .analyze();
  expect(results.violations).toEqual([]);
});

Template deduplication tip

A single shared <AccordionItem /> or <PopoverTrigger /> referencing an unmounted panel ID triggers aria-valid-attr-value on every FAQ, pricing, and product view. Fixing that one React component clears every page cluster.

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 axe-core flag aria-controls when my React panel is conditionally rendered?
WAI-ARIA requires IDREF attributes like aria-controls, aria-labelledby, and aria-describedby to reference an existing ID in the current document. Either keep the controlled element mounted with hidden={!open} or conditionally pass aria-controls={open ? panelId : undefined}.
What values are valid for aria-current and aria-live in React?
aria-current accepts 'page' | 'step' | 'location' | 'date' | 'time' | true | false; aria-live accepts 'off' | 'polite' | 'assertive'. Never pass custom values like 'active' or 'normal'.
Does passing aria-describedby='' (empty string) fail aria-valid-attr-value?
Yes—an empty or whitespace-only IDREF fails. Pass undefined (not empty string) in JSX so React omits the attribute entirely when no description is active.