Data display
TreeView
Navigate nested settings, categories, or folders using a tree with expandable branches and activatable leaves.
import { TreeView } from '@reactloom/ui';Examples
Account settings tree
- Settings
- Profile
- Notifications
- Billing
Choose a settings page.
import { useState } from 'react';
import { Stack, TreeView, type TreeViewNode } from '@reactloom/ui';
const nodes: TreeViewNode[] = [
{ id: 'settings', label: 'Settings', children: [
{ id: 'profile', label: 'Profile' }, { id: 'notifications', label: 'Notifications' },
] },
{ id: 'billing', label: 'Billing', children: [{ id: 'invoices', label: 'Invoices' }] },
];
export default function Example() {
const [selected, setSelected] = useState<string | null>(null);
return <Stack gap="2">
<TreeView aria-label="Account settings" nodes={nodes} selectedId={selected}
defaultExpandedIds={['settings']} onActivate={(node) => setSelected(node.id)} />
<div role="status">{selected ? `Selected ${selected}` : 'Choose a settings page.'}</div>
</Stack>;
}Controlled handbook outline
- Getting started
- Support
import { useState } from 'react';
import { TreeView } from '@reactloom/ui';
export default function Example() {
const [expanded, setExpanded] = useState<readonly string[]>([]);
return <TreeView aria-label="Handbook outline" expandedIds={expanded} onExpandedChange={setExpanded}
nodes={[
{ id: 'start', label: 'Getting started', children: [{ id: 'access', label: 'Account access' }] },
{ id: 'support', label: 'Support', children: [{ id: 'help', label: 'Contact help desk' }] },
]} />;
}API reference
| Prop | Type | Default |
|---|---|---|
nodesIDs and labels with optional child nodes. | readonly TreeViewNode[] | — |
aria-labelName the hierarchy. | string | — |
expandedIds · defaultExpandedIdsControlled and initial open branches. | readonly string[] | — |
onExpandedChangeReceives the new expansion state. | (ids: string[]) => void | — |
selectedIdExternally selected leaf. | string | null | — |
onActivateRuns when a leaf is activated. | (node: TreeViewNode) => void | — |
The root list accepts className, style, and a ref. Set --pl-tree-indent to change the indentation per level.
Keyboard interaction
| Key | Action |
|---|---|
| Up / Down | Move through visible nodes |
| Left / Right | Collapse, expand, or move to the parent or first child, mirrored in RTL |
| Home / End | Focus the first or last visible node |
| Enter / Space | Toggle a branch or activate a leaf |
| Type letters | Find a visible node by label |
On first tab into the tree, focus starts on the selected leaf if it is visible, or on the first node.
Usage guidelines
Do
- Keep node IDs unique across the hierarchy. Use the selected leaf to reflect the application’s current destination.
Don’t
- Avoid using a tree for a single-level link list.