Aliases
tree
components / treeview
Single-select hierarchical collection with branch expansion, depth cues, and keyboard traversal.
Playground
Start here. Switch systems, interact with the shipped component, and let the rest of the page answer the why and how after the behavior clicks.
Cobalt
The crisp default DK action system: bright primary, roomy spacing, and a direct editorial rhythm.
Overview
This section explains the intent of the component before the implementation details.
Aliases
tree
Explore the math
Decision guide
Use these notes to decide quickly whether this is the right DK component for the job.
Decision guide
Do
Do not
Usage
Prefer these situations when choosing this component.
Usage
These patterns are better served by a different component or a simpler surface.
Anti-patterns
Migration notes
Anatomy
The anatomy explains which pieces matter to the recipe and accessibility model.
tree row
itemSingle hierarchical row with level, selection, and branch state.
expand/collapse affordance
branchOpens or closes a node with children.
supporting node text
descriptionOptional secondary copy beneath the main label.
API
The docs contract distinguishes props, DOM events, and slots so integration behavior is explicit.
Props
| Name | Type | Default | Description |
|---|---|---|---|
items | Array<{ id: string; label: string; description?: string; disabled?: boolean; children?: TreeViewItem[] }> | — | Tree definitions with nested child arrays. |
value | string | — | Controlled selected node id. |
expandedIds | string[] | — | Controlled expanded branch ids. |
onChange | (detail: { value: string | undefined }) => void | — | Callback fired when the selected node changes. |
onExpandedChange | (detail: { ids: string[] }) => void | — | Callback fired when the expanded branch set changes. |
theme | ThemeContract | — | Overrides the compiled DK theme used to resolve tokens and recipes for this component. |
Events
| Name | Payload | Description |
|---|---|---|
change | { value: string | undefined } | Fires when the component commits a new value. |
expandedchange | { ids: string[] } | Fires when expanded branches change. |
Slots
| Name | Description |
|---|---|
default | TreeView is data-driven in v1 and does not expose node slots. |
Recipes
These notes summarize the intended recipe surface rather than exposing raw implementation detail first.
Variants
Sizes
States
Accessibility
This is the behavior the component promises to assistive tech and keyboard users today.
Semantics
Keyboard
Screen readers
Checklist
Implementation
This section shows the representative compiled slot variables that the runtime consumes for the selected design system.
Implementation notes
Implementation checklist
Examples
Each example is intentionally practical, grouped by starter, common pattern, and edge-case coverage.
Starter
1 example
starter
Starter: nested resource listA readable hierarchical list with one expanded branch.
Copy snippet
<TreeView items={treeItems} expandedIds={['workspace']} value="overview" />Common patterns
1 example
common
Common: ambiguous nodes with descriptionsDescriptions can clarify similarly named nodes without changing the structure.
Copy snippet
<TreeView items={[{ id: 'workspace', label: 'Workspace', children: [{ id: 'activity', label: 'Activity', description: 'Recent events' }] }]} expandedIds={['workspace']} />Edge cases
1 example
edge
Edge: externally controlled branchesControl selection and expanded branches when app state owns the hierarchy.
Copy snippet
<TreeView items={treeItems} value={selectedNode} expandedIds={expanded} onChange={(detail) => selectedNode = detail.value} onExpandedChange={(detail) => expanded = detail.ids} />Verification
Proofs stay visible in the docs so the system shows what it can guarantee, not just what it can render.