Plinth

Tree View

File-explorer style tree with expand/collapse and full keyboard navigation.

Install

npx shadcn@latest add https://plinth.dhrumilkherde.com/r/tree-view.json

Usage

import { TreeView, type TreeNode } from "@/components/ui/tree-view";

const files: TreeNode[] = [
  {
    id: "src",
    label: "src",
    icon: <FolderOpen />,
    children: [{ id: "app", label: "app.tsx", icon: <FileText /> }],
  },
];

<TreeView
  data={files}
  defaultExpanded={["src"]}
  onSelect={(id) => openFile(id)}
/>

Props

PropTypeDefault
dataTreeNode[] ({ id, label, icon?, children? })required
defaultExpandedstring[][]
selected / onSelectcontrolled selection

Accessibility

  • Proper tree / treeitem / group roles with aria-expanded and aria-selected.
  • Keyboard: Up/Down move, Right expands, Left collapses or jumps to the parent, Enter/Space selects.

On this page