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
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.
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