TreeView
Hierarchical file/folder structure with box-drawing characters and keyboard navigation.
Import
Basic Usage
src
index.ts
components
Button.tsx
Input.tsx
utils
package.json
tsconfig.json
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| data | TreeNode[] | - | Tree data structure to render (required) |
| defaultExpanded | string[] | [] | Node IDs that should be expanded by default |
| expanded | string[] | - | Controlled expanded state |
| onSelect | (node: TreeNode) => void | - | Callback when a node is selected |
| onToggle | (nodeId: string, expanded: boolean) => void | - | Callback when a node is expanded/collapsed |
| className | string | - | Additional CSS class names |
TreeNode
| Prop | Type | Description |
|---|---|---|
| id | string | Unique identifier for the node |
| label | string | Display label for the node |
| children | TreeNode[] | Child nodes (makes this a folder/branch) |
| isFile | boolean | Whether this is a file (leaf node) |
| icon | React.ReactNode | Custom icon to display |
Keyboard Navigation
| Key | Action |
|---|---|
| Arrow Up/Down | Navigate between nodes |
| Arrow Right | Expand folder or move to first child |
| Arrow Left | Collapse folder or move to parent |
| Enter/Space | Select node and toggle expansion |
Variants
File Tree
src
index.ts
components
Button.tsx
Input.tsx
utils
package.json
tsconfig.json
With Selection Callback
Documents
report.pdf
notes.txt
Projects
Downloads
Controlled Expansion
Deep Nesting
Level 1
Level 2
Level 3
Level 4
deeply-nested.txt
sibling.ts