Course contentsShow
← React
Lesson 1104 of 2,39628. Composition: Compound ComponentsFree lesson

Accessibility Built Into Compound Components

Learn how both libraries handle ARIA attributes, focus management, and keyboard navigation automatically.

Accessibility Built Into Compound Components

What you'll learn: How libraries like Radix UI and Headless UI automatically handle ARIA attributes, focus management, and keyboard navigation in their compound components.

The Invisible Accessibility Layer

When you build your own tabs or menu components, you'd typically need to manually add role="tab", aria-selected, aria-controls, keyboard handlers for arrow keys, and focus management logic. That's dozens of lines of finicky code you need to get exactly right.

Radix UI and Headless UI ship all of that built-in to their compound components. When you use <Tabs.Root>, <Tabs.List>, <Tabs.Trigger>, and <Tabs.Content>, the library automatically:

  • Applies correct ARIA attributes: Each trigger gets role="tab", aria-selected, and aria-controls pointing to its matching content panel.
  • Manages focus programmatically: When you press arrow keys, focus moves between tab triggers automatically. When you press Tab, it moves focus out of the component properly.
  • Handles keyboard navigation: Left/Right arrows navigate tabs, Home/End jump to first/last, Enter/Space activate a tab.

How It Works

The shared context in compound components isn't just for state—it's also how these libraries wire up accessibility relationships. When <Tabs.Trigger> renders, it reads from context to know its index, whether it's selected, and which content panel ID to reference. The library generates stable IDs and manages focus imperatively under the hood.

The Developer Experience Win

You get WAI-ARIA compliant components by simply assembling the compound parts correctly. No need to study the ARIA Authoring Practices Guide or worry if you forgot aria-labelledby. The library enforces correct patterns through its API design.

Key Takeaway: Radix UI and Headless UI bake accessibility directly into their compound component architecture—ARIA roles, focus management, and keyboard navigation work automatically when you compose their parts together, giving you production-grade accessible components with minimal effort.