Tree
stableA hierarchical list, like a file explorer.
Basic usage
- src
- index.ts
- app.tsx
Examples
Multi-level file tree
Deeply nested tree mimicking a project directory structure.
- src
- components
- Button.tsx
- Dialog.tsx
- index.ts
Large file tree
Tree handles nested groups, expanded state and keyboard navigation.
- src
- app.tsx
- index.ts
- theme.ts
- docs
- components.mdx
- migration.mdx
- tests
Features
- Expand / collapse.
- Keyboard navigation.
Installation
bash
pnpm dlx structyl add treeAPI Reference
Tree.Root
A file-explorer-style tree.
| Prop | Type | Default |
|---|---|---|
| expanded | string[]Controlled expanded item ids. | — |
| onExpandedChange | (expanded: string[]) => voidCalled when expansion changes. | — |
| selected | stringControlled selected id. | — |
| onSelectedChange | (id?: string) => voidCalled when selection changes. | — |
Tree.Item
A tree node.
| Prop | Type | Default |
|---|---|---|
| id | stringUnique node id. | — |
| hasChildren | booleanWhether the node is expandable. | — |
Tree.Trigger
The clickable node label.
| Prop | Type | Default |
|---|
Tree.Group
The children of an expandable node.
| Prop | Type | Default |
|---|