structyl

Tree

stable

A hierarchical list, like a file explorer.

Basic usage

  • src
    • index.ts
    • app.tsx

Examples

Multi-level file tree

Deeply nested tree mimicking a project directory structure.

  • src
    • components
      • Button.tsx
      • Dialog.tsx
    • index.ts

Large file tree

Tree handles nested groups, expanded state and keyboard navigation.

  • src
    • app.tsx
    • index.ts
    • theme.ts
  • docs
    • components.mdx
    • migration.mdx

Features

  • Expand / collapse.
  • Keyboard navigation.

Installation

bash
pnpm dlx structyl add tree

API Reference

Tree.Root

A file-explorer-style tree.

PropTypeDefault
expandedstring[]

Controlled expanded item ids.

onExpandedChange(expanded: string[]) => void

Called when expansion changes.

selectedstring

Controlled selected id.

onSelectedChange(id?: string) => void

Called when selection changes.

Tree.Item

A tree node.

PropTypeDefault
idstring

Unique node id.

hasChildrenboolean

Whether the node is expandable.

Tree.Trigger

The clickable node label.

PropTypeDefault

Tree.Group

The children of an expandable node.

PropTypeDefault
Tree | structyl