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 of the native component are also available.
| Name | Type | Default | Description |
|---|---|---|---|
| itemId* | string | - | The id of the item. Must be unique. |
| classes | Partial | - | Override or extend the styles applied to the component. See CSS classes API below for more details. |
| disabled | bool | false | If |
| disableSelection | bool | false | If |
| id | string | - | The id attribute of the item. If not provided, it will be generated. |
| label | node | - | The label of the item. |
| onBlur | func | - | Callback fired when the item root is blurred. Signature: function(event: FocusEvent<HTMLLIElement, Element> & TreeViewCancellableEvent) => void |
| onFocus | any | - | This prop isn't supported.
Use the |
| onKeyDown | func | - | Callback fired when a key is pressed on the keyboard and the tree is in focus. Signature: function(event: KeyboardEvent<HTMLLIElement> & TreeViewCancellableEvent) => void |
| slotProps | TreeItemSlotProps | {} | The props used for each component slot. |
| slots | TreeItemSlots | {} | Overridable component slots. See Slots API below for more details. |
| sx | Array<func | object | bool> | func | object | - | The system prop that allows defining system overrides as well as additional CSS styles. See the `sx` page for more details. |
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.
| Slot name | Class name | Default component | Description |
|---|---|---|---|
| checkbox | .MuiTreeItem-checkbox | TreeItemCheckbox | The component that renders the item checkbox for selection. |
| collapseIcon | The icon used to collapse the item. | ||
| content | .MuiTreeItem-content | TreeItemContent | The component that renders the content of the item. (e.g.: everything related to this item, not to its children). |
| dragAndDropOverlay | .MuiTreeItem-dragAndDropOverlay | TreeItemDragAndDropOverlay | The component that renders the overlay when an item reordering is ongoing.
Warning: This slot is only useful when using the ` |
| endIcon | The icon displayed next to an end item. | ||
| errorIcon | .MuiTreeItem-errorIcon | TreeItemErrorContainer | The component that is rendered when the item is in an error state.
Warning: This slot is only useful when using the ` |
| expandIcon | The icon used to expand the item. | ||
| groupTransition | .MuiTreeItem-groupTransition | TreeItemGroupTransition | The component that renders the children of the item. |
| icon | The icon to display next to the Tree Item's label. | ||
| iconContainer | .MuiTreeItem-iconContainer | TreeItemIconContainer | The component that renders the icon. |
| label | .MuiTreeItem-label | TreeItemLabel | The component that renders the item label. |
| labelInput | .MuiTreeItem-labelInput | TreeItemLabelInput | The component that renders the input to edit the label when the item is editable and is currently being edited. |
| loadingIcon | .MuiTreeItem-loadingIcon | TreeItemLoadingContainer | The component that is rendered when the item is in a loading state.
Warning: This slot is only useful when using the ` |
| root | .MuiTreeItem-root | TreeItemRoot | The component that renders the root. |
These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.
| Class name | Rule name | Description |
|---|---|---|
| .MuiTreeItem-checkbox | checkbox | Styles applied to the checkbox element. |
| .MuiTreeItem-content | content | Styles applied to the content element. |
| .MuiTreeItem-dragAndDropOverlay | dragAndDropOverlay | Styles applied to the drag and drop overlay element. |
| .MuiTreeItem-errorIcon | errorIcon | Styles applied to the error icon element |
| .MuiTreeItem-groupTransition | groupTransition | Styles applied to the transition element. |
| .MuiTreeItem-iconContainer | iconContainer | Styles applied to the icon container element. |
| .MuiTreeItem-label | label | Styles applied to the label element. |
| .MuiTreeItem-labelInput | labelInput | Styles applied to the label input element (visible only when editing is enabled). |
| .MuiTreeItem-loadingIcon | loadingIcon | Styles applied to the loading icon element |
| .MuiTreeItem-root | root | Styles applied to the root element. |
You can override the style of the component using one of these customization options:
- With a global class name.
- With a rule name as part of the component's
styleOverridesproperty in a custom theme.
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.