Fix aria-valid-attr-value in React
React apps frequently trigger critical aria-valid-attr-value violations when a trigger renders aria-controls='panel-1' while the panel is conditionally unmounted ({isOpen && <div id='panel-1'>}), or when TypeScript types aren't checked on aria-expanded / aria-live strings. Only attach IDREF attributes when the target node exists in the DOM—or keep the panel mounted with hidden={!isOpen}.
Before and after
// 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 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>
);
}Fixed vs. broken example
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.
Playwright + axe-core check
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.
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)
"Shipping & Returns FAQ, button" (collapsed/expanded state omitted due to invalid token)
"Shipping & Returns FAQ, button, expanded"
VoiceOver (macOS / iOS)
"Shipping & Returns FAQ, button" (state not exposed)
"Shipping & Returns FAQ, expanded, button"
Common questions
Why does axe-core flag aria-controls when my React panel is conditionally rendered?
What values are valid for aria-current and aria-live in React?
Does passing aria-describedby='' (empty string) fail aria-valid-attr-value?
Test a URL for aria-valid-attr-value
Enter any public URL for a free WCAG 2.2 AA check—no account or credit card required.
Shipping React weekly? Block new aria-valid-attr-value regressions in PRs with our baseline-diff GitHub Action PR gate (≤20 URLs/PR).