Tree view
ProA hierarchy of rows that open and fold, with selection, their own controls and children that load. Not an M3 component (@windmorph/react-pro).
import { TreeView, TreeViewItemContent } from '@windmorph/react-pro';Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.
Props
TreeView 24 props
The top-level nodes.
Renders a row's content; usually a
TreeViewItemContent.The row's text, for typeahead and its screen reader name.
The open rows (controlled).
The rows open at first, when uncontrolled.
How rows are selected.
The selected rows (controlled).
The rows selected at first, when uncontrolled.
Rows that can't be selected or activated, besides each node's
disabled.Replaces the expand icon, which points to the inline end at rest.
The tree's own density.
Shown when there are no rows.
Ref to the outermost element.
The outermost element's id.
Events
Called when rows open or close.
Called when the selection changes.
Called when a row is activated (a press, or Enter).
Fetches a row's children as it opens. The app adds them to
items.
Text
Words it shows or announces. A
LabelsProvidersets them for the whole app.Names a row's expand button at rest.
Names a row's expand button when open.
Shown while a row's children load.
Shown when they couldn't be loaded.
The button that tries again.
Names a row's checkbox.
One of
aria-labeloraria-labelledbyis required.One of
aria-labeloraria-labelledbyis required.
Classes for the outermost element. Wins over the defaults via
cn().Classes for each part.
The
treegridelement.Each row.
A row’s content.
A row’s expand button.
A row’s chevron.
A row’s checkbox.
What leads a row.
A row’s text.
The title.
A row’s second line.
What trails a row.
The row shown while children load.
The row shown when children fail to load.
Inline styles for the outermost element.
TreeViewItemContent 5 props
The row's title.
Text below the title.
An icon or avatar before the title.
The row's own controls, after the title. Reached with the Right arrow.
Types
TreeViewNode 5 fields
A node of a TreeView.
The node's unique id.
Its children, when they are known.
It has children that aren't loaded yet;
onLoadChildrenfetches them.Turns the row off for selection and activation; it can still be reached.
Makes the row a link.
Spec status
Not part of Material Design 3: a Windmorph Pro component, built on M3's colour roles, type scale, shapes and motion. Its variants and configurations each link to a live example.
Theming & tokens
Set the tokens below on the tree or any ancestor. Style each part with classNames: root, row, content, expandButton, expandIcon, checkbox, leading, text, title, supportingText, trailing, loadingRow, errorRow.
| Variable | Default | Paints |
|---|---|---|
--wm-tree-view-row-min-height | 48px | The least height of a row at density 0; each density step takes 4px off. |
--wm-tree-view-row-shape | var(--md-sys-shape-corner-full) | A row’s corners. |
--wm-tree-view-row-gap | 4px | The space between a row’s parts. |
--wm-tree-view-padding-inline | 8px | The space at the end of a row. |
--wm-tree-view-indent | 24px | How far each level is indented. |
--wm-tree-view-label-color | var(--md-sys-color-on-surface) | A row’s title. |
--wm-tree-view-supporting-color | var(--md-sys-color-on-surface-variant) | A row’s supporting text. |
--wm-tree-view-selected-container-color | var(--md-sys-color-secondary-container) | A selected row’s surface. |
--wm-tree-view-selected-label-color | var(--md-sys-color-on-secondary-container) | A selected row’s title and supporting text. |
--wm-tree-view-disabled-label-color | color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent) | A disabled row’s text. |
--wm-tree-view-icon-color | var(--md-sys-color-on-surface-variant) | The expand icon and a row’s leading icon. |
--wm-tree-view-icon-size | 24px | The expand icon’s size. |
--wm-tree-view-expand-button-size | 48px | The expand button’s touch target, and the space left in a row without one. |
--wm-tree-view-chevron-duration | var(--md-sys-motion-spring-spatial-fast-duration) | How long the expand icon takes to turn. |
--wm-tree-view-chevron-easing | var(--md-sys-motion-spring-spatial-fast-easing) | The easing of the expand icon’s turn. |