InkUI
Components

TreeView

Hierarchical collapsible tree with keyboard navigation and guide lines.

Navigate hierarchical data with expand/collapse, keyboard focus, and tree guide lines. Ideal for file explorers, dependency trees, and structured data.

Live Preview
TreeView · file explorer
src/
components/
├ Button.tsx
└ Input.tsx
├ index.ts
└ utils.ts
~/my-cli — node v22● running

Installation

npx inkui add tree-view

Usage

import { TreeView } from './components/ui/tree-view';
 
const nodes = [
  {
    id: 'src',
    label: 'src',
    defaultExpanded: true,
    children: [
      { id: 'index', label: 'index.ts' },
      { id: 'utils', label: 'utils.ts' },
    ],
  },
  { id: 'pkg', label: 'package.json' },
];
 
export default function App() {
  return (
    <TreeView
      nodes={nodes}
      onSelect={(node) => console.log(node.id)}
    />
  );
}

Keyboard Shortcuts

KeyAction
/ kPrevious node
/ jNext node
/ l / EnterExpand or select
/ hCollapse
SpaceToggle expand/collapse
gFirst node
GLast node

API Reference

PropTypeDefaultDescription
nodesTreeNode[]Tree data (required)
onSelect(node) => voidCalled on Enter/select
onToggle(node, expanded) => voidCalled on expand/collapse
maxHeightnumberMax visible rows
guidesbooleantrueShow tree guide lines
showIconsbooleantrueShow file/folder icons
leafIconstring'📄'Icon for leaf nodes
branchIconstring'📁'Icon for collapsed branches
branchOpenIconstring'📂'Icon for expanded branches
focusbooleantrueAccept keyboard input
themeInkUIThemedarkThemeColor theme

On this page