Skip to contentSkip 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.



Demos:

API:

Props

Props of the native component are also available.

NameTypeDefaultDescription
itemId*string-

The id of the item. Must be unique.

classesPartial-

Override or extend the styles applied to the component.

See CSS classes API below for more details.

disabledboolfalse

If true, the item is disabled.

disableSelectionboolfalse

If true, the item cannot be selected.

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.

Signature:function(event: FocusEvent<HTMLLIElement, Element> & TreeViewCancellableEvent) => void
    onFocusany-

    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.

    Signature:function(event: KeyboardEvent<HTMLLIElement> & TreeViewCancellableEvent) => void
      slotPropsTreeItemSlotProps{}

      The props used for each component slot.

      slotsTreeItemSlots{}

      Overridable component slots.

      See Slots API below for more details.

      sxArray<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.

      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
      checkbox.MuiTreeItem-checkboxTreeItemCheckboxThe component that renders the item checkbox for selection.
      collapseIconThe icon used to collapse the item.
      content.MuiTreeItem-contentTreeItemContentThe component that renders the content of the item. (e.g.: everything related to this item, not to its children).
      dragAndDropOverlay.MuiTreeItem-dragAndDropOverlayTreeItemDragAndDropOverlayThe component that renders the overlay when an item reordering is ongoing. Warning: This slot is only useful when using the `` component.
      endIconThe icon displayed next to an end item.
      errorIcon.MuiTreeItem-errorIconTreeItemErrorContainerThe component that is rendered when the item is in an error state. Warning: This slot is only useful when using the `` component is lazy loading is enabled.
      expandIconThe icon used to expand the item.
      groupTransition.MuiTreeItem-groupTransitionTreeItemGroupTransitionThe component that renders the children of the item.
      iconThe icon to display next to the Tree Item's label.
      iconContainer.MuiTreeItem-iconContainerTreeItemIconContainerThe component that renders the icon.
      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.
      loadingIcon.MuiTreeItem-loadingIconTreeItemLoadingContainerThe component that is rendered when the item is in a loading state. Warning: This slot is only useful when using the `` component is lazy loading is enabled.
      root.MuiTreeItem-rootTreeItemRootThe component that renders the root.

      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
      .MuiTreeItem-checkboxcheckboxStyles applied to the checkbox element.
      .MuiTreeItem-contentcontentStyles applied to the content element.
      .MuiTreeItem-dragAndDropOverlaydragAndDropOverlayStyles applied to the drag and drop overlay element.
      .MuiTreeItem-errorIconerrorIconStyles applied to the error icon element
      .MuiTreeItem-groupTransitiongroupTransitionStyles applied to the transition element.
      .MuiTreeItem-iconContainericonContainerStyles applied to the icon container element.
      .MuiTreeItem-labellabelStyles applied to the label element.
      .MuiTreeItem-labelInputlabelInputStyles applied to the label input element (visible only when editing is enabled).
      .MuiTreeItem-loadingIconloadingIconStyles applied to the loading icon element
      .MuiTreeItem-rootrootStyles applied to the root element.

      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.