Data
Tree View
A hierarchical list that can be expanded and collapsed. It ships unstyled on purpose: you decide what a folder and a file look like inside TreeView.Node render.
Want folder and file icons without writing the render function? Use File Tree, a ready-made layer on top of this component.
Import
tsx
import { TreeView, createTreeCollection } from "@indoku/ui"Anatomy
TreeView.Root (collection)├─ TreeView.Label└─ TreeView.Tree └─ TreeView.Node (render) ├─ TreeView.BranchControl folders │ ├─ TreeView.BranchIndicator chevron, rotates when open │ └─ TreeView.BranchText └─ TreeView.Item files └─ TreeView.ItemTextExamples
Without icons
The minimal version: text only. Folders show no indicator at all unless you add one.
Files
src
components
card.tsx
index.ts
public
favicon.svg
package.json
README.md
tsx
With icons
nodeState.expanded tells you whether a folder is open, so you can swap the closed and open folder icons. The chevron goes inside TreeView.BranchIndicator, which rotates it for you.
src
components
card.tsx
index.ts
public
favicon.svg
package.json
README.md
tsx
Controlled
Drive expansion and selection from your own state, for example to add expand-all and collapse-all buttons. tree.getBranchValues() returns every folder id.
src
components
card.tsx
index.ts
public
favicon.svg
package.json
README.md
Selected: none
tsx
Accessibility
- Follows the WAI-ARIA tree view pattern:
role="tree"andtreeitem, witharia-expandedon folders. - Arrow keys move between nodes and expand or collapse folders, Home and End jump to the first and last node, Enter or Space selects.
- Icons are decorative. Keep the text in
BranchTextandItemTextso screen readers can announce each node.
Notes
- Every node needs a unique
id. It is the value used byexpandedValueandselectedValue. - Icons you add are plain children, so they are not part of the theme: size them yourself (the
Iconcomponent or theboxSizeprop on SVGs).
Created by @indokudev