Tree View
NewGeneric tree with tri-state checkboxes that cascade, or single selection, and full keyboard support.
3 permissions granted
Installation
$ pnpm dlx shadcn@latest add @synccn/tree-viewFirst time in this project? Connect synccn with one command.
Usage
import { TreeView } from "@/components/ui/tree-view";<TreeView data={nodes} value={checked} onValueChange={setChecked} />API reference
Generated from the component's TypeScript types, so it always matches the code.
TreeView
Generic tree with expand and collapse, tri-state checkboxes that cascade to children, or single selection, plus full keyboard support. Use it for permissions, categories, folders.
- datarequired
TreeNode[]—
- selectionMode
"checkbox" | "single"Default
"checkbox""checkbox" checks leaves and shows parents as checked or partly checked; "single" selects one node.
- value
string[]Controlled checked leaf ids (checkbox) or the selected id in a one-item array (single).
- defaultValue
string[]Default
[]Selection at first, when uncontrolled.
- onValueChange
(value: string[]) => voidCalled with the new selection.
- defaultExpanded
string[]Default
[]Ids of nodes open at first.
- aria-label
stringAccessible name for the tree.
- className
stringExtra classes for the root element.
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
npm packages
- clsx for cn()
- tailwind-merge for cn()
- lucide-react for Check, ChevronRight, Minus
Keyboard
- ↓or↑Move between nodes
- →Open, or move to the first child
- ←Close, or move to the parent
- SpaceCheck or select
- EnterOpen a branch, or select
- HomeorEndFirst or last node
Accessibility
- Uses tree and treeitem roles; checkboxes report aria-checked including "mixed" for partly checked branches.
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA roles: tree, treeitem
- ARIA attributes: aria-checked, aria-disabled, aria-expanded, aria-label, aria-level, aria-multiselectable, aria-posinset, aria-selected, aria-setsize
- Keys handled: ArrowUp, ArrowDown, ArrowLeft, ArrowRight, Home, End, Enter, Space
- Shows a visible focus ring for keyboard users