slop audit
Blog post 82 / Accessibility and visual design

Fix aria-required-children errors in axe

Resolve an aria-required-children error by tracing missing child roles, fixing list markup across loading and empty states, and adding a Playwright test.

By Slop Audit · 5 min read

An aria-required-children error means axe found a role whose expected child roles are missing or incorrectly placed. Start at the reported parent. Find its computed role, check what the browser exposes beneath it, and fix the markup in the state that failed. A results grid can look like a list while exposing a list container with no list items.

What aria-required-children checks

Some roles describe structures that depend on other roles. A list needs listitem children. A tablist needs tabs. Assistive technology relies on these relationships to present items as part of a list or tabs as part of the same control. The child role can come from native HTML or an explicit role attribute. WAI-ARIA calls these relationships required owned elements.

Deque documents the axe aria-required-children rule. The reported selector usually points to the container. Start there when searching your component code. If the report instead says aria-required-parent, start from the reported child and check where the component renders it.

Find where the child role went missing

  1. Open the reported route at the failing viewport and reproduce the state. Include the filter, expanded panel, or loading phase if it changes the component.
  2. Inspect the reported element in DevTools. Check the computed role and children the browser exposes in the Chrome DevTools accessibility tree.
  3. Look for a missing item role, a wrapper that changes the accessible hierarchy, or an ancestor that hides the items from assistive technology. A generic DOM wrapper can be flattened in the accessibility tree, so check its computed role before removing it.
  4. If the browser exposes the list but none of its items, inspect what the component rendered there. Compare the first render, populated results, and an empty response. The fix may belong in a conditional branch shared by many routes.

If a portal mounts the children elsewhere, check whether the widget can render them inside its container first. WAI-ARIA defines aria-owns for relationships the DOM cannot express. When you rely on it, confirm the ID references resolve and inspect the resulting accessibility tree.

Repair a list with native HTML

The links here are usable on their own, but the explicit list has no list items. A CSS class that styles a card supplies no item role.

<div id="project-results" role="list">
  <div class="card"><a href="/projects/atlas">Atlas</a></div>
  <div class="card"><a href="/projects/cedar">Cedar</a></div>
</div>

Use a ul with li children. Keep styling on the list and the cards.

<ul id="project-results" class="project-grid">
  <li class="card"><a href="/projects/atlas">Atlas</a></li>
  <li class="card"><a href="/projects/cedar">Cedar</a></li>
</ul>

If you must keep the original div structure, put role="listitem" on each card wrapper and retain the native link inside it. That preserves both the item relationship and the link. For other structures, consult the role definition before moving or relabeling elements. Use the accessible tabs guide if you are repairing a tablist, or check the native table markup examples if a table layout introduced incorrect row or cell roles.

Handle loading and zero results

Put a loading or empty message beside the list area. On an initial load, render the list once its items arrive. When a request returns zero results, replace the list with a clear message such as “No projects match this filter.” A loading placeholder or empty message inside the list exposes the message as a result if it has a list item role.

If an existing widget stays mounted and temporarily loses required children while a script updates it, set aria-busy="true" on a containing element during the update. Reset it when the update finishes, including when it ends in an empty or error state. Keep that attribute tied to the real loading state. See the WAI-ARIA definition of aria-busy.

Add a regression test for the rendered states

Use a seeded route in CI so the results and their order are predictable. In this example, the test app applies its search filter via the q query parameter, and the seeded page displays exactly two projects without a filter. Configure Playwright's baseURL for the test app and install @axe-core/playwright.

import AxeBuilder from "@axe-core/playwright";
import { expect, test } from "@playwright/test";

test("project results expose their list items", async ({ page }) => {
  await page.goto("/projects");
  const container = page.locator("#project-results");
  const list = page.getByRole("list").and(container);

  await expect(list.getByRole("listitem")).toHaveCount(2);
  await expect(list.getByRole("link", { name: "Atlas", exact: true }))
    .toHaveAttribute("href", "/projects/atlas");

  const report = await new AxeBuilder({ page })
    .include("#project-results")
    .withRules(["aria-required-children", "aria-required-parent", "list", "listitem"])
    .analyze();

  expect(report.violations).toEqual([]);
});

test("no matches show an empty state", async ({ page }) => {
  await page.goto("/projects?q=no-match-in-the-fixture");
  await expect(page.getByText("No projects match this filter.", { exact: true }))
    .toBeVisible();
  await expect(page.locator("#project-results")).toHaveCount(0);
});

The role assertion waits for populated results and confirms the items are exposed. The axe scan then checks that state, using the native list rules as well as the ARIA rules. If the broken state needs a click or a breakpoint, reproduce it explicitly in the test. Use the Playwright accessibility testing guide to scope checks and the website regression testing checklist to decide which routes should run them on every PR.

Verify the deployed page

On the deployed route, confirm that a screen reader exposes the list and its items, then Tab through the item links and try the zero-results filter. Include other component states in your accessibility checks before launch.

Run Slop Audit on your deployed public URL to look for axe findings in the rendered page. When the browser check completes and reports the violation, use its rule ID and selector to locate the container, fix the component, then rescan the same URL. Use your local test for states that require a specific interaction or test data.