GitHub
Core
Glass
Brutal
Humanist

Tree View
Pro

Display nested structures like file systems, categories, or organizational charts with checkboxes and connection lines.

TreeView Playground

TreeView Playground
Preview
Code
Documents
12 items
Work
5 items
Report.pdf
2.3 MB
Presentation.pptx
5.1 MB
Archives
3 items
Q1-Report.pdf
1.2 MB
Q2-Report.pdf
1.4 MB
Resume.docx
156 KB
Cover Letter.docx
89 KB
Notes.txt
4 KB
photo-001.jpg
3.2 MB
photo-002.jpg
2.8 MB
screenshot.png
890 KB
Controls
Checkboxes:
Connection Lines:

Installation

You can add the tree view component to your project manually:

1

Install the following dependencies:

npm install class-variance-authority clsx tailwind-merge @phosphor-icons/react @react-aria/focus @react-aria/interactions @react-aria/utils
2

Copy and paste the following code into your project.

Loading...
3

Update the import paths to match your project setup.

Update the import aliases (e.g. @/components, @/utils) in the copied files to match your project's path configuration.

Basic Usage

Define your hierarchical data and pass it to the TreeView component:

import { TreeView, type TreeNode } from '@versaui/ui/components/TreeView';

const data: TreeNode[] = [
  {
    id: 'documents',
    supportingText: '12 items',
    children: [
      { id: 'report', title: 'Report.pdf', supportingText: '2.3 MB' },
      { id: 'notes', title: 'Notes.txt', supportingText: '4 KB' },
    ]
  },
];

<TreeView data={data} />

Connection Lines

Connection lines help visualize parent-child relationships. They are enabled by default:

// With connection lines (default)
<TreeView data={data} showConnectionLines />

// Without connection lines
<TreeView data={data} showConnectionLines={false} />

Checkboxes

Enable checkboxes for multi-selection. Parent-child check propagation is handled automatically:

<TreeView
  data={data}
  showCheckboxes
  onCheckChange={(ids) => console.log('Checked:', ids)}
/>

Controlled State

For full control over expand, check, and selection states:

const [expandedIds, setExpandedIds] = useState(['documents']);
const [checkedIds, setCheckedIds] = useState([]);
const [selectedIds, setSelectedIds] = useState([]);

<TreeView
  data={data}
  expandedIds={expandedIds}
  checkedIds={checkedIds}
  selectedIds={selectedIds}
  onExpandChange={setExpandedIds}
  onCheckChange={setCheckedIds}
  onSelectionChange={setSelectedIds}
/>

Custom Icons

Provide custom icons via the icon property on each node:

import { FolderIcon, FileTextIcon, ImageIcon } from '@phosphor-icons/react';

const data: TreeNode[] = [
  {
    id: 'assets',
    icon: <FolderIcon size={16} weight="duotone" />,
    children: [
      { id: 'readme', title: 'README.md', icon: <FileTextIcon size={16} /> },
      { id: 'logo', title: 'logo.svg', icon: <ImageIcon size={16} /> },
    ]
  }
];

Disabled Items

Mark specific nodes as disabled to prevent interaction:

const data: TreeNode[] = [
  {
    id: 'downloads',
    disabled: true,
    children: [
      { id: 'file1', title: 'installer.exe' }
    ]
  }
];

Accessibility

  • Keyboard navigation: Use Enter or Space to toggle expand/collapse
  • Each item has role="treeitem", aria-expanded, aria-selected, and aria-disabled
  • Inset focus ring appears when navigating via keyboard
  • Tree structure is announced via role="group" containers

TreeNode Type

interface TreeNode {
  id: string;
  supportingText?: string;
  icon?: React.ReactNode;
  disabled?: boolean;
  children?: TreeNode[];
}

TreeView Props

PropTypeDefaultDescription
dataTreeNode[][]Array of root-level tree nodes.
showConnectionLinesbooleantrueShow lines connecting parent to children.
showCheckboxesbooleantrueShow checkboxes on each node.
selectedIdsstring[][]Controlled selected node IDs.
expandedIdsstring[][]Controlled expanded node IDs.
checkedIdsstring[][]Controlled checked node IDs.
defaultExpandedIdsstring[][]Initial expanded IDs (uncontrolled).
defaultCheckedIdsstring[][]Initial checked IDs (uncontrolled).
onSelectionChange(ids: string[]) => voidCallback when selection changes.
onExpandChange(ids: string[]) => voidCallback when expand state changes.
onCheckChange(ids: string[]) => voidCallback when check state changes.
classNamestring''Additional CSS classes.

On this page