Skip to Content
Puzzle
UI ComponentsNavigation

Tree View

Navigate and select items in a keyboard-accessible hierarchy.

Import

import { TreeView, type TreeViewItem } from "@puzzle-ui/ui";

Hierarchy and selection

Each item needs a stable unique ID. Supply textValue for rich labels so typeahead can find them. Every tree requires an accessible name.

390 × 400

Multiple selection and navigation

selectionMode="none" is useful for navigation trees. Link items can report route state with getItemActive. Use multiple selection for independent file-like choices.

390 × 300

API

PropTypeDefaultDescription
itemsTreeViewItem<TData>[]RequiredHierarchical data.
aria-label or aria-labelledbystringRequiredAccessible tree name.
selectionMode"none" | "single" | "multiple""single"Selection behavior.
expandedIds, defaultExpandedIdsstring[][]Controlled/initial expansion.
onExpandedChange(ids: string[]) => void-Expansion changes.
selectedIds, defaultSelectedIdsstring[][]Controlled/initial selection.
onSelectionChange(ids: string[]) => void-Selection changes.
defaultFocusedIdstringSelected or first root itemInitial focus target.
onFocusedChange(id: string) => void-Focus changes.
loadChildren(item) => Promise<TreeViewItem<TData>[]>-Load children of a hasChildren item.
onLoadChildrenError(item, error: unknown) => void-Handle load failures.
onItemActivate(item) => void-Enter activation.
getItemActive(item) => boolean-Current-route predicate.
renderItem, renderIcon, renderLabel(item, state) => ReactNodeBuilt-in rendererNon-interactive custom content.
expandOnItemClickbooleanfalseToggle branches on label click.
size"sm" | "md""md"Density.
indentationstring | numberTheme spacingHierarchy indentation.
typeaheadbooleantrueCharacter-based navigation.
loadingLabel, loadErrorLabelstringBuilt-in messagesLoading/error feedback.
itemClassNamestring-Class on each item.

Items require id and label; optional fields are href, textValue, icon, endAdornment, children, hasChildren, disabled, selectable, and data. Disabled branches can still expand. Rendering state contains expanded, selected, focused, loading, disabled, and hasChildren.

Arrow keys move through the hierarchy; Home/End reach boundaries, Enter activates, and Space selects. Re-collapse and re-expand a failed lazy branch to retry. Keep nested buttons and links out of custom row content.

;