Rich Tree View - Label editing
Learn how to edit the label of Tree View items.
Enable label editing
You can use the isItemEditable prop to enable editing.
If set to true, this prop will enable label editing on all items:
- @mui/x-data-grid
- @mui/x-data-grid-pro
- @mui/x-date-pickers
- @mui/x-date-pickers-pro
- Charts
- Tree View
Limit editing to some items
If you pass a method to isItemEditable, only the items for which the method returns true will be editable:
- @mui/x-data-grid editable
- @mui/x-data-grid-pro editable
- @mui/x-date-pickers
- @mui/x-date-pickers-pro
- Charts
- Tree View
Limit editing to leaves
You can limit the editing to just the leaves of the tree.
- @mui/x-data-grid
- @mui/x-data-grid-pro
- @mui/x-date-pickers
- @mui/x-date-pickers-pro
- Charts
- Tree View
Track item label change
Use the onItemLabelChange prop to trigger an action when the label of an item changes.
No item has been edited yet
- @mui/x-data-grid
- @mui/x-data-grid-pro
- @mui/x-date-pickers
- @mui/x-date-pickers-pro
- Charts
- Tree View
Change the default behavior
By default, blurring the tree item saves the new value if there is one.
To modify this behavior, use the slotProps of the TreeItem2.
- @mui/x-data-grid
- @mui/x-data-grid-pro
- @mui/x-date-pickers
- @mui/x-date-pickers-pro
- Charts
- Tree View
Validation
You can override the event handlers of the labelInput and implement a custom validation logic using the interaction methods from useTreeItem2Utils.
- @mui/x-data-grid
- @mui/x-data-grid-pro
- @mui/x-date-pickers
- @mui/x-date-pickers-pro
- Charts
- Tree View
Enable editing using only icons
The demo below shows how to entirely override the editing behavior, and implement it using icons.
- @mui/x-data-grid
- @mui/x-data-grid-pro
- @mui/x-date-pickers
- @mui/x-date-pickers-pro
- Charts
- Tree View
Create a custom labelInput
The demo below shows how to use a different component in the labelInput slot.
- Elena Kim
- Noah Rodriguez
- Maya Patel
- Ethan Lee
- Ava Jones
Imperative API
Change the label of an item
Use the setItemExpansion API method to change the expansion of an item.
apiRef.current.updateItemLabel(
// The id of the item to to update
itemId,
// The new label of the item.
newLabel,
);
- Data Grid
- Date and time pickers
- Charts
- Tree View