Navigation

Tree.

Folders and nested choices, with calm motion and a clear keyboard path.

LIVE PREVIEWTry it. It works.

Install the source

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/tree.json

Registry setup · Examples · API and behavior · Open the playground

COMPLETE EXAMPLES

Use it in context.

Each example includes its imports, data and state. The preview runs that same source. Include the stylesheet once in your application.

Browse without changing selection

Focus, expansion and selection have separate controlled state.

Loads this example when you need it.

Keyboard

  • Right opens a folder; Left closes it.
  • Arrow keys move focus; Space selects and Enter activates.

States covered

  • Expanded folder
  • Focused node
  • Selected file
  • Disabled node

Install this complete example and its component dependencies.

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/example-basic-tree.json
Complete source
React / TypeScript
/*!
MIT License

Copyright (c) 2026 Jaison

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import {useState} from 'react';
import {Tree,type TreeNode} from '@bld8/ui';
import '@bld8/ui/styles.css';
const nodes:TreeNode[]=[{id:'src',label:'src',children:[{id:'app',label:'app.tsx'},{id:'styles',label:'styles.css'}]},{id:'readme',label:'README.md'},{id:'private',label:'Unavailable example',disabled:true}];
export default function TreeExample(){const [expanded,setExpanded]=useState<string[]>(['src']),[selected,setSelected]=useState<string|null>(null);return <div><Tree label="Example project files" nodes={nodes} expandedIds={expanded} onExpandedChange={setExpanded} selectedId={selected} onSelectedChange={setSelected}/><p>Selected ID: {selected??'none'}</p></div>;}

Quick reference

React / TypeScript
<Tree label="Project files" nodes={nodes}
  expandedIds={expanded} onExpandedChange={setExpanded}
  selectedId={selected} onSelectedChange={setSelected} />

In the workspace or ZIP starter, import components from @bld8/ui and include @bld8/ui/styles.css once. Registry installations use your local bld8/ source path. Wrap overlays in UIProvider.

API & behaviour

Stable unique IDs identify nodes. Arrow keys move focus without changing selection; Home/End and typeahead navigate visible enabled nodes. Right opens a parent or enters its first child; Left closes it or returns to its parent. Space selects and Enter selects/activates. Disabled nodes cannot be selected. Controlled or default selection/expansion is supported. hasChildren with undefined children marks an unloaded folder; onLoadChildren requests its data and the host supplies loadingIds, errors and new nodes. The host owns cancellation, stale-response protection, authorisation and caching. Empty children means a loaded empty folder. FileBrowser demonstrates an abortable service boundary. Shared motion respects live reduced-motion changes.

Tree

Tree public properties
PropTypeDefault
labelRequiredstring—
nodesRequiredreadonly TreeNode[]—
classNamestring | undefined—
defaultExpandedIdsreadonly string[] | undefined[]
defaultSelectedIdstring | null | undefinednull
disabledboolean | undefinedfalse
errorsReadonly<Record<string, string>> | undefined{}
expandedIdsreadonly string[] | undefined—
loadingIdsreadonly string[] | undefined[]
onActivate((node: TreeNode) => void) | undefined

Enter/double-click activation. Folder activation also toggles expansion.

—
onExpandedChange((ids: string[]) => void) | undefined—
onLoadChildren((id: string) => void) | undefined

Host owns requests, cancellation and the updated children/loading/error props.

—
onSelectedChange((id: string) => void) | undefined—
selectedIdstring | null | undefined—

TreeNode

TreeNode public properties
PropTypeDefault
idRequiredstring

Unique across the entire tree; keep stable while items are reordered.

—
labelRequiredstring—
childrenreadonly TreeNode[] | undefined

undefined with hasChildren means children have not been loaded yet.

—
descriptionstring | undefined—
disabledboolean | undefined—
hasChildrenboolean | undefined—
iconLucideIcon | undefined—

Tables come from the public TypeScript declarations. Related types and function parameters are shown alongside their component. A dash means no default is declared at the public function boundary.

Related controls

Notes to self

Test this component with real content, keyboard input and both themes. The example is a starting point; labels, error handling and behaviour still need to fit the application.