Introducing PrimeReact v11-alpha 🎉Discover Now

Tree

An unstyled, accessible tree component with compound composition for hierarchical data.

Build fully custom tree views with complete control over layout and styling.

basic-demo

Pre-styled Versions

Choose a pre-styled library to use Tree with ready-made designs.
For hook-based usage without components, see the Headless API.

Features#

  • Compound component API with sub-components: Root, List, Node, Content, Toggle, Icon, Label, Filter, Header, Footer, Empty
  • Three selection modes: single, multiple, and checkbox with parent-child propagation
  • Drag-drop reordering with scope validation for same-tree and cross-tree transfers
  • Built-in filtering with customizable filter input
  • Lazy loading support for on-demand node fetching

Usage#

import { Tree } from 'primereact/tree';
<Tree.Root>
    <Tree.Header>
        <Tree.Filter />
    </Tree.Header>
    <Tree.List>
        <Tree.Node>
            <Tree.Content>
                <Tree.Toggle />
                <Tree.Icon />
                <Tree.Label />
            </Tree.Content>
        </Tree.Node>
    </Tree.List>
    <Tree.Footer />
    <Tree.Empty />
</Tree.Root>

Behavior#

Polymorphic Rendering#

Use as on any sub-component to change the rendered HTML element.

<Tree.Root as="nav">
    <Tree.List>
        <Tree.Node>
            <Tree.Content as="a">
                <Tree.Label />
            </Tree.Content>
        </Tree.Node>
    </Tree.List>
</Tree.Root>

Default elements: Root=div, List=ul, Node=li, Content=div, Toggle=button, Icon=span, Label=span, Filter=input, Header=div, Footer=div, Empty=div.

Render Function Children#

Content accepts a render function as children, providing access to the component instance. The instance exposes tree (root instance) and treenode (current node instance).

<Tree.Content>{(instance) => <div>Node is {instance.treenode?.state.expanded ? 'expanded' : 'collapsed'}</div>}</Tree.Content>

Pass Through#

Some parts may not be visible in the preview depending on the component's current state.

/* Select a part to see its CSS selector for custom styling */

API#

TreeRoot#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: TreeRootInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: TreeRootInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceTreeRootInstance—
The instance to pass to the component.
ptSafeRecord<TreeRootPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: TreeRootInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
valueTreeNodeData[]—
An array of treenodes.
expandedKeysTreeExpandedKeys—
A record of keys to represent the state of the tree expansion state in controlled mode.
defaultExpandedKeysTreeExpandedKeys—
The default expanded keys when used in uncontrolled mode.
selectionKeysTreeSelectionKeys | TreeCheckboxSelectionKeys—
A record of keys to represent the selection state in controlled mode. For single/multiple mode: Record<string, boolean> For checkbox mode: Record<string, { checked: boolean, partialChecked: boolean }>
defaultSelectionKeysTreeSelectionKeys | TreeCheckboxSelectionKeys—
The default selected keys when used in uncontrolled mode.
selectionMode"checkbox" | "multiple" | "single"—
Defines the selection mode.
metaKeySelectionbooleanfalse
Defines how multiple items can be selected, when true metaKey needs to be pressed to select or unselect multiple items. When set to false selection of each item can be toggled individually.
highlightOnSelectbooleanfalse
Highlights automatically the first item.
draggableNodesboolean—
Whether the tree nodes can be dragged.
droppableNodesboolean—
Whether the tree can accept dropped nodes.
draggableScopestring | string[]—
A unique identifier for the draggable scope.
droppableScopestring | string[]—
A unique identifier for the droppable scope.
validateDropbooleanfalse
Whether to validate drops before processing.
onToggle(event: useTreeToggleEvent) => void—
Callback fired when a node is toggled.
onExpand(event: useTreeExpandEvent) => void—
Callback fired when a node is toggled.
onCollapse(event: useTreeCollapseEvent) => void—
Callback fired when a node is toggled.
onClick(event: useTreeClickEvent) => void—
Callback fired when a node is clicked.
onSelect(event: useTreeSelectEvent) => void—
Callback fired when a node is selected.
onUnselect(event: useTreeUnselectEvent) => void—
Callback fired when a node is unselected.
onNodeDrop(event: useTreeNodeDropEvent) => void—
Callback fired when a node is dropped.
onDragEnter(event: useTreeDragEnterEvent) => void—
Callback fired when drag enters the tree.
onDragLeave(event: useTreeDragLeaveEvent) => void—
Callback fired when drag leaves the tree.
onExpandedChange(event: TreeRootExpandedChangeEvent) => void—
Callback fired when the tree's expanded keys state changes.
onSelectionChange(event: TreeRootSelectionChangeEvent) => void—
Callback fired when the tree's selection keys state changes.
onValueChange(event: TreeRootValueChangeEvent) => void—
Callback fired when the tree's value state changes.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"tree"
data-part"root"
data-drag-hoverPresent when a node is being dragged over root

