Skip to content

Tree view

Pro

A 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

By name or description, across the 29 props below

TreeView 24 props

  • itemstype readonly T[]Required

    The top-level nodes.

  • childrentype (node: T) => ReactNodeRequired

    Renders a row's content; usually a TreeViewItemContent.

  • textValuetype (node: T) => stringRequired

    The row's text, for typeahead and its screen reader name.

  • expandedKeystype Iterable<Key>

    The open rows (controlled).

  • defaultExpandedKeystype Iterable<Key>

    The rows open at first, when uncontrolled.

  • selectionModetype "none" | "single" | "multiple"default "none"

    How rows are selected.

  • selectedKeystype Iterable<Key> | "all"

    The selected rows (controlled).

  • defaultSelectedKeystype Iterable<Key> | "all"

    The rows selected at first, when uncontrolled.

  • disabledKeystype Iterable<Key>

    Rows that can't be selected or activated, besides each node's disabled.

  • expandIcontype ReactNode

    Replaces the expand icon, which points to the inline end at rest.

  • densitytype 0 | -1 | -2 | -3default the theme's

    The tree's own density.

  • emptytype ReactNode

    Shown when there are no rows.

  • reftype Ref<HTMLDivElement>

    Ref to the outermost element.

  • idtype string

    The outermost element's id.

Events

  • onExpandedChangetype ((keys: Set<Key>) => void)

    Called when rows open or close.

  • onSelectionChangetype ((keys: Selection) => void)

    Called when the selection changes.

  • onActiontype ((key: Key) => void)

    Called when a row is activated (a press, or Enter).

  • onLoadChildrentype ((key: Key) => Promise<unknown>)

    Fetches a row's children as it opens. The app adds them to items.

Text

  • labelstype Partial<TreeViewLabels>

    Words it shows or announces. A LabelsProvider sets them for the whole app.

  • aria-labeltype string

    One of aria-label or aria-labelledby is required.

  • aria-labelledbytype string

    One of aria-label or aria-labelledby is required.

TreeViewItemContent 5 props

  • titletype ReactNodeRequired

    The row's title.

  • supportingTexttype ReactNode

    Text below the title.

  • leadingtype ReactNode

    An icon or avatar before the title.

  • trailingtype ReactNode

    The row's own controls, after the title. Reached with the Right arrow.

Types

TreeViewNode 5 fields

A node of a TreeView.

  • idtype KeyRequired

    The node's unique id.

  • childrentype readonly TreeViewNode[]

    Its children, when they are known.

  • hasChildrentype boolean

    It has children that aren't loaded yet; onLoadChildren fetches them.

  • disabledtype boolean

    Turns the row off for selection and activation; it can still be reached.

  • hreftype string

    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.

  • Single and multiple selection (selectionMode)

    Built

    Configuration · Selection

  • Controls in a row (TreeViewItemContent)

    Built

    Configuration · Actions

  • Children that load, with a retry

    Built

    Use case · Loading

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.

TreeView tokens
VariableDefaultPaints
--wm-tree-view-row-min-height48pxThe least height of a row at density 0; each density step takes 4px off.
--wm-tree-view-row-shapevar(--md-sys-shape-corner-full)A row’s corners.
--wm-tree-view-row-gap4pxThe space between a row’s parts.
--wm-tree-view-padding-inline8pxThe space at the end of a row.
--wm-tree-view-indent24pxHow far each level is indented.
--wm-tree-view-label-colorvar(--md-sys-color-on-surface)A row’s title.
--wm-tree-view-supporting-colorvar(--md-sys-color-on-surface-variant)A row’s supporting text.
--wm-tree-view-selected-container-colorvar(--md-sys-color-secondary-container)A selected row’s surface.
--wm-tree-view-selected-label-colorvar(--md-sys-color-on-secondary-container)A selected row’s title and supporting text.
--wm-tree-view-disabled-label-colorcolor-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent)A disabled row’s text.
--wm-tree-view-icon-colorvar(--md-sys-color-on-surface-variant)The expand icon and a row’s leading icon.
--wm-tree-view-icon-size24pxThe expand icon’s size.
--wm-tree-view-expand-button-size48pxThe expand button’s touch target, and the space left in a row without one.
--wm-tree-view-chevron-durationvar(--md-sys-motion-spring-spatial-fast-duration)How long the expand icon takes to turn.
--wm-tree-view-chevron-easingvar(--md-sys-motion-spring-spatial-fast-easing)The easing of the expand icon’s turn.