Skip to main content

Design system components

TreeView

Application tree with hierarchical selection, expansion, roving focus, and arrow-key navigation.

Status: beta. Group: navigation. Markdown version: /design-system/components/tree-view.md

When to use

Use TreeView for application hierarchies that users expand, collapse, navigate, and select. Use stable identifiers and concise node labels.

When not to use

  • Do not replace a sitemap or ordinary nested navigation list.
  • Do not nest independently focusable controls inside node labels.
  • Do not use TreeView for a flat set of links or ordinary site navigation.

Look-alikes

The contract names no look-alike with a deciding condition.

Props

TreeView props
PropTypeDefaultDescriptionRequired
nodesTreeViewNode[]noneHierarchical nodes.Yes
aria-labelstringnoneAccessible name for the tree.Yes
selectedIdstring | nullnoneControlled selected node identifier.No
defaultSelectedIdstring | nullnullInitial uncontrolled selected node identifier.No
onSelectedIdChange(id: string) => voidnoneReceives selection changes.No
expandedIdsstring[]noneControlled expanded node identifiers.No
defaultExpandedIdsstring[][]Initial uncontrolled expanded node identifiers.No
onExpandedIdsChange(ids: string[]) => voidnoneReceives expansion changes.No
size"sm" | "md" | "lg"mdDensity scale.No
classNamestringnoneNo description in the contract.No

Variants

  • Available sizes: sm, md, lg (default md).

Invalid combinations

  • MUST NOT: selectedId and defaultSelectedId set together. selectedId makes the component controlled and defaultSelectedId uncontrolled; pass one, not both.
  • MUST NOT: expandedIds and defaultExpandedIds set together. expandedIds makes the component controlled and defaultExpandedIds uncontrolled; pass one, not both.

Keyboard

TreeView keyboard behaviour
KeyBehaviour
ArrowUpMoves focus or the value in that direction. (standard)
ArrowDownMoves focus or the value in that direction. (standard)
ArrowLeftMoves focus or the value in that direction. (standard)
ArrowRightMoves focus or the value in that direction. (standard)
HomeMoves to the first item. (standard)
EndMoves to the last item. (standard)
EnterActivates the focused control. (standard)
SpaceActivates or toggles the focused control. (standard)

Rows marked (standard) name a key the contract lists without a description; the behaviour shown is the usual one for that key.

Rules

Every item under When not to use is a MUST NOT. MUST and SHOULD follow RFC 2119.

TreeView rules
LevelRuleHow it is checked
MUST NOTselectedId and defaultSelectedId set together. selectedId makes the component controlled and defaultSelectedId uncontrolled; pass one, not both.Checked by the MCP tool validate_component_usage.
MUST NOTexpandedIds and defaultExpandedIds set together. expandedIds makes the component controlled and defaultExpandedIds uncontrolled; pass one, not both.Checked by the MCP tool validate_component_usage.
MUSTARIA: Root has role=tree and an accessible name.Not yet verified: no evidence record. WCAG 4.1.2.
MUSTARIA: Nodes expose role=treeitem, aria-level and aria-selected.Not yet verified: no evidence record. WCAG 4.1.2.
MUSTARIA: Branch nodes expose aria-expanded.Not yet verified: no evidence record. WCAG 4.1.2.
MUSTARIA: Only the focused treeitem has tabIndex=0.Not yet verified: no evidence record. WCAG 4.1.2.
MUSTRequired stories produce no axe violations at the configured severity.Automated by npm run test:stories:matrix:ci. WCAG 2.5.8.
MUSTThe accessibility tree (role, name, state) matches the committed snapshot for every required story.Automated by npm run test:stories:matrix:ci. WCAG 1.3.1, 4.1.2.
MUSTThe component remains legible and operable under a real browser forced-colors: active pass.Automated by npm run test:stories:hc.
MUSTEvery documented keyboard interaction works as specified.Not yet verified: no evidence record. WCAG 2.1.1, 2.1.2.
MUSTA human completed an end-to-end accessibility review of this component.Manual review, last on 2026-07-26.
SHOULDGive the tree an accessible label that identifies the hierarchy.Not stated in the contract.
SHOULDUse stable node identifiers across filtering, refreshes, and reordering.Not stated in the contract.
SHOULDKeep labels concise and place secondary status in the description.Not stated in the contract.
SHOULDPreserve expansion state when nearby application content changes.Not stated in the contract.
SHOULD NOTDo not embed buttons, inputs, or menus inside a tree item's label.Not stated in the contract.

Install and import

  • Install: npm install @digitaltableteur/react (version 0.9.1, restricted access on npm).
  • Import: import { TreeView } from "@digitaltableteur/react";
  • Entry point: @digitaltableteur/react/navigation exports it too.
  • Styles: import @digitaltableteur/react/style.css once at the app boundary.