Defines passthrough(pt) options of Tree component.

labeltypedescription
rootTreeRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.
listTreeRootPassThroughType<HTMLAttributes<HTMLUListElement>>Used to pass attributes to the list's DOM element.
nodeTreeRootPassThroughType<HTMLAttributes<HTMLLIElement>>Used to pass attributes to the node's DOM element.
contentTreeRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the content's DOM element.
labelTreeRootPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the label's DOM element.
toggleTreeRootPassThroughType<ButtonHTMLAttributes<HTMLButtonElement>>Used to pass attributes to the toggle button's DOM element.
toggleIconTreeRootPassThroughType<SVGProps<SVGSVGElement>>Used to pass attributes to the toggle icon's DOM element.
pcCheckboxTreeRootPassThroughType<HTMLAttributes<HTMLInputElement>>Used to pass attributes to the checkbox's DOM element.
pcFilterTreeRootPassThroughType<HTMLAttributes<HTMLElement>>Used to pass attributes to the filter's DOM element.
headerTreeRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the header's DOM element.
footerTreeRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the footer's DOM element.
emptyTreeRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the empty message's DOM element.
dropPointTreeRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the drop point's DOM element.

TreeList#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: TreeListInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: TreeListInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceTreeListInstance—
The instance to pass to the component.
ptSafeRecord<TreeListPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: TreeListInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"tree"
data-part"list"

Defines passthrough(pt) options of TreeList component.

labeltypedescription
rootTreeListPassThroughType<HTMLAttributes<HTMLUListElement>>Used to pass attributes to the root's DOM element.

TreeNode#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: TreeNodeInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: TreeNodeInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceTreeNodeInstance—
The instance to pass to the component.
ptSafeRecord<TreeNodePassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: TreeNodeInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
nodeTreeNodeData—
Node data. See TreeNodeData interface for more information.
indexnumber—
Index of the node in the list of siblings.
draggableNodesboolean—
Whether nodes can be dragged.
droppableNodesboolean—
Whether nodes can accept drops.
draggableScopestring | string[]—
Draggable scope identifier.
droppableScopestring | string[]—
Droppable scope identifier.
validateDropbooleanfalse
Whether to validate drops before processing.
onNodeDrop(event: TreeNodeDropEvent) => void—
Callback fired when a node is dropped on this node.
onNodeDragEnter(event: TreeNodeDragEnterEvent) => void—
Callback fired when drag enters this node.
onNodeDragLeave(event: TreeNodeDragLeaveEvent) => void—
Callback fired when drag leaves this node.
onValueChange(event: TreeNodeValueChangeEvent) => void—
Callback fired when the tree value changes.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"tree"
data-part"node"
data-node-keyNode key value
data-expandedPresent when node is expanded (non-leaf only)
data-collapsedPresent when node is collapsed (non-leaf only)
data-selectedPresent when node is selected
data-leafPresent when node is a leaf
data-disabledPresent when node is disabled

Defines passthrough(pt) options of TreeNode component.

labeltypedescription
rootTreeNodePassThroughType<HTMLAttributes<HTMLLIElement>>Used to pass attributes to the root's DOM element.

