Skip to content
GitHub (opens in a new tab)

TreeView

Nested hierarchy people open and close level by level to browse, pick, or check items.

stableOrganismcontracts/treeview.json

Preview

TreeView

A nested list people open and close level by level, like teams in an organization, project folders or account hierarchies, to pick or check items.

Master

The advanced tree: selection multiple, icons, guide lines and reorderable. Variants shows the simple one. Click chevrons to open folders; drag the grip or use Alt+arrow keys to move rows.

Organization
Design
Sienna Hewitt
Ammar Foley
Caitlyn King
Projects
Powersurge
Client brief
Brief_v1
Brief_v2

Usage

Use TreeView for data that nests: folders and files, an org chart, parent and child accounts, product categories. Simple is chevrons and guide lines, one row selected. Advanced is selection multiple, kit checkboxes, folder icons, and reorderable with a grip Move menu. Do not use it for a flat list, app navigation, or page sections that open and close.

Do's

  • Teams, folders, or account trees the user walks level by level
  • Browse, pick one, or check several items in a nested data hierarchy
  • Arranging a hierarchy with reorderable and onItemsChange

Don'ts

<TreeView
  label="Workspace"
  selection="multiple"
  showIcons
  showLines
  reorderable
  defaultExpanded={["org","design","projects","powersurge","client-brief"]}
  defaultSelected={["design","sienna","ammar","caitlyn"]}
  items={workspace}
  onItemsChange={setWorkspace}
/>

When to use

  • Teams, folders, or account trees the user walks level by level
  • Browse, pick one, or check several items in a nested data hierarchy
  • Arranging a hierarchy with reorderable and onItemsChange

When not to use

  • Page sections that disclose copy — use Accordion or Collapsible
  • App navigation — use SideNav (product) or DocsNav (docs/catalog)
  • Flat comparable columns — use Table or DataTable
  • A short flat choice list — use Select or RadioGroup

What an agent reads

import { TreeView } from "agentic-ds-kit";
must
  • Tree has an accessible name from label
  • Each node is role=treeitem with aria-level
  • Folders set aria-expanded; collapsed children are hidden from AT
  • Expanded children sit in role=group
  • selection=single uses aria-selected; selection=multiple sets aria-multiselectable and aria-checked (including mixed on branches)
  • Disabled nodes set aria-disabled and are not selectable
  • Keyboard: Up/Down move among visible nodes; Left/Right collapse, expand, or move to parent/child; Home/End; Space/Enter select or toggle
  • reorderable: drag grip to reorder; Alt+Up/Down swap siblings; Alt+Right nest into folder above; Alt+Left move out; Shift+F10 or grip opens Move menu
  • Hover: the fill is one decorative layer (aria-hidden) that glides to the row under the pointer or the treeitem with keyboard focus on hover and arrow keys (clip-path only, --motion-expand-*); it lands in place on first show, after the pointer leaves and on resize or scroll, and jumps with no slide under prefers-reduced-motion. Roles, aria-selected, aria-expanded and focus order are unchanged and the focus ring stays on the treeitem. Selected and drop-target rows keep their own fill
defaults
  • size md
  • selection none
  • showLines false
  • showIcons false
  • reorderable false
stops if
  • Do not use Accordion or Collapsible for a data hierarchy
  • Do not use SideNav or DocsNav for a data tree
  • Do not use Table or DataTable for nested browse/pick
  • Do not use Select or RadioGroup for a nested tree
  • Do not invent a local nested list, folder row, tree checkbox, or move handle — compose kit Checkbox and DropdownMenu
  • Do not add Density
  • Do not use Material Symbols or raw hex
  • TreeView has no loading or error prop: while its data loads or fails, render kit Skeleton, LoadError or Empty in its place

From contracts/treeview.json: must is the a11y requirements, defaults the prop defaults, stops if the doNot rules where the agent asks instead of inventing a cousin.

Props

NameTypeRequiredDefaultNotes
itemsarrayYes—A node with children (even []) is a folder. Omit children on a leaf. Optional icon when showIcons. A curated Lucide name (PascalCase or kebab-case) renders instantly; any other Lucide name needs import "agentic-ds-kit/icons-on-demand" once (otherwise it is skipped with a dev warning). Or pass the Lucide component (Plus) or an element.
labelstringYes—Accessible name for role=tree
sizesm | mdNomd—
selectionnone | single | multipleNonone—
expandedstring[]No—controlled folder ids
defaultExpandedstring[]No—uncontrolled initial folder ids
onExpandedChangefunctionNo—(expanded: string[]) => void
selectedstring[]No—controlled node ids. Single keeps 0 or 1 id. Ignored when selection is none.
defaultSelectedstring[]No—uncontrolled initial node ids
onSelectedChangefunctionNo—(selected: string[]) => void
showLinesbooleanNofalse—
showIconsbooleanNofalseFolder, FolderOpen, and File via LucideByName. Not Material Symbols.
reorderablebooleanNofalseGrip handle with drag-and-drop, Move menu, and Alt+Arrow moves among siblings or in/out of folders. Calls onItemsChange.
onItemsChangefunctionNo—(items: TreeViewItem[]) => void when reorderable moves a node
  • Component
    →

    Accordion

    Disclosure list for short related sections: one open at a time, or several with type multiple.

  • Component
    →

    Collapsible

    Single show/hide panel.

  • Component
    →

    SideNav

    Product side nav: brand header, icon items, optional badges, closeable; variant single (one column that closes to an icon rail) or rail-subnav (a fixed icon rail plus a SideNav.SubNav column with the picked parent's rows).

  • Component
    →

    DocsNav

    Docs and catalog sidebar only: title, grouped text-only links, optional decorative icons and muted counts on group and subgroup headers only, an active page pill and optional footer links.