Tree
A collapsible hierarchy with a guide line per level — file trees, resource explorers, nested config.
Loading documentation…
Tree renders a hierarchy from data. Indentation is drawn as a guide line
per level rather than as padding, so at depth five you can still see which
branch a row belongs to.
Rows are real buttons inside a tree role, so arrow keys and screen readers
both work without anything extra from you.
children decides what a node is. An array — even an empty one — makes a
branch with a chevron, which is how an empty folder stays a folder. Leave it
undefined for a leaf.
expanded with onExpandedChange hands the open branches to you — the way to
persist them, or to expand a path when a route changes.
openIcon swaps the glyph for an open branch, which is how a closed folder and
an open one end up looking different.
The hierarchy.
Ids of the branches open on first render.
Controlled open branches. Pair it with onExpandedChange.
Fires when a branch opens or closes.
The selected node's id. Selection is always controlled.
Fires with the whole node, not just its id.
The icon for an open branch, when it differs from icon.
Merged into the root.
Stable id, used for expansion, selection and React keys.
The row's text.
The leading glyph.
A right-aligned hint — a count, a status dot, a size.
Nested nodes. An empty array still renders a chevron; undefined makes a
leaf.
Dims the row and ignores interaction.