Tree
Hierarchical data with expandable nodes, selection and keyboard navigation.
src
components
button.tsx
card.tsx
tree.tsx
hooks
index.ts
package.json
tsconfig.json
Installation
pnpm dlx nachui add treeAnatomy
An item with children is a branch: clicking it toggles expansion. An item without children is a leaf: clicking it selects it and fires
onSelectedChange on the root. Arrow keys walk the visible rows, ArrowRight expands, ArrowLeft collapses or jumps to the parent, Home and End jump to the edges.Composition
Use the following composition to build a
Tree:Variants
Lines
showLines draws a guide line along each level.app
docs
elements
page.tsx
layout.tsx
page.tsx
layout.tsx
globals.css
proxy.ts
Icons
Pass
icon for every node and iconOpen for branches that change while expanded, like folders.packages
ui
tree.tsx
frame.tsx
cli
turbo.json
Plus and minus
toggleIcon="plus-minus" swaps the chevron for plus and minus toggles.content
docs
en
es
README.md
API Reference
Tree
| Prop | Type | Default | Description |
|---|---|---|---|
defaultExpanded | string[] | [] | Branch values expanded on mount |
defaultSelected | string | - | Initially selected leaf |
selected | string | - | Controlled selected leaf |
onSelectedChange | (value: string) => void | - | Callback when a leaf is selected |
indent | number | 16 | Pixels of indentation per level |
toggleIcon | 'chevron' | 'plus-minus' | 'chevron' | Expand and collapse icon style |
showLines | boolean | false | Draw guide lines between levels |
label | string | 'Tree' | Accessible name for the tree |
className | string | - | Additional CSS classes |
Tree.Item
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | - | Unique value, used for expansion and selection |
label | ReactNode | - | Row content |
icon | ReactNode | - | Leading icon |
iconOpen | ReactNode | - | Icon while the branch is expanded |
disabled | boolean | false | Disable the row |
onSelect | () => void | - | Callback when this leaf is selected |
className | string | - | Additional CSS classes |
Found something to improve?
Notice a bug, typo, or missing detail on this page? Help us make the documentation better by opening a GitHub issue.