Components
Tree view
Nested and virtualized tree views with keyboard navigation, checkbox propagation, drag reordering, inline rename, and cached lazy loading.
@composerkit/tree-view ships two tree components:
| Component | Best for | Key features |
|---|---|---|
TreeView / SimpleTreeView | Small-to-medium nested trees | Controlled expansion, single/multi/range selection, checkboxSelection with selectionPropagation, inline label editing, typeahead search, and RTL arrow mirroring. |
TreeViewPro | Large or remote hierarchies | Fixed-height row virtualization (itemHeight, height), drag-and-drop and keyboard (Ctrl/Cmd+Shift+Arrow) reordering (itemsReordering), and lazy dataSource loading with TTL cache (createTreeViewCache). |
Loading the component gallery…
Install
shadcn registry
npx shadcn@latest init --defaults --yesnpx shadcn registry add '@composerkit=https://composerkit.dynd.ai/r/{name}.json'npx shadcn add https://composerkit.dynd.ai/r/tree-view.json --overwrite{+{+ "registries": {+ "@composerkit": "https://composerkit.dynd.ai/r/{name}.json"+ }+}}Import
import { TreeView } from "@/components/tree-view/tree-view";Demo code
"use client";import type { TreeViewItem } from "composerkit/components/tree-view/model";import { SimpleTreeView, TreeItem, TreeView,} from "composerkit/components/tree-view/tree-view";import { useState } from "react";import { AppearanceControl } from "@/components/appearance-control";const ITEMS: TreeViewItem[] = [ { children: [ { id: "button", label: "Button" }, { id: "checkbox", label: "Checkbox" }, { id: "date-picker", label: "Date picker" }, ], id: "inputs", label: "Inputs", }, { children: [ { id: "charts", label: "Charts" }, { id: "data-grid", label: "Data grid" }, { id: "tree-view", label: "Tree view" }, ], id: "data-display", label: "Data display", }, { children: [ { id: "scheduler", label: "Scheduler" }, { disabled: true, id: "archived", label: "Archived calendar" }, ], id: "planning", label: "Planning", },];export const TreeViewGalleryExample = () => { const [expanded, setExpanded] = useState<string[]>([ "inputs", "data-display", ]); const [selected, setSelected] = useState<string[]>(["data-grid"]); return ( <main className="gallery"> <header className="flex flex-wrap items-center justify-between gap-4"> <div> <h1>Tree view</h1> <p className="text-sm text-muted-foreground"> Accessible hierarchical trees with keyboard roving focus, checkbox propagation, inline renaming, and lazy loading. </p> </div> <AppearanceControl id="tree-view-gallery-appearance" /> </header> <section className="grid gap-6 md:grid-cols-2"> <div className="flex flex-col gap-2"> <h2>Controlled tree view</h2> <TreeView checkboxSelection expandedItems={expanded} items={ITEMS} multiSelect onExpandedItemsChange={setExpanded} onSelectedItemsChange={setSelected} selectedItems={selected} /> </div> <div className="flex flex-col gap-2"> <h2>Declarative simple tree</h2> <SimpleTreeView defaultExpandedItems={["workspace"]}> <TreeItem itemId="workspace" label="packages/composerkit"> <TreeItem itemId="src" label="src"> <TreeItem itemId="components" label="components" /> <TreeItem itemId="styles" label="styles" /> </TreeItem> <TreeItem itemId="design" label="DESIGN.md" /> </TreeItem> </SimpleTreeView> </div> </section> </main> );};Props
TreeItemContentProps
Prop
Type
TreeViewProProps
Prop
Type
SimpleTreeViewProps
Prop
Type
TreeItemProps
Prop
Type
TreeViewProps
Prop
Type