Skip to content
Data Display

Tree

A hierarchical tree view for file explorers, nested navigation, and category pickers. Expand/collapse, single selection, icons, and full keyboard support following the ARIA tree pattern. Expanded and selected state can be controlled or uncontrolled.

Click to select and expand; focus the tree and use the arrow keys to navigate.

src
components
button.tsx
tree.tsx
index.ts
README.md

selected: tree

Import

import { Tree } from "@mikenotthepope/substrateui"

Keyboard

/ — move between visible nodes.

— expand a collapsed node, or move to its first child.

— collapse an expanded node, or move to its parent.

Enter / Space — select (and toggle a parent).

Home / End — jump to the first / last visible node.

Accessibility

The tree implements the WAI-ARIA tree pattern: role="tree" with treeitem children carrying aria-expanded, aria-selected, and aria-level. A roving tabindex keeps a single stop in the tab order, and full arrow-key navigation is provided.

API Reference

PropTypeDefaultDescription
dataTreeNode[]Hierarchical nodes: { id, label, icon?, children?, disabled? }.
defaultExpandedIdsstring[][]Ids expanded initially (uncontrolled).
expandedIdsstring[]Controlled set of expanded ids.
onExpandedChange(ids: string[]) => voidCalled when the expanded set changes.
defaultSelectedIdstring | nullnullSelected id initially (uncontrolled).
selectedIdstring | nullControlled selected id.
onSelect(id: string) => voidCalled when the selection changes.