/
1.1k
Sponsor

Tree

Expandable/collapsible tree view

Terminal

Installation

$ pnpm dlx shadcn@latest add @termcn/ink/tree

Usage

import { Tree } from "@/components/ui/tree";
<Tree
  defaultExpanded={["src"]}
  nodes={[
    {
      key: "src",
      label: "src",
      children: [
        { key: "index", label: "index.ts" },
        { key: "utils", label: "utils.ts" },
      ],
    },
    { key: "pkg", label: "package.json" },
  ]}
/>

API Reference

Tree

PropTypeDefault
nodesTreeNode[]required
onSelect(node: TreeNode) => void-
defaultExpandedstring[][]
expandedIconstring"▼"
collapsedIconstring"▶"
leafIconstring"•"

TreeNode

PropTypeDefault
keystringrequired
labelstringrequired
childrenTreeNode[]-
iconstring-

Notes

Accessibility

termcn exposes the following behavior through Ink's terminal accessibility APIs. This is not a browser ARIA or general WCAG-conformance claim.

  • Keyboard: Arrow keys move the current item or viewport; Home / End move to the boundaries; PageUp / PageDown move by a page; Enter / Space select or expand when supported; Tab / Shift+Tab leave the composite.
  • Focus and composition: Input is active only while the component's focus target is focused, enabled, active, and inside the topmost focus scope.
  • Screen reader: Ink labels and semantic state expose the component without relying on visual styling alone.