Skip to content

Early previewhamur is not on npm yet. The components are being built in the open, follow along on GitHub.

UIComponentsReact

Tree

A hierarchy of rows that open and close, with a chevron per parent, one or many selected items, and checkboxes that cascade.

Built on the headless Tree.See its API in Docs

Rendered by React 19.3.1

tree.tsx

Installation

npx shadcn@4.23.0 add https://hamur.dev/r/react/tree.json

It also adds utils. The app needs its setup first: Installation.

Usage

Put one TreeItem per node inside Tree: its row is a TreeItemContent with a TreeItemToggle (a chevron that turns down while the item is open), an optional TreeItemIndicator and a TreeItemText, and a parent holds its children in a TreeGroup after the row. Each level indents its row by one step, read from the row's --tree-item-level. TreeEmpty shows while the tree has no items. The keys, the selection, the cascade, lazy loading, moving items and the form value come from the headless Tree.

import {
  Tree,
  TreeEmpty,
  TreeGroup,
  TreeItem,
  TreeItemContent,
  TreeItemIndicator,
  TreeItemText,
  TreeItemToggle,
} from '@/components/ui/tree'

Examples

Default

A file explorer: folders that open and close, one selected.

Its preview and code are at the top of the page.

The focused row takes a ring inside its edges and the selected row a tinted ground. In a multiple tree the indicator is a Checkbox's box, checked, empty or showing a dash while only some of a parent's children are checked; pass keepMounted so an unchecked box stays. While an item is dragged over another, a line before or after it, or a ring around it, shows where it will land. This item takes Base UI's component ID as its slug and one name per Base UI part.

API reference

The styled parts pass every prop to the headless part they wrap and add classes. The props, data attributes and keyboard are on Tree's API reference.