Tree View
An expandable tree structure with checkable nodes, custom icons, keyboard navigation, and smooth animations.
Overview
The TreeView component renders a recursive tree structure with expand/collapse animations, optional checkboxes, file/folder icons, and full keyboard navigation. Built on Framer Motion for smooth transitions.
Installation
Install the component via the CLI in one command.
npx @work-rjkashyap/unified-ui add tree-viewpnpm dlx @work-rjkashyap/unified-ui add tree-viewnpx @work-rjkashyap/unified-ui add tree-viewbunx @work-rjkashyap/unified-ui add tree-viewIf you haven't initialized your project yet, run npx @work-rjkashyap/unified-ui init first. See the CLI docs for details.
Or install the full package
Use this approach if you prefer to install the entire design system as a dependency instead of copying individual components.
npm install @work-rjkashyap/unified-uipnpm add @work-rjkashyap/unified-uiyarn add @work-rjkashyap/unified-uibun add @work-rjkashyap/unified-uiAnatomy
import { TreeView } from "@work-rjkashyap/unified-ui";Examples
Basic File Tree
- src
- components
- button.tsx
- input.tsx
- dialog.tsx
- app.tsx
- index.ts
- package.json
- README.md
With Checkboxes
- Permissions
- Read
- Write
- Delete
- Settings
- Profile
- Notifications
Without Icons
- Section A
- Item A.1
- Item A.2
- Section B
Props
| Prop | Type | Default | Description |
|---|---|---|---|
items | TreeNode[] | — | The tree data structure. |
defaultExpanded | string[] | [] | Default expanded node IDs (uncontrolled). |
expanded | string[] | — | Controlled expanded node IDs. |
onExpandedChange | (expanded: string[]) => void | — | Callback when expanded state changes. |
checkable | boolean | false | Enable checkboxes on nodes. |
defaultChecked | string[] | [] | Default checked node IDs (uncontrolled). |
checked | string[] | — | Controlled checked node IDs. |
onCheckedChange | (checked: string[]) => void | — | Callback when checked state changes. |
onNodeSelect | (nodeId: string) => void | — | Callback when a node is clicked. |
selectedId | string | — | Currently selected node ID (visual highlight). |
showLines | boolean | true | Show connector lines for hierarchy. |
showIcons | boolean | true | Show default file/folder icons. |
className | string | — | Additional CSS classes. |
TreeNode
| Property | Type | Description |
|---|---|---|
id | string | Unique identifier. |
label | string | Display label. |
icon | ReactNode | Custom icon (overrides default). |
children | TreeNode[] | Child nodes (makes it a branch/folder). |
disabled | boolean | Whether the node is disabled. |
Accessibility
- Uses
role="tree"on the root androle="treeitem"on each node. aria-expandedon branch nodes.aria-selectedon the active node.- Keyboard: Arrow keys to navigate, Enter/Space to expand/collapse, ArrowRight to expand, ArrowLeft to collapse.
- Respects
prefers-reduced-motion.
Sidebar
A composable, multi-variant application sidebar with collapsible groups, nested menus, icon-only mode, mobile sheet overlay, and keyboard shortcut toggle. Supports default, floating, and inset layouts.
Infinite Scroll
Scroll-triggered infinite loading with Intersection Observer, loading indicator, and end-of-list detection.