How to build an accessible TreeView in React

Implements the WAI-ARIA TreeView pattern: role=tree on the root, role=treeitem with aria-level/posinset/setsize and aria-expanded on each node, a single roving tabindex, and full APG keyboard support (arrows expand/collapse and move, Home/End, Enter/Space select, printable-character typeahead)

When to use a TreeView

When not to use it

Keyboard interactions

Role tree, verified at WCAG 2.2-AA.

Common mistakes

Avoid: A single-level TreeView with no children on any node

Prefer: A List or StructuredList

A tree with no hierarchy adds twisties and ARIA tree semantics for content that is flat

Example

<TreeView defaultExpanded={["src"]} items={[{ id: "src", label: "src", children: [{ id: "index", label: "index.ts" }] }]} />

See the full TreeView reference →