Fix aria-required-children in React
React component trees frequently break aria-required-children when animation wrappers (<motion.div>), Tooltip providers, or styling <div> elements sit between role='tablist' and role='tab' (or role='menu' and role='menuitem'). Flattening wrappers—or marking structural wrappers role='none' and ensuring direct required child roles—restores proper assistive-technology counts and keyboard navigation.
Before and after
// Broken React Tabs: wrapper <div>s and plain <button>s inside role="tablist"
export function ProductTabs({ active, onChange }: { active: string; onChange: (id: string) => void }) {
return (
<div role="tablist" aria-label="Product details">
<div className="tab-wrapper">
<button type="button" onClick={() => onChange("specs")}>Specs</button>
</div>
<div className="tab-wrapper">
<button type="button" onClick={() => onChange("reviews")}>Reviews</button>
</div>
</div>
);
}// Fixed React Tabs: role="tablist" directly owns role="tab" controls + paired tabpanel
interface TabItem {
id: string;
label: string;
content: string;
}
export function ProductTabs({
tabs,
activeId,
onSelect,
}: {
tabs: TabItem[];
activeId: string;
onSelect: (id: string) => void;
}) {
return (
<div>
<div role="tablist" aria-label="Product details">
{tabs.map((tab) => {
const selected = tab.id === activeId;
return (
<button
key={tab.id}
id={`tab-${tab.id}`}
type="button"
role="tab"
aria-selected={selected}
aria-controls={`panel-${tab.id}`}
tabIndex={selected ? 0 : -1}
onClick={() => onSelect(tab.id)}
>
{tab.label}
</button>
);
})}
</div>
{tabs.map((tab) => (
<div
key={tab.id}
id={`panel-${tab.id}`}
role="tabpanel"
aria-labelledby={`tab-${tab.id}`}
hidden={tab.id !== activeId}
>
{tab.content}
</div>
))}
</div>
);
}Fixed vs. broken example
Remove extraneous intermediate wrapper <div>s between a composite ARIA parent and its required children—or set role="none" on purely structural wrappers.
Playwright + axe-core check
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";
test("React Tabs widget exposes valid tablist -> tab ARIA ownership", async ({ page }) => {
await page.goto("/products/pro-plan");
await expect(page.getByRole("tablist", { name: "Product details" })).toBeVisible();
await expect(page.getByRole("tab")).toHaveCount(2);
const results = await new AxeBuilder({ page })
.withRules(["aria-required-children"])
.analyze();
expect(results.violations).toEqual([]);
});Template deduplication tip
A single broken <Tabs> or <DropdownMenu> primitive in src/components/ui/ triggers aria-required-children on every dashboard, settings, and product detail view. A11yDrift clusters every route into one React primitive fix.
What NVDA and VoiceOver announce
When a container declares role='tablist', role='menu', or role='listbox' without directly owning its required child roles (tab, menuitem, option), assistive technologies break arrow-key navigation, item counts ('1 of 3'), and selection state announcements.
NVDA (Windows)
"Product details, tab control" -> "Specs, button" (item count and selected tab semantics lost)
"Product details, tab control, Specs, tab, selected, 1 of 2"
VoiceOver (macOS / iOS)
"Product details, tab group, 0 items" -> "Specs, button"
"Specs, selected, tab, 1 of 2, Product details, tab group"
Common questions
Why does adding a Framer Motion <div> inside role='tablist' break aria-required-children?
What if my React listbox is temporarily empty while loading results?
Should React navigation links use role='menu' and role='menuitem'?
Test a URL for aria-required-children
Enter any public URL for a free WCAG 2.2 AA check—no account or credit card required.
Shipping React weekly? Block new aria-required-children regressions in PRs with our baseline-diff GitHub Action PR gate (≤20 URLs/PR).