TreeContent#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: TreeContentInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: TreeContentInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceTreeContentInstance—
The instance to pass to the component.
ptSafeRecord<TreeContentPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: TreeContentInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"tree"
data-part"content"
data-selectedPresent when selected or checked
data-selectablePresent when selectable
data-expandedPresent when expanded (non-leaf only)
data-collapsedPresent when collapsed (non-leaf only)
data-leafPresent when leaf node
data-checkedPresent when checked (checkbox mode)
data-partial-checkedPresent when partially checked (checkbox mode)
data-disabledPresent when disabled
data-drop-hoverPresent when a dragged node hovers over content

Defines passthrough(pt) options of TreeContent component.

labeltypedescription
rootTreeContentPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

TreeToggle#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: TreeToggleInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: TreeToggleInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceTreeToggleInstance—
The instance to pass to the component.
ptSafeRecord<TreeTogglePassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: TreeToggleInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"tree"
data-part"toggle"
data-expandedPresent when node is expanded
data-collapsedPresent when node is collapsed

Defines passthrough(pt) options of TreeToggle component.

labeltypedescription
rootTreeTogglePassThroughType<ButtonHTMLAttributes<HTMLButtonElement>>Used to pass attributes to the root's DOM element.
toggleIconTreeTogglePassThroughType<SVGProps<SVGSVGElement>>Used to pass attributes to the toggle icon's DOM element.

TreeIcon#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: TreeIconInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: TreeIconInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceTreeIconInstance—
The instance to pass to the component.
ptSafeRecord<TreeIconPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: TreeIconInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of TreeIcon component.

labeltypedescription
rootTreeIconPassThroughType<SVGAttributes<SVGElement>>Used to pass attributes to the root's DOM element.

TreeLabel#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: TreeLabelInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: TreeLabelInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceTreeLabelInstance—
The instance to pass to the component.
ptSafeRecord<TreeLabelPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: TreeLabelInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of TreeLabel component.

labeltypedescription
rootTreeLabelPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the root's DOM element.

TreeFilter#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: TreeFilterInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: TreeFilterInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceTreeFilterInstance—
The instance to pass to the component.
ptSafeRecord<TreeFilterPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: TreeFilterInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"tree"
data-part"filter"

Defines passthrough(pt) options of TreeFilter component.

labeltypedescription
rootTreeFilterPassThroughType<HTMLAttributes<HTMLElement>>Used to pass attributes to the root's DOM element.

TreeHeader#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: TreeHeaderInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: TreeHeaderInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceTreeHeaderInstance—
The instance to pass to the component.
ptSafeRecord<TreeHeaderPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: TreeHeaderInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of TreeHeader component.

labeltypedescription
rootTreeHeaderPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

TreeFooter#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: TreeFooterInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: TreeFooterInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceTreeFooterInstance—
The instance to pass to the component.
ptSafeRecord<TreeFooterPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: TreeFooterInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of TreeFooter component.

labeltypedescription
rootTreeFooterPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

TreeEmpty#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: TreeEmptyInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: TreeEmptyInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceTreeEmptyInstance—
The instance to pass to the component.
ptSafeRecord<TreeEmptyPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: TreeEmptyInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of TreeEmpty component.

labeltypedescription
rootTreeEmptyPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

Accessibility#

Screen Reader#

The root list element uses role="tree" while each list item uses role="treeitem" with aria-label, aria-selected, and aria-expanded attributes. In checkbox selection, aria-checked is used instead of aria-selected. Child containers use role="group". Toggle icons are hidden from screen readers as their parent treeitem element with its attributes is used instead. The aria-setsize, aria-posinset, and aria-level attributes are calculated implicitly and added to each treeitem.

Keyboard Support#

KeyFunction
tabMoves focus to the first selected node when focus enters the component, if there is none then first element receives the focus. If focus is already inside the component, moves focus to the next focusable element in the page tab sequence.
shift + tabMoves focus to the last selected node when focus enters the component, if there is none then first element receives the focus. If focus is already inside the component, moves focus to the previous focusable element in the page tab sequence.
enterSelects the focused treenode.
spaceSelects the focused treenode.
down arrowMoves focus to the next treenode.
up arrowMoves focus to the previous treenode.
right arrowIf node is closed, opens the node otherwise moves focus to the first child node.
left arrowIf node is open, closes the node otherwise moves focus to the parent node.