Tree view

A tree view is a structure that displays data in a hierarchical view. It can be used in a dropdown, drawer, primary-detail, modal, or wizard.

Examples

Single selectable

Multiselectable

A tree view can be setup to allow multiple nodes to be selected. When a tree view is intended to allow multiple selection, the isMultiSelectable property must be passed.

With separate selection and expansion

The hasSelectableNodes modifier will separate the expansion and selection behaviors, allowing a parent node to be selected or deselected without toggling its expansion.

A search input can be used to filter tree view items. It is recommended that a tree view with more than 7 nodes includes a search input.

With checkboxes

With icons

With badges

With custom badges

With action items

Guides

Compact

Compact, no background

With memoization

Turning on memoization with the useMemo property helps prevent unnecessary re-renders for large data sets. With this flag active, activeItems must pass in an array of nodes along the selected item's path to update properly.

Props

TreeView

The main tree view component.
*required
NameTypeDefaultDescription
datarequiredTreeViewDataItem[]Data of the tree view.
activeItemsTreeViewDataItem[]Active items of tree view.
allExpandedbooleanSets the expanded state on all tree nodes, overriding default behavior and current internal state.
aria-labelstringA text string that sets the accessible name of the tree view list. Either this or the aria-labelledby property must be passed in.
aria-labelledbystringA space separated list of element id's that sets the accessible name of the tree view list. Either this or the aria-label property must be passed in.
classNamestringClass to add if not passed a parentItem property.
compareItems(item: TreeViewDataItem, itemToCheck: TreeViewDataItem) => boolean(item, itemToCheck) => item.id === itemToCheck.idComparison function for determining active items.
defaultAllExpandedbooleanfalseSets the default expanded behavior.
expandedIconReact.ReactNodeIcon for all expanded node items.
hasBadgesbooleanfalseFlag indicating if all nodes in the tree view should have badges.
hasCheckboxesbooleanfalseFlag indicating if all nodes in the tree view should have checkboxes.
hasGuidesbooleanfalseFlag indicating if the tree view has guide lines.
hasSelectableNodesbooleanfalseFlag indicating that tree nodes should be independently selectable, even when having children.
iconReact.ReactNodeIcon for all leaf or unexpanded node items.
idstringID of the tree view.
isMultiSelectablebooleanfalseFlag indicating whether multiple nodes can be selected in the tree view. This will also set the aria-multiselectable attribute on the tree view list which is required to be true when multiple selection is intended. Can only be applied to the root tree view list.
isNestedbooleanfalseFlag indicating if the tree view is nested.
onCheck(event: React.ChangeEvent<HTMLInputElement>, item: TreeViewDataItem, parentItem: TreeViewDataItem) => voidCallback for item checkbox selection.
onCollapse(event: React.MouseEvent, item: TreeViewDataItem, parentItem: TreeViewDataItem) => voidCallback for collapsing a node with children.
onExpand(event: React.MouseEvent, item: TreeViewDataItem, parentItem: TreeViewDataItem) => voidCallback for expanding a node with children.
onSelect(event: React.MouseEvent, item: TreeViewDataItem, parentItem: TreeViewDataItem) => voidCallback for item selection.
parentItemTreeViewDataItemInternal. Parent item of a tree view list item.
toolbarReact.ReactNodeToolbar to display above the tree view.
useMemobooleanFlag indicating the tree view should utilize memoization to help render large data sets. Setting this property requires that the activeItems property is passed an array containing every node in the selected item's path.
variant'default' | 'compact' | 'compactNoBackground''default'Variant presentation styles for the tree view.

TreeViewDataItem

Properties that make up a tree view data item. These properties should be passed in as an object to one of the various tree view component properties which accept TreeViewDataItem as a type.
*required
NameTypeDefaultDescription
namerequiredReact.ReactNodeInternal content of a tree view item.
actionReact.ReactNodeAction of a tree view item, which can be either a button or dropdown component.
badgePropsanyAdditional properties of the tree view item badge.
checkPropsTreeViewCheckPropsAdditional properties of the tree view item checkbox.
childrenTreeViewDataItem[]Child nodes of a tree view item.
customBadgeContentReact.ReactNodeOptional prop for a custom badge.
defaultExpandedbooleanFlag indicating if node is expanded by default.
expandedIconReact.ReactNodeExpanded icon of a tree view item.
hasBadgebooleanFlag indicating if a tree view item has a badge.
hasCheckboxbooleanFlag indicating if a tree view item has a checkbox.
iconReact.ReactNodeDefault icon of a tree view item.
idstringID of a tree view item.
titleReact.ReactNodeTitle of a tree view item. Only used in compact presentations.

TreeViewSearch

Renders a search input for the tree view. This sub-component should be passed into the tree view component's toolbar property.
*required
NameTypeDefaultDescription
aria-labelstringAccessible label for the search input.
classNamestringClasses applied to the wrapper for the search input.
idstringId for the search input.
namestringName for the search input.
onSearch(event: React.ChangeEvent<HTMLInputElement>) => voidCallback for search input.

CSS variables

Expand or collapse columnSelectorVariableValue

View source on GitHub