Settings tabs using WAI-ARIA tablist, tab, and tabpanel roles
An account settings page splits its options into three sections. Sighted users see tabs, but screen reader users currently hear a row of unrelated buttons and a block of text. Build a tabs widget that uses the WAI-ARIA tab roles, states and properties, so assistive technology announces “tab, 1 of 3, selected” and knows which panel each tab controls.
The starter code includes the sections:
const SETTINGS_SECTIONS = [
{ id: 'profile', title: 'Profile', body: 'Your public name and photo appear next to every comment you post.' },
{ id: 'notifications', title: 'Notifications', body: 'Pick which updates reach your inbox and which stay inside the app.' },
{ id: 'privacy', title: 'Privacy', body: 'Decide who can find your profile and see your recent activity.' },
];
title as its text. Use <button type="button"> elements with role="tab".role="tablist" named Account settings (with aria-label, or aria-labelledby pointing at a visible heading). The tablist contains only the tabs, not the panels.role="tabpanel", showing the section’s body.aria-selected="true"; every other tab has aria-selected="false". Profile is selected at first.hidden attribute.id and aria-controls set to its panel’s id.id and aria-labelledby set to its tab’s id.<div role="tablist" aria-label="Account settings">
<button role="tab" id="tab-profile" aria-selected="true" aria-controls="panel-profile">Profile</button>
<button role="tab" id="tab-notifications" aria-selected="false" aria-controls="panel-notifications">Notifications</button>
...
</div>
<div role="tabpanel" id="panel-profile" aria-labelledby="tab-profile">Your public name and photo ...</div>
<div role="tabpanel" id="panel-notifications" aria-labelledby="tab-notifications" hidden>Pick which updates ...</div>
...
After clicking Privacy: Privacy has aria-selected="true", Profile and Notifications have aria-selected="false", and only the Privacy panel is visible.
aria-selected must be the string "false" on unselected tabs, not missing. In React, aria-selected={false} renders "false".aria-controls must point at an element that exists.React.useId(), or the container’s id).The tests click your tabs and inspect the ARIA attributes a screen reader relies on. You don’t need test ids, specific class names, or an exact HTML structure. They check that:
[role="tablist"] is named Account settings and contains three [role="tab"] elements whose text is Profile, Notifications, Privacy, and no [role="tabpanel"].aria-selected is "true" on the selected tab and "false" on the others after every click.aria-controls is the id of a [role="tabpanel"], every panel’s aria-labelledby is the id of the tab that controls it, and no id repeats.hidden or display: none), and it is the selected tab’s panel. The visible text includes the selected section’s body and not the others.Capitalization and extra spacing don’t matter.