Lesson 29 of 52Accessibility in depth
ARIA Widget Patterns: Tabs, Menus, Comboboxes and Live Regions
Build disclosures, tabs, menu buttons and a combobox in plain JavaScript, wire names and live regions correctly, and avoid the ARIA that breaks pages.
An audit comes back on your design system with forty findings, and thirty of them are WCAG 4.1.2 Name, Role, Value. The tabs announce as a row of plain buttons. The account menu says "button" with no hint it opens anything. The search box suggests results that a screen reader user never hears about. Every one of these components looks fine and works with a mouse, which is why nobody noticed. This lesson is about the contract between your markup and assistive technology: how a name is computed, which roles, states and keys each common widget needs, and when to stop building and use a vetted library.
How a control gets its name
Accessibility basics said every control needs a name. Browsers compute it with a fixed algorithm (the W3C "accname" spec), and the order matters because the first source that produces text wins and the rest are ignored.
aria-labelledby beats everything. It can point at several ids (aria-labelledby="a b") and joins their text, which is how a 'Delete' button can be named 'Delete Invoice 1042'.
A description is separate from the name. aria-describedby points at hint text or an error message, and screen readers read it after the name and role, usually after a short pause: "Email, edit text, invalid entry, Enter an email like name@example.com". Names should be short and stable. Descriptions carry the extra detail.
You do not have to guess what the browser computed. In Chrome DevTools, select an element and open the Accessibility pane next to Styles. It shows the computed role, the name and where the name came from, with the losing sources crossed out. Firefox has the same in its Accessibility Inspector.
What does this print?
<span id="t" hidden>Remove item</span> <button aria-labelledby="t" aria-label="Close" title="Dismiss"> X </button>
One rule from WCAG ties names to what people see: 2.5.3 Label in Name (A). If a control has visible text, its accessible name must contain that text, ideally at the start. A button that shows "Send" but has aria-label="Submit form" breaks voice control: a user says "click Send" and nothing happens, because the software matches against "Submit form".
The pattern catalogue
You do not invent keyboard behaviour or ARIA wiring. The WAI-ARIA Authoring Practices Guide (APG) at w3.org/WAI/ARIA/apg documents each widget pattern: the roles, the states and properties, and every key. Treat it as the specification for your components. It is not a law and screen reader support varies, so test what you build, but when a reviewer asks "why does Home do that?", the APG is the answer.
Accessible React components built tabs with roving tabindex in React. Here you build the patterns in plain DOM, because that shows exactly which attributes change on each key press, and the same code works in any framework.
Disclosure: the pattern you need most
A disclosure is a button that shows and hides a region: FAQ answers, "Show filters", a mobile nav. It is the simplest pattern and the right answer for far more UI than people expect.
Preview
Four details carry the pattern. It is a real button, so Enter and Space work for free. aria-expanded is the single source of truth, and the CSS rotates the icon from that attribute, so the visual and the announced state can never disagree. The button sits inside a heading so screen reader users can find questions by heading navigation. And the panel uses hidden, which removes it from the accessibility tree as well as from view. For static content, <details> and <summary> give you all of this with no script at all.
Tabs, and automatic versus manual activation
Tabs need three roles: tablist on the container, tab on each tab and tabpanel on each panel. The selected tab has aria-selected="true". Each tab points at its panel with aria-controls, and each panel is named by its tab with aria-labelledby. The tablist is a single Tab stop: arrows move between tabs, Home and End jump to the ends.
The APG describes two activation models. With automatic activation, arrowing to a tab shows its panel at once. With manual activation, arrows only move focus, and Enter or Space shows the panel. Automatic is better when panels render instantly. Manual is better when showing a panel is slow, such as a fetch, because otherwise every arrow press on the way to the fourth tab fires a request.
Preview
In manual mode, notice that the roving tabindex stays on the selected tab, not the focused one. If the user arrows to "Usage" without activating it and tabs away, Shift+Tab brings them back to the tab whose panel is showing. The panels have tabindex="0" because these have no focusable content inside; if a panel starts with a link or field, leave the panel out of the tab order.
Menu buttons, and why most menus are not menus
ARIA's menu role means an application menu, like File and Edit in a desktop app. When a screen reader meets role="menu", it switches into a mode where arrow keys go to the widget, and it expects menuitem children, nothing else. Links, headings and paragraphs inside it are not announced normally.
So the account dropdown in your header, which holds "Profile", "Billing" and "Sign out" links, is almost always better as a disclosure that shows a plain list of links. Users can Tab through it and it behaves like the rest of the page. Reach for role="menu" when the items are actions inside an app, such as "Duplicate", "Rename", "Delete" on a file, and you will implement the full keyboard model.
Preview
Press Enter on the button: focus lands on the first item. Up arrow on the button opens at the last item. Escape returns focus to the button, Tab closes the menu and lets focus move on. That is a lot of behaviour for three actions, which is exactly why you should not use the pattern for navigation.
Roving tabindex or aria-activedescendant
A composite widget (tabs, menu, listbox, grid, toolbar) is one Tab stop with arrow keys inside. There are two ways to track the active item:
| Roving tabindex | aria-activedescendant | |
|---|---|---|
| Where DOM focus is | Moves to each item | Stays on the container or input |
| How the item is marked | tabindex="0" on it, -1 on the rest | The container's attribute holds the item's id |
| Scrolling into view | Free, because focus moves | You scroll it yourself |
| Focus styling | :focus-visible works | Style a class or [aria-selected] |
| Best for | Tabs, toolbars, menus, radio-like groups | Comboboxes, where typing must stay in the input |
Roving tabindex is the default choice because real focus is what every screen reader and browser handles most consistently. aria-activedescendant exists for one main reason: in a combobox the user keeps typing while choosing, so focus cannot leave the text field.
Combobox: the hardest common widget
The ARIA 1.2 combobox puts role="combobox" on the input itself. The input has aria-expanded (is the list showing?), aria-controls (the listbox's id), aria-autocomplete="list" and, while an option is highlighted, aria-activedescendant pointing at that option. The popup is a role="listbox" of role="option" items.
The input filters options and sets aria-expanded="true". Focus never leaves the input.
Preview
Type "l", then use the arrows and watch the state line: aria-activedescendant changes while focus stays in the input. Three details are easy to miss. The options call preventDefault() on mousedown, so clicking one does not blur the input first and close the list before the click lands. The code scrolls the active option into view itself, because no real focus move happens. And the result count goes into a status region that exists from page load.
This demo still skips things a production combobox needs: debounced async results with a loading state, a "no results" message, grouping, right-to-left languages, IME composition for Chinese and Japanese input, and testing on VoiceOver for iOS, where aria-activedescendant support has historically been weaker than on desktop. That list is why teams use React Aria, Base UI, Radix or Headless UI for comboboxes, date pickers and nested menus, and build disclosures and tabs themselves.
Live regions
Some changes happen away from focus: "Saved", "3 results", "Upload failed". A live region is an element whose content changes are announced.
aria-live="polite", orrole="status": announced when the screen reader finishes what it is saying. Use it for almost everything.aria-live="assertive", orrole="alert": interrupts. Keep it for errors that need attention now. Overusing it is like shouting every sentence.
The rule that breaks most implementations: the region must already be in the accessibility tree before its content changes. Screen readers watch existing regions for mutations. Inserting a brand new <div role="status">Saved</div> is often not announced, because the region and its text arrive together. Render an empty region at page load and change its text. To repeat an identical message ("Saved" twice), clear it first and set it again after a short delay, or append a changing detail.
Preview
The list here is a simulation built with a MutationObserver, which is roughly how screen readers notice changes. For the real thing, turn on VoiceOver (Cmd+F5) or NVDA and press the buttons. Also avoid wrapping a big, frequently updating area such as a chat log or ticker in aria-live. Announcing every change makes the page unusable; announce a short summary instead.
States and the attributes that hide things
A handful of state attributes do most of the work in real apps:
aria-pressed="true|false"makes a toggle button ("Bold", "Mute"). Do not change the label as well; "Mute, toggle button, pressed" already says it all.aria-current="page"marks the current link in navigation (alsostep,date,location).aria-invalid="true"on a field with an error, plusaria-describedbypointing at the message.aria-busy="true"on a region while it updates, so assistive tech can wait for the final content.aria-hidden="true"removes an element and all its children from the accessibility tree. It does not remove them from the tab order, so a focusable element inside lands the user on something with no name and no role. To hide a whole region from everyone, including keyboard users, use theinertattribute.
Match each piece of markup to the problem it causes.
- accessible name
- The text assistive tech uses to identify a control, computed from aria-labelledby, aria-label, native labels or content, in that order.
- APG
- The WAI-ARIA Authoring Practices Guide: the W3C's reference for roles, states and keys of each widget pattern.
- disclosure
- A button with aria-expanded that shows and hides a related region.
- composite widget
- A widget such as tabs, a menu or a listbox that is one Tab stop with arrow keys inside.
- aria-activedescendant
- An attribute on the focused element pointing at the id of the item that is active, without moving DOM focus.
- live region
- An element whose content changes are announced, set with aria-live, role='status' or role='alert'.
- inert
- An HTML attribute that makes a subtree unfocusable, unclickable and hidden from assistive tech.