Unified UI

Tree View

An expandable tree structure with checkable nodes, custom icons, keyboard navigation, and smooth animations.

Overview

The TreeView component renders a recursive tree structure with expand/collapse animations, optional checkboxes, file/folder icons, and full keyboard navigation. Built on Framer Motion for smooth transitions.


Installation

Install the component via the CLI in one command.

npx @work-rjkashyap/unified-ui add tree-view
pnpm dlx @work-rjkashyap/unified-ui add tree-view
npx @work-rjkashyap/unified-ui add tree-view
bunx @work-rjkashyap/unified-ui add tree-view

If you haven't initialized your project yet, run npx @work-rjkashyap/unified-ui init first. See the CLI docs for details.

Or install the full package

Use this approach if you prefer to install the entire design system as a dependency instead of copying individual components.

npm install @work-rjkashyap/unified-ui
pnpm add @work-rjkashyap/unified-ui
yarn add @work-rjkashyap/unified-ui
bun add @work-rjkashyap/unified-ui

Anatomy

import { TreeView } from "@work-rjkashyap/unified-ui";

Examples

Basic File Tree

  • src
    • components
      • button.tsx
      • input.tsx
      • dialog.tsx
    • app.tsx
    • index.ts
  • package.json
  • README.md

With Checkboxes

  • Permissions
    • Read
    • Write
    • Delete
  • Settings
    • Profile
    • Notifications

Without Icons

  • Section A
    • Item A.1
    • Item A.2

Props

PropTypeDefaultDescription
itemsTreeNode[]The tree data structure.
defaultExpandedstring[][]Default expanded node IDs (uncontrolled).
expandedstring[]Controlled expanded node IDs.
onExpandedChange(expanded: string[]) => voidCallback when expanded state changes.
checkablebooleanfalseEnable checkboxes on nodes.
defaultCheckedstring[][]Default checked node IDs (uncontrolled).
checkedstring[]Controlled checked node IDs.
onCheckedChange(checked: string[]) => voidCallback when checked state changes.
onNodeSelect(nodeId: string) => voidCallback when a node is clicked.
selectedIdstringCurrently selected node ID (visual highlight).
showLinesbooleantrueShow connector lines for hierarchy.
showIconsbooleantrueShow default file/folder icons.
classNamestringAdditional CSS classes.

TreeNode

PropertyTypeDescription
idstringUnique identifier.
labelstringDisplay label.
iconReactNodeCustom icon (overrides default).
childrenTreeNode[]Child nodes (makes it a branch/folder).
disabledbooleanWhether the node is disabled.

Accessibility

  • Uses role="tree" on the root and role="treeitem" on each node.
  • aria-expanded on branch nodes.
  • aria-selected on the active node.
  • Keyboard: Arrow keys to navigate, Enter/Space to expand/collapse, ArrowRight to expand, ArrowLeft to collapse.
  • Respects prefers-reduced-motion.

On this page