Tree
A hierarchical list of items that expand to reveal their children.
Note: Tree is currently in preview. Its API may change before it becomes stable.
Usage guidelines
- Avoid when items contain controls: A tree item is one focusable element that screen readers read as a whole, so it can’t hold buttons, inputs, or links that keyboard users need to reach. Use Tree Grid for those items instead.
- Avoid trees for site navigation: Prefer links grouped under disclosure buttons, such as Collapsible. The WAI-ARIA Authoring Practices caution against trees for site navigation. If you use one, follow the links example.
- Give the tree an accessible name: Prefer
<Tree.Label>, or provide anaria-labelon<Tree.List>when no visible label is rendered. - Name every control: Give
<Tree.Input>a visible<label>, since a placeholder disappears once the user types. An item is named by itslabel, so pass other visible content, such as a size, toaria-describedby. The expansion trigger and the clear button have English names, such as “Expand Documents” and “Clear filter”: pass your ownaria-labelto translate them, based onstate.expandedfor the trigger. - Support touch screen readers: VoiceOver on iOS and TalkBack users can’t press arrow keys. Render
<Tree.ItemExpansionTrigger>so they can expand items by tapping. It’s the only reliable way in a right-to-left tree, where TalkBack’s Expand and Collapse actions are reversed on the item that has focus. Withmultiple="opt-in", render<Tree.CheckboxItem>so that tapping an item toggles it without clearing the others.
Anatomy
Import the component and assemble its parts:
<Tree.CheckboxItem> and <Tree.LinkItem> replace <Tree.Item> for items that toggle like a checkbox or link to another page. They take the same children, and <Tree.CheckboxItemIndicator> goes inside <Tree.CheckboxItem>.
<Tree.FilterProvider> wraps <Tree.Root> to add filtering, so trees without it don’t bundle the filter. Adding or removing it remounts the tree, so keep it rendered and pass an empty value to turn filtering off.
Item models
To add fields to the standard item, extend Tree.DefaultItem and redeclare children with your own type. Otherwise, nested items only need the standard fields, while callbacks type them as your model.
For any other item model, use Tree.createItems(). Supply setChildren for nested edits and managed reparenting.
The root infers the item type from items. Other parts, such as <Tree.List> and the providers, can’t see it and type items as any. Annotate the parameter of the function you pass them, as (node: Node) does.
Examples
Multiple selection
Set multiple on <Tree.Root> to let users select more than one item. A click or Space adds or removes an item, as does Enter on an item that can’t expand, and the selected items are an array.
Opt-in multiple selection
Use multiple="opt-in" when users opt in to selecting more than one item by holding a modifier key. Without one, a click or moving focus with the keyboard moves the selection to a single item.
- Ctrl or Cmd+click adds or removes an item.
- Shift+click selects a range, as does Shift+Arrow Up or Arrow Down.
- Ctrl+Arrow Up or Arrow Down moves focus without changing the selection, and Ctrl+Space adds or removes the focused item. On macOS, use Option instead of Ctrl.
On touch devices, which have no modifier keys, a tap adds or removes an item, the same as multiple. A <Tree.CheckboxItem> always selects as with multiple.
Checkbox selection
Render <Tree.CheckboxItem> in place of <Tree.Item> to select items like checkboxes, and <Tree.CheckboxItemIndicator> inside it to show the state. Set multiple on <Tree.Root> to allow more than one item to be selected. In single selection, checking an item unchecks the others, so use <Tree.Item> there instead.
Selection propagation
The checkboxSelectionPropagation prop controls how checking an item affects related items, with a <Tree.CheckboxItem> or with actionsRef.setItemSelection(). With descendants, checking a parent selects its whole branch. With parents, checking all of its selectable children selects the parent. Both are enabled by default with multiple selection. Pressing a <Tree.Item> selects or deselects that item only.
Select all
With multiple selection, Ctrl+A or Cmd+A selects every item, including the ones under collapsed parents, and onSelectedItemsChange receives their IDs in tree order. Disabled items keep their state: a selected one stays selected, and the others stay unselected. While the tree is filtered, the shortcut adds the items the filter shows to the selection and keeps the rest of it.
Rendering items
To render the items, pass a function to Tree.List. It’s called with each item in view:
A function can’t be passed from a Server Component, so a tree rendered this way must be in a Client Component. You can also map over the data yourself and render an item part for each item as children, which works in either:
An item part rendered as a child renders nothing while one of its ancestors is collapsed or the filter hides it. When you render the items this way:
- Render every item, in order: Render an item part for each item in
items, collapsed ones included, with its children right after it. Keyboard navigation can’t reach an item that isn’t rendered. - Make the item part the outer element: Only the item part hides, so content around it stays visible. Use its
renderprop to change the element instead. - Render the data you pass to
items: WithdefaultItems, the items thatactionsRefadds aren’t in your data, so they don’t render. Passitemsand update it inonItemsChangeinstead. - Prefer a function for large or animated trees: A function renders only the items in view, and only a function can animate branches with
<Tree.GroupTransition>.
Tree doesn’t virtualize its rows yet. It renders a row for every item whose ancestors are expanded, including rows scrolled out of view, and keyboard navigation can’t move focus to a row that isn’t rendered.
Links
Render <Tree.LinkItem> in place of <Tree.Item> to link an item to another page, and set active on the current page’s item.
Animated expansion
Render <Tree.GroupTransition> after each item to animate expanding and collapsing branches. Use the --tree-group-transition-height CSS variable with the data-starting-style and data-ending-style attributes to animate the group’s height.
Filtering
Wrap <Tree.Root> in <Tree.FilterProvider> and add <Tree.Input> inside the root.
A match keeps its ancestors visible. Use mode to choose how the items that don’t match are shown.
Changes that replace the selection, such as a press, a Shift range, or Ctrl+A, keep the selected items that the filter hides.
Matching items
Items match their label by default and receive a data-filter-match attribute. Screen readers don’t announce it, so describe matches with aria-description, as the demo does.
By default, an item matches when its label contains the query, ignoring case, accents, and punctuation.
Use filter to replace the matching. It receives each item’s label, the trimmed query, and the item, and keeps the item when it returns true.
Tree.useFilter provides the same locale-aware comparisons:
External filtering
To match items on a server, pass the matches to filteredItems. The tree keeps showing their ancestors and applies mode. Every match must also be in the tree’s items.
To render the results yourself, pass filter={null} and give the root the filtered items. Selected items you leave out stay selected when a press toggles another item, and a press that replaces the selection or Ctrl+A drops them.
Status messages
<Tree.Status> politely announces the number of filter matches and of selected items to screen readers.
Keep it mounted and hide it visually, as the demos above do, since screen readers don’t reliably announce a live region that appears with its message.
The messages are in English.
To translate them or write your own, pass the content as children, or a function that receives the latest change and its default message:
Sticky ancestors
To keep the ancestors of the rows at the top visible while scrolling, render copies of them above the list. With a fixed row height, the scroll position tells which row each copy covers, and actionsRef gives that row’s ancestors. Hide the copies from assistive technology, and in onItemHighlighted, scroll a highlighted row out from under them.
Updating items
Use actionsRef.current.applyTransaction() to add, update, move, or remove items without rebuilding items yourself. The operations apply in the order they’re called, as a single change, and each one sees the items as the earlier ones left them.
onItemsChange lists the changes in eventDetails.changes, in the order they applied, so applying them to another copy of the items, such as on a server, gives the same result. With a controlled items, inserted items render only once the parent passes them back, so wait for that before focusing them.
High-frequency updates
Set transactionThrottle to commit the transactions of a short window together.
Keyboard interactions
In every selection mode:
- Arrow Down and Arrow Up move focus to the next and previous rows. Focus stops at the first and last rows.
- Arrow Right expands a collapsed row, and moves focus to the first child of an expanded one.
- Arrow Left collapses an expanded row, and moves focus to the parent of any other row.
- Home and End move focus to the first and last rows.
- Page Up and Page Down move focus by as many rows as fit in the scroll container.
- * expands every sibling of the focused row.
- Typing characters moves focus to the next row whose label starts with them, ignoring case. A space typed during the search is part of it, so “New folder” can match. The search ends after a pause, or when focus leaves the tree. With a
<Tree.Input>, the characters go to the input instead. - Space selects the focused row.
- Enter expands or collapses a row that can expand, and selects any other row. It follows the link of a
<Tree.LinkItem>and selects the row. - Tab moves focus into the tree and out of it. Focus returns to the row that had it last, or else to the first selected row, the row that links to the current page, or the first row.
With multiple, each row toggles on its own:
- Space adds or removes the focused row, as does Enter on a row that can’t expand.
With multiple="opt-in", the selection follows focus:
- Arrow keys, Home, End, Page Up, Page Down and typing move the selection to the row they move focus to. On a disabled row or a
<Tree.CheckboxItem>, the selection stays where it was. - Space makes the focused row the only selected row, as does Enter on a row that can’t expand.
- See Opt-in multiple selection for the keys that move focus without the selection, and that add or remove single rows.
In both multiple modes:
- Shift+Arrow Down or Arrow Up moves focus, and replaces the selection with the rows from the focused row to the one it moves to. Right after a press with Shift or another Shift+arrow key, it grows or shrinks that range instead.
- Shift+Space replaces the selection with the range from the anchor to the
focused row. The anchor is the row that was last pressed without Shift, or the start of
the last range. With
multiple="opt-in", moving the selection with the keyboard moves the anchor too. When there’s no anchor, or it’s under a collapsed parent, the range starts at the first selected row, or at the first row. - Ctrl+Shift+Home or End adds the rows from the focused row to the first or last row to the selection. On macOS, use Cmd instead of Ctrl.
- Ctrl or Cmd+A selects every item, as Select all describes.
Space checks or unchecks a <Tree.CheckboxItem>, as does Enter when it can’t expand. With multiple="opt-in", it behaves as with multiple.
None of these keys expand, collapse, or select a disabled row. It still takes focus unless itemFocusableWhenDisabled is false, ranges and Ctrl+A skip it, and a selected one stays selected. A disabled tree leaves the tab order.
In <Tree.Input>:
- Arrow Down and Arrow Up move focus to the first and last matches. While the tree isn’t filtered, they move it to the row Tab would reach.
- Enter moves focus to the first match.
- Esc clears the query.
In right-to-left layouts, Arrow Right and Arrow Left swap. The tree doesn’t handle Esc on a row, so a popup or dialog around it can close.
API reference
FilterProvider
Enables filtering for the tree it wraps.
Add an Input inside the root to edit the query.
Doesn’t render its own HTML element.
defaultValuestring''
- Name
- Description
The filter query when the tree is initially rendered. To render a controlled query, use the
valueprop instead.- Type
- Default
''
valuestring—
- Name
- Description
The filter query. To render an uncontrolled query, use the
defaultValueprop instead.- Type
onValueChangefunction—
- Name
- Description
Event handler called when the filter query changes.
- Type
filterUnion—
- Name
- Description
Filter function used to match items against the query. Receives each item’s label, the trimmed query, and the item, and keeps the item when it returns
true. By default, items match when their label contains the query, ignoring case, accents, and punctuation. A new function matches every item again, so keep it stable across renders. Passnullwhen rendering filtered items yourself.- Type
filteredItemsany[]—
- Name
- Description
The items matching the query, for filtering done outside the tree, such as on a server. Replaces
filterwhen set, and an empty array matches nothing. Each item must also be in the tree’s items.- Type
localeIntl.LocalesArgument—
- Name
- Description
Locale used when comparing an item against the query. Defaults to the runtime’s default locale.
- Type
modeTree.FilterMode'hide-non-matches'
- Name
- Description
How the tree presents the items that don’t match.
'hide-non-matches': shows only the matches, their ancestors, and their descendants.'collapse-non-matches': shows every item, collapsing the branches without matches.'expand-matches': shows every item, expanding the branches with matches.
The expansion the filter forces doesn’t change
expandedItems.- Type
- Default
'hide-non-matches'
childrenReact.ReactNode—
- Name
- Type
Tree.FilterProvider.PropsHide
Re-Export of FilterProvider props as TreeFilterProviderProps
Tree.FilterProvider.StateHide
Tree.FilterProvider.ChangeEventReasonHide
Tree.FilterProvider.ChangeEventDetailsHide
Root
Groups all parts of the tree. Doesn’t render its own HTML element.
actionsRefReact.RefObject<Tree.Root.Actions<TItem> | null>—
- Name
- Description
A ref to imperative actions on the tree.
- Type
checkboxSelectionPropagationTree.CheckboxSelectionPropagation{ parents: true, descendants: true }
- Description
Controls how checking an item, with its checkbox or with
setItemSelection(), propagates through the hierarchy. Pressing an item without a checkbox, replacing the selection, or selecting a range doesn’t propagate.When
checkboxSelectionPropagation.descendantsis set totrue:- Selecting a parent selects all its descendants automatically.
- Deselecting a parent deselects all its descendants automatically.
When
checkboxSelectionPropagation.parentsis set totrue:- Selecting all descendants of a parent selects the parent automatically.
- Deselecting a descendant of a selected parent deselects the parent automatically.
- Type
- Default
{ parents: true, descendants: true }
defaultExpandedItemsTree.ItemId[][]
- Description
The items that are initially expanded.
To render a controlled component, use the
expandedItemsprop instead.- Type
- Default
[]
defaultItemsTree.Root.Items<TItem>—
- Name
- Description
The item data used for an uncontrolled component on its initial render. Accepts the same data as
items.- Type
defaultSelectedItemsUnion—
- Description
The items that are initially selected. With multiple selection,
nullis the same as[]. Defaults tonullwith single selection and[]with multiple selection.To render a controlled component, use the
selectedItemsprop instead.- Type
disableEmptySelectionbooleanfalse
- Description
Whether the user is prevented from deselecting the last selected item. An empty initial or controlled selection is still allowed.
- Type
- Default
false
expandOnClickbooleanfalse
- Name
- Description
Whether clicking anywhere on an item row toggles expansion. When
false, clicking the row does not toggle expansion; clicking its expansion trigger does.- Type
- Default
false
expandedItemsTree.ItemId[]—
- Name
- Description
The expanded items.
To render an uncontrolled component, use the
defaultExpandedItemsprop instead.- Type
itemFocusableWhenDisabledbooleantrue
- Description
Whether disabled items should be focusable. A disabled tree leaves the tab order whatever this prop is.
- Type
- Default
true
itemsTree.Root.Items<TItem>—
- Name
- Description
The controlled item data. Pass a standard item array, or a collection returned by
createItems()for a custom item model. A model that extends the standard item must redeclarechildrenwith its own type.- Type
multipleboolean | 'opt-in'false
- Name
- Description
Whether multiple items can be selected, and how selecting an item affects the current selection.
false: only one item can be selected.true: each item is toggled independently.'opt-in': selecting an item moves the current selection to it, and users hold a modifier key to select more than one item. It behaves liketrueon touch devices, where there are no modifier keys, and for items with a checkbox.
- Type
- Default
false
onExpandedItemsChangefunction—
- Description
Event handler called when items are expanded or collapsed.
The event
reasonis'list-navigation'for Arrow Right, Arrow Left and*, and'missing'when expanded items are removed by a transaction. Automatic changes cannot be canceled; callingeventDetails.cancel()for'missing'has no effect.- Type
onItemExpansionTogglefunction—
- Description
Event handler called when an item is expanded or collapsed.
- Type
onItemHighlightedfunction—
- Description
Event handler called when an item is highlighted (it receives focus, or one of its controls does) or unhighlighted. Receives the highlighted item’s id, or
undefinedwhen no item is highlighted anymore, such as when focus leaves the tree.The event
reasonis'keyboard'when a key press moved focus,'pointer'when a press did, and'none'otherwise, such as when tabbing into or out of the tree, callingactionsRef.focusItem(), or when focus moves away from a removed item.- Type
onItemSelectionTogglefunction—
- Description
Event handler called when an item is selected or deselected.
- Type
onItemsChangefunction—
- Name
- Description
Event handler called when the items change. Fires when items are added, removed, moved, or updated, so controlled hierarchies can persist every edit.
- Type
onSelectedItemsChangefunction—
- Description
Event handler called when the selected items change.
The event
reasonis'list-navigation'when a key that moves focus, or Ctrl+A, changes the selection,'missing'when selected items are removed by a transaction, and'none'when the tree re-applies checkbox propagation after its items change, such as when a checked folder loads its children. Automatic changes cannot be canceled; callingeventDetails.cancel()for'missing'or'none'has no effect.- Type
selectedItemsUnion—
- Name
- Description
The selected items. With multiple selection,
nullis the same as[].To render an uncontrolled component, use the
defaultSelectedItemsprop instead.- Type
transactionThrottlenumber0
- Description
The minimum time between two commits of
actionsRef.applyTransaction(), in milliseconds. The first transaction after a quiet period commits at once. The ones that follow within the window are applied together, as a single items change, when the window ends. Until then, the actions and the rendered items show the items as the last commit left them. CallactionsRef.flushTransactions()to commit them right away.- Type
- Default
0
disabledbooleanfalse
- Name
- Description
Whether the component should ignore user interaction.
- Type
- Default
false
childrenReact.ReactNode—
- Name
- Description
The children of the component.
- Type
Tree.Root.StateHide
Tree.Root.ActionsHide
Tree.Root.HighlightEventReasonHide
Tree.Root.HighlightEventDetailsHide
Tree.Root.ExpansionChangeEventDetailsHide
Tree.Root.ExpansionChangeEventReasonHide
Tree.Root.ItemExpansionToggleEventDetailsHide
Tree.Root.ItemExpansionToggleValueHide
Tree.Root.ItemsHide
Tree.Root.ItemsChangeEventDetailsHide
Tree.Root.ItemsChangeEventReasonHide
Tree.Root.ItemSelectionToggleEventDetailsHide
Tree.Root.ItemSelectionToggleValueHide
Tree.Root.SelectionChangeEventDetailsHide
Tree.Root.SelectionChangeEventReasonHide
Label
An accessible label that is automatically associated with the tree.
Clicking it focuses the tree.
Renders a <div> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
Tree.Label.StateHide
Input
A search field that filters the tree.
Requires the root to be wrapped in FilterProvider.
Renders an <input> element.
disabledbooleanfalse
- Name
- Description
Whether the component should ignore user interaction.
- Type
- Default
false
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-disabled
Present when the input is disabled.
Attribute | Description | |
|---|---|---|
data-disabled | Present when the input is disabled. | |
Tree.Input.StateHide
Clear
A button that clears the input text.
Requires the root to be wrapped in FilterProvider.
Renders a <button> element when the input has text.
nativeButtonbooleantrue
- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set tofalseif the rendered element is not a button (for example,<div>).- Type
- Default
true
disabledbooleanfalse
- Name
- Description
Whether the component should ignore user interaction.
- Type
- Default
false
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-disabled
Present when the button is disabled.
Attribute | Description | |
|---|---|---|
data-disabled | Present when the button is disabled. | |
Tree.Clear.StateHide
Status
Displays a status message whose content changes are announced politely to screen readers.
By default, announces in English the number of items matching the filter, and the
number of selected items after a press or a key changes a multiple selection.
Screen readers announce the state of the item itself. Pass a function as
children to build the message from change in another language.
This component’s root element must remain mounted in the DOM to announce
changes consistently across screen readers. Avoid hiding or removing the
component itself with display: none, hidden, aria-hidden, or conditional
rendering. Prefer updating or conditionally rendering its children instead.
Renders a <div> element.
children| React.ReactNode
| ((state: Tree.Status.State) => React.ReactNode)—
| ((state: Tree.Status.State) => React.ReactNode)
- Name
- Description
The status content, or a function that receives the state and returns it. Defaults to the English message of the latest change.
- Type
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
Tree.Status.StateHide
Tree.Status.ChangeHide
Tree.Status.FilterChangeHide
Tree.Status.SelectionChangeHide
Empty
Renders its children only when the tree has no visible rows, or when no item
matches the filter.
Announces changes politely to screen readers.
This component’s root element must remain mounted in the DOM to announce
changes consistently across screen readers. Avoid hiding or removing the
component itself with display: none, hidden, aria-hidden, or conditional
rendering. Prefer updating or conditionally rendering its children instead.
Renders a <div> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
Tree.Empty.StateHide
List
A container for the tree items.
Renders a <div> element.
Render a group transition after each item of a function child to animate expand/collapse transitions.
children| React.ReactNode
| ((item: any) => React.ReactNode)—
| ((item: any) => React.ReactNode)
- Name
- Description
The items of the tree. A function renders each of the root’s
itemsin view, and receives an item. Annotate its parameter to type it. Otherwise, render an item part for each of the root’sitemsas children, in order. Each one renders nothing while it’s out of view.- Type
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-disabled
Present when the tree is disabled.
data-empty
Present when the tree has no visible rows, or no item matches the filter.
Attribute | Description | |
|---|---|---|
data-disabled | Present when the tree is disabled. | |
data-empty | Present when the tree has no visible rows, or no item matches the filter. | |
Tree.List.StateHide
Item
An item in a tree, and a row in a tree grid.
Renders a <div> element.
itemId*Tree.ItemId—
- Name
- Description
The id of the item.
- Type
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-selected
Present when the item is selected.
data-highlighted
Present when the item is highlighted: it has focus, or, in a tree grid, one of its controls does.
data-disabled
Present when the item is disabled.
data-collapsed
Present when the item is collapsed.
data-expandable
Present when the item can be expanded.
data-expanded
Present when the item is expanded.
data-filter-match
Present when the item is an exact filter match.
data-item-id
The id of the item.
Attribute | Description | |
|---|---|---|
data-selected | Present when the item is selected. | |
data-highlighted | Present when the item is highlighted: it has focus, or, in a tree grid, one of its controls does. | |
data-disabled | Present when the item is disabled. | |
data-collapsed | Present when the item is collapsed. | |
data-expandable | Present when the item can be expanded. | |
data-expanded | Present when the item is expanded. | |
data-filter-match | Present when the item is an exact filter match. | |
data-item-id | The id of the item. | |
--tree-item-level
The level of the item in the tree hierarchy (1-based, matches aria-level).
CSS Variable | Description | |
|---|---|---|
--tree-item-level | The level of the item in the tree hierarchy (1-based, matches aria-level). | |
Tree.Item.StateHide
CheckboxItem
An item that users check and uncheck like a checkbox.
In a tree grid, render TreeGrid.RowCheckbox in the item instead.
Renders a <div> element.
itemId*Tree.ItemId—
- Name
- Description
The id of the item.
- Type
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-checked
Present when the item is checked.
data-unchecked
Present when the item is not checked and none of its selectable descendants are.
data-highlighted
Present when the item is highlighted: it has focus.
data-disabled
Present when the item is disabled.
data-collapsed
Present when the item is collapsed.
data-expandable
Present when the item can be expanded.
data-expanded
Present when the item is expanded.
data-filter-match
Present when the item is an exact filter match.
data-indeterminate
Present when the item is not checked but some of its selectable descendants are.
data-item-id
The id of the item.
Attribute | Description | |
|---|---|---|
data-checked | Present when the item is checked. | |
data-unchecked | Present when the item is not checked and none of its selectable descendants are. | |
data-highlighted | Present when the item is highlighted: it has focus. | |
data-disabled | Present when the item is disabled. | |
data-collapsed | Present when the item is collapsed. | |
data-expandable | Present when the item can be expanded. | |
data-expanded | Present when the item is expanded. | |
data-filter-match | Present when the item is an exact filter match. | |
data-indeterminate | Present when the item is not checked but some of its selectable descendants are. | |
data-item-id | The id of the item. | |
--tree-item-level
The level of the item in the tree hierarchy (1-based, matches aria-level).
CSS Variable | Description | |
|---|---|---|
--tree-item-level | The level of the item in the tree hierarchy (1-based, matches aria-level). | |
Tree.CheckboxItem.PropsHide
Re-Export of CheckboxItem props as TreeCheckboxItemProps
Tree.CheckboxItem.StateHide
CheckboxItemIndicator
Renders when the checkbox item is checked or mixed.
Renders a <span> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
keepMountedbooleanfalse
- Name
- Description
Whether to keep the element in the DOM when the item is not checked.
- Type
- Default
false
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-checked
Present when the item is checked.
data-unchecked
Present when the item is not checked and none of its selectable descendants are.
data-disabled
Present when the item is disabled.
data-indeterminate
Present when the item is not checked but some of its selectable descendants are.
data-starting-style
Present when the indicator is animating in.
data-ending-style
Present when the indicator is animating out.
Attribute | Description | |
|---|---|---|
data-checked | Present when the item is checked. | |
data-unchecked | Present when the item is not checked and none of its selectable descendants are. | |
data-disabled | Present when the item is disabled. | |
data-indeterminate | Present when the item is not checked but some of its selectable descendants are. | |
data-starting-style | Present when the indicator is animating in. | |
data-ending-style | Present when the indicator is animating out. | |
Tree.CheckboxItemIndicator.PropsHide
Re-Export of CheckboxItemIndicator props as TreeCheckboxItemIndicatorProps
Tree.CheckboxItemIndicator.StateHide
LinkItem
An item that links to another page. Enter and clicks follow the link.
In a tree grid, render TreeGrid.CellLink in the item instead.
Renders an <a> element.
activebooleanfalse
- Name
- Description
Whether the link is the current page. Marks the item with
aria-current="page", and gives it the tree’s tab stop when no item is selected and no other item had focus.- Type
- Default
false
itemId*Tree.ItemId—
- Name
- Description
The id of the item.
- Type
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-selected
Present when the item is selected.
data-highlighted
Present when the item is highlighted: it has focus.
data-disabled
Present when the item is disabled.
data-active
Present when the link is the current page.
data-collapsed
Present when the item is collapsed.
data-expandable
Present when the item can be expanded.
data-expanded
Present when the item is expanded.
data-filter-match
Present when the item is an exact filter match.
data-item-id
The id of the item.
Attribute | Description | |
|---|---|---|
data-selected | Present when the item is selected. | |
data-highlighted | Present when the item is highlighted: it has focus. | |
data-disabled | Present when the item is disabled. | |
data-active | Present when the link is the current page. | |
data-collapsed | Present when the item is collapsed. | |
data-expandable | Present when the item can be expanded. | |
data-expanded | Present when the item is expanded. | |
data-filter-match | Present when the item is an exact filter match. | |
data-item-id | The id of the item. | |
--tree-item-level
The level of the item in the tree hierarchy (1-based, matches aria-level).
CSS Variable | Description | |
|---|---|---|
--tree-item-level | The level of the item in the tree hierarchy (1-based, matches aria-level). | |
Tree.LinkItem.StateHide
ItemIndentGuide
Renders vertical indent guide lines for a tree item, one per ancestor level.
Each line carries data-level and, when its ancestor is a last child, data-last.
Renders a <span> element containing inner <span> elements.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-last
Present when the ancestor at this guide’s depth is the last child of its parent. Use it to truncate the guide line.
data-level
The level of the ancestor this guide line belongs to, from 1 for the root items, like its
aria-level.
Attribute | Description | |
|---|---|---|
data-last | Present when the ancestor at this guide’s depth is the last child of its parent. Use it to truncate the guide line. | |
data-level | The level of the ancestor this guide line belongs to, from | |
--tree-indent-guide-level
The level of the ancestor this guide line belongs to, from 1 for the root items, like its
aria-level. Set on each inner <span> within the indent guide wrapper.
CSS Variable | Description | |
|---|---|---|
--tree-indent-guide-level | The level of the ancestor this guide line belongs to, from | |
Tree.ItemIndentGuide.PropsHide
Re-Export of ItemIndentGuide props as TreeItemIndentGuideProps
Tree.ItemIndentGuide.StateHide
ItemExpansionTrigger
A button that toggles the expansion state of a tree item.
Alt-click (Option-click on macOS) toggles its descendants too.
Renders a <button> element when the item can be expanded.
In a link item, renders a <span> that only handles clicks, since a link
can’t contain a button. Keyboard users expand the item with the arrow keys.
nativeButtonbooleantrue
- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set tofalseif the rendered element is not a button (for example,<div>).- Type
- Default
true
disabledbooleanfalse
- Name
- Description
Whether the component should ignore user interaction. The trigger is also disabled while its item or the tree is disabled.
- Type
- Default
false
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-disabled
Present when the trigger, its item, or the tree is disabled.
data-collapsed
Present when the item is collapsed.
data-expanded
Present when the item is expanded.
Attribute | Description | |
|---|---|---|
data-disabled | Present when the trigger, its item, or the tree is disabled. | |
data-collapsed | Present when the item is collapsed. | |
data-expanded | Present when the item is expanded. | |
Tree.ItemExpansionTrigger.PropsHide
Re-Export of ItemExpansionTrigger props as TreeItemExpansionTriggerProps
Tree.ItemExpansionTrigger.StateHide
ItemGroupIndicator
A visual indicator for expandable tree items.
Renders a <span> element when the item can be expanded.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-collapsed
Present when the item is collapsed.
data-expanded
Present when the item is expanded.
Attribute | Description | |
|---|---|---|
data-collapsed | Present when the item is collapsed. | |
data-expanded | Present when the item is expanded. | |
Tree.ItemGroupIndicator.PropsHide
Re-Export of ItemGroupIndicator props as TreeItemGroupIndicatorProps
Tree.ItemGroupIndicator.StateHide
GroupTransition
A wrapper that animates a group of tree items while it expands or collapses.
Rendering this part next to an item enables transitions for that item’s
children, which render inside it. Renders null while the group is not animating.
Renders a <div> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-collapsing
Present while the group animates its items out, as its parent collapses.
data-expanding
Present while the group animates its items in, as its parent expands.
data-parent-id
The id of the item whose children the group contains.
data-starting-style
Present when the group is animating in.
data-ending-style
Present when the group is animating out.
Attribute | Description | |
|---|---|---|
data-collapsing | Present while the group animates its items out, as its parent collapses. | |
data-expanding | Present while the group animates its items in, as its parent expands. | |
data-parent-id | The id of the item whose children the group contains. | |
data-starting-style | Present when the group is animating in. | |
data-ending-style | Present when the group is animating out. | |
--tree-group-transition-height
The height of the animated group of tree items.
CSS Variable | Description | |
|---|---|---|
--tree-group-transition-height | The height of the animated group of tree items. | |
Tree.GroupTransition.PropsHide
Re-Export of GroupTransition props as TreeGroupTransitionProps
Tree.GroupTransition.StateHide
useFilter
Matches items against a query using Intl.Collator for robust string matching.
This hook is used when customizing how items match.
Call its methods inside the filter prop of <Tree.FilterProvider>.
Parameters
Tree.FilterOptions
localeIntl.LocalesArgument
- Name
- Description
The locale to use for string comparison. Defaults to the user’s runtime locale.
- Type
Return value
Tree.Filter
containsfunction
- Name
- Description
Returns whether the text contains the query.
- Type
startsWithfunction
- Name
- Description
Returns whether the text starts with the query.
- Type
endsWithfunction
- Name
- Description
Returns whether the text ends with the query.
- Type
createItems
Normalizes a custom item model into a collection for the items prop of <Tree.Root>, deriving each item’s ID, label, and children.
Create static collections at module scope, and memoize dynamic collections by their data and every value their accessors read.
Parameters
data*TItem[]—
- Name
- Description
The items to render, or
undefinedwhen there are none yet.- Type
options*CreateTreeItemsOptions<TItem>—
- Name
- Description
Accessors that read and update the item model.
- Type