TreeView

Hierarchical, expandable tree of nodes with keyboard navigation and selection

Category: display · WCAG 2.2-AA · display, tree, hierarchy, navigation, files

Variants

States

Props

PropTypeDefaultDescription
labelstringAlias of `ariaLabel` — the same invisible accessible name under the other spelling. Neither is deprecated.
ariaLabelstringInvisible accessible name. The catalog convention; `aria-label` is accepted as an alias for the DOM spelling.
aria-labelstringAccessible label for the tree.
items{ id: string; label: ReactNode; icon?: ReactNode; children?: TreeNode[] }[]The items to render.
selectionMode'single' | 'multi'singleWhether one or multiple nodes can be selected ('single' | 'multi').
selectedstring | string[]The controlled selected node id(s).
defaultSelectedstring | string[]The initially selected node id(s) when uncontrolled.
onSelectChange(selected: string | string[]) => voidCalled with the new selection when it changes.
onValueChange(selected: string | string[]) => voidCalled with the new selection. Preferred over `onSelectChange`, which is the catalog’s only value-carrying handler not named onValueChange and is deprecated.
expandedstring[]The controlled set of expanded node ids.
defaultExpandedstring[]The initially expanded node ids when uncontrolled.
onExpandedChange(expanded: string[]) => voidCalled with the new expanded set when it changes.

Design tokens

When to use

When not to use

How to build an accessible TreeView in React →

Examples

Single select

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

Multi select

<TreeView selectionMode="multi" items={nodes} onSelectChange={(ids) => set(ids)} />

Related components

← Back to docs