Skip to content

TreeItem API

API reference docs for the React TreeItem component. Learn about the props, CSS, and other APIs of this exported module.

Demos

Import

import { TreeItem } from '@mui/x-tree-view/TreeItem';
// or
import { TreeItem } from '@mui/x-tree-view';
// or
import { TreeItem } from '@mui/x-tree-view-pro';

Learn about the difference by reading this guide on minimizing bundle size.

Props

Props of the native component are also available.

NameTypeDefaultDescription
itemId*string-

The id of the item. Must be unique.

childrenany-

The content of the component.

classesobject-

Override or extend the styles applied to the component.

See CSS classes API below for more details.

disabledboolfalse

If true, the item is disabled.

idstring-

The id attribute of the item. If not provided, it will be generated.

labelnode-

The label of the item.

onBlurfunc-

Callback fired when the item root is blurred.

onFocusunsupportedProp-

This prop isn't supported. Use the onItemFocus callback on the tree if you need to monitor an item's focus.

onKeyDownfunc-

Callback fired when a key is pressed on the keyboard and the tree is in focus.

slotPropsobject{}

The props used for each component slot.

slotsobject{}

Overridable component slots.

See Slots API below for more details.

The ref is forwarded to the root element.

Theme default props

You can use MuiTreeItem to change the default props of this component with the theme.

Slots

Slot nameClass nameDefault componentDescription
root.MuiTreeItem-rootTreeItemRootThe component that renders the root.
content.MuiTreeItem-contentTreeItemContentThe component that renders the content of the item. (e.g.: everything related to this item, not to its children).
groupTransition.MuiTreeItem-groupTransitionTreeItemGroupTransitionThe component that renders the children of the item.
iconContainer.MuiTreeItem-iconContainerTreeItemIconContainerThe component that renders the icon.
checkbox.MuiTreeItem-checkboxTreeItemCheckboxThe component that renders the item checkbox for selection.
label.MuiTreeItem-labelTreeItemLabelThe component that renders the item label.
labelInput.MuiTreeItem-labelInputTreeItemLabelInputThe component that renders the input to edit the label when the item is editable and is currently being edited.
dragAndDropOverlay.MuiTreeItem-dragAndDropOverlayTreeItemDragAndDropOverlayThe component that renders the overlay when an item reordering is ongoing. Warning: This slot is only useful when using the <RichTreeViewPro /> component.
collapseIconThe icon used to collapse the item.
expandIconThe icon used to expand the item.
endIconThe icon displayed next to an end item.
iconThe icon to display next to the Tree Item's label.

CSS classes

These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.

Class nameRule nameDescription
.Mui-disabledState class applied to the element when disabled.
.Mui-expandedState class applied to the content element when expanded.
.Mui-focusedState class applied to the content element when focused.
.Mui-selectedState class applied to the content element when selected.
.MuiTreeItem-editableeditableStyles applied to the content of the items that are editable.
.MuiTreeItem-editingeditingStyles applied to the content element when editing is enabled.

You can override the style of the component using one of these customization options:

Source code

If you did not find the information in this page, consider having a look at the implementation of the component for more detail.