@mui/x-tree-view 7.19.0 → 7.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +224 -43
  2. package/RichTreeView/RichTreeView.js +14 -53
  3. package/SimpleTreeView/SimpleTreeView.js +8 -8
  4. package/TreeItem/TreeItem.js +25 -12
  5. package/TreeItem/TreeItem.types.d.ts +6 -4
  6. package/TreeItem/TreeItemContent.d.ts +5 -5
  7. package/TreeItem/TreeItemContent.js +29 -33
  8. package/TreeItem/treeItemClasses.d.ts +1 -1
  9. package/TreeItem2/TreeItem2.types.d.ts +1 -1
  10. package/TreeItem2DragAndDropOverlay/TreeItem2DragAndDropOverlay.js +7 -7
  11. package/TreeItem2Icon/TreeItem2Icon.types.d.ts +1 -1
  12. package/TreeView/TreeView.d.ts +1 -1
  13. package/TreeView/TreeView.js +8 -8
  14. package/index.js +1 -1
  15. package/internals/components/RichTreeViewItems.d.ts +35 -0
  16. package/internals/components/RichTreeViewItems.js +56 -0
  17. package/internals/corePlugins/corePlugins.d.ts +1 -1
  18. package/internals/corePlugins/corePlugins.js +1 -1
  19. package/internals/corePlugins/useTreeViewId/useTreeViewId.js +3 -3
  20. package/internals/corePlugins/useTreeViewId/useTreeViewId.types.d.ts +1 -1
  21. package/internals/corePlugins/useTreeViewId/useTreeViewId.utils.d.ts +1 -1
  22. package/internals/corePlugins/useTreeViewId/useTreeViewId.utils.js +1 -1
  23. package/internals/index.d.ts +1 -0
  24. package/internals/index.js +1 -0
  25. package/internals/models/treeView.d.ts +2 -2
  26. package/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.types.d.ts +2 -2
  27. package/internals/plugins/useTreeViewFocus/useTreeViewFocus.types.d.ts +1 -1
  28. package/internals/plugins/useTreeViewIcons/useTreeViewIcons.types.d.ts +1 -1
  29. package/internals/plugins/useTreeViewItems/index.d.ts +1 -1
  30. package/internals/plugins/useTreeViewItems/useTreeViewItems.types.d.ts +8 -8
  31. package/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.js +1 -1
  32. package/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js +3 -3
  33. package/internals/plugins/useTreeViewLabel/useTreeViewLabel.js +1 -1
  34. package/internals/plugins/useTreeViewLabel/useTreeViewLabel.types.d.ts +1 -1
  35. package/internals/plugins/useTreeViewSelection/useTreeViewSelection.types.d.ts +3 -3
  36. package/modern/RichTreeView/RichTreeView.js +14 -53
  37. package/modern/SimpleTreeView/SimpleTreeView.js +8 -8
  38. package/modern/TreeItem/TreeItem.js +25 -12
  39. package/modern/TreeItem/TreeItemContent.js +29 -33
  40. package/modern/TreeItem2DragAndDropOverlay/TreeItem2DragAndDropOverlay.js +7 -7
  41. package/modern/TreeView/TreeView.js +8 -8
  42. package/modern/index.js +1 -1
  43. package/modern/internals/components/RichTreeViewItems.js +56 -0
  44. package/modern/internals/corePlugins/corePlugins.js +1 -1
  45. package/modern/internals/corePlugins/useTreeViewId/useTreeViewId.js +3 -3
  46. package/modern/internals/corePlugins/useTreeViewId/useTreeViewId.utils.js +1 -1
  47. package/modern/internals/index.js +1 -0
  48. package/modern/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.js +1 -1
  49. package/modern/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js +3 -3
  50. package/modern/internals/plugins/useTreeViewLabel/useTreeViewLabel.js +1 -1
  51. package/modern/useTreeItem2/useTreeItem2.js +11 -11
  52. package/node/RichTreeView/RichTreeView.js +14 -53
  53. package/node/SimpleTreeView/SimpleTreeView.js +8 -8
  54. package/node/TreeItem/TreeItem.js +25 -12
  55. package/node/TreeItem/TreeItemContent.js +29 -33
  56. package/node/TreeItem2DragAndDropOverlay/TreeItem2DragAndDropOverlay.js +7 -7
  57. package/node/TreeView/TreeView.js +8 -8
  58. package/node/index.js +1 -1
  59. package/node/internals/components/RichTreeViewItems.js +64 -0
  60. package/node/internals/corePlugins/corePlugins.js +1 -1
  61. package/node/internals/corePlugins/useTreeViewId/useTreeViewId.js +3 -3
  62. package/node/internals/corePlugins/useTreeViewId/useTreeViewId.utils.js +1 -1
  63. package/node/internals/index.js +7 -0
  64. package/node/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.js +1 -1
  65. package/node/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js +3 -3
  66. package/node/internals/plugins/useTreeViewLabel/useTreeViewLabel.js +1 -1
  67. package/node/useTreeItem2/useTreeItem2.js +11 -11
  68. package/package.json +4 -4
  69. package/useTreeItem2/index.d.ts +1 -1
  70. package/useTreeItem2/useTreeItem2.js +11 -11
  71. package/useTreeItem2/useTreeItem2.types.d.ts +2 -2
@@ -53,7 +53,7 @@ const SimpleTreeView = /*#__PURE__*/React.forwardRef(function SimpleTreeView(inP
53
53
  const ownerState = props;
54
54
  if (process.env.NODE_ENV !== 'production') {
55
55
  if (props.items != null) {
56
- warnOnce(['MUI X: The `SimpleTreeView` component does not support the `items` prop.', 'If you want to add items, you need to pass them as JSX children.', 'Check the documentation for more details: https://mui.com/x/react-tree-view/simple-tree-view/items/.']);
56
+ warnOnce(['MUI X: The Simple Tree View component does not support the `items` prop.', 'If you want to add items, you need to pass them as JSX children.', 'Check the documentation for more details: https://mui.com/x/react-tree-view/simple-tree-view/items/.']);
57
57
  }
58
58
  }
59
59
  const {
@@ -104,7 +104,7 @@ process.env.NODE_ENV !== "production" ? SimpleTreeView.propTypes = {
104
104
  })
105
105
  }),
106
106
  /**
107
- * If `true`, the tree view renders a checkbox at the left of its label that allows selecting it.
107
+ * If `true`, the Tree View renders a checkbox at the left of its label that allows selecting it.
108
108
  * @default false
109
109
  */
110
110
  checkboxSelection: PropTypes.bool,
@@ -174,39 +174,39 @@ process.env.NODE_ENV !== "production" ? SimpleTreeView.propTypes = {
174
174
  */
175
175
  multiSelect: PropTypes.bool,
176
176
  /**
177
- * Callback fired when tree items are expanded/collapsed.
177
+ * Callback fired when Tree Items are expanded/collapsed.
178
178
  * @param {React.SyntheticEvent} event The DOM event that triggered the change.
179
179
  * @param {array} itemIds The ids of the expanded items.
180
180
  */
181
181
  onExpandedItemsChange: PropTypes.func,
182
182
  /**
183
- * Callback fired when the `content` slot of a given tree item is clicked.
183
+ * Callback fired when the `content` slot of a given Tree Item is clicked.
184
184
  * @param {React.MouseEvent} event The DOM event that triggered the change.
185
185
  * @param {string} itemId The id of the focused item.
186
186
  */
187
187
  onItemClick: PropTypes.func,
188
188
  /**
189
- * Callback fired when a tree item is expanded or collapsed.
189
+ * Callback fired when a Tree Item is expanded or collapsed.
190
190
  * @param {React.SyntheticEvent} event The DOM event that triggered the change.
191
191
  * @param {array} itemId The itemId of the modified item.
192
192
  * @param {array} isExpanded `true` if the item has just been expanded, `false` if it has just been collapsed.
193
193
  */
194
194
  onItemExpansionToggle: PropTypes.func,
195
195
  /**
196
- * Callback fired when a given tree item is focused.
196
+ * Callback fired when a given Tree Item is focused.
197
197
  * @param {React.SyntheticEvent | null} event The DOM event that triggered the change. **Warning**: This is a generic event not a focus event.
198
198
  * @param {string} itemId The id of the focused item.
199
199
  */
200
200
  onItemFocus: PropTypes.func,
201
201
  /**
202
- * Callback fired when a tree item is selected or deselected.
202
+ * Callback fired when a Tree Item is selected or deselected.
203
203
  * @param {React.SyntheticEvent} event The DOM event that triggered the change.
204
204
  * @param {array} itemId The itemId of the modified item.
205
205
  * @param {array} isSelected `true` if the item has just been selected, `false` if it has just been deselected.
206
206
  */
207
207
  onItemSelectionToggle: PropTypes.func,
208
208
  /**
209
- * Callback fired when tree items are selected/deselected.
209
+ * Callback fired when Tree Items are selected/deselected.
210
210
  * @param {React.SyntheticEvent} event The DOM event that triggered the change.
211
211
  * @param {string[] | string} itemIds The ids of the selected items.
212
212
  * When `multiSelect` is `true`, this is an array of strings; when false (default) a string.
@@ -19,6 +19,7 @@ import resolveComponentProps from '@mui/utils/resolveComponentProps';
19
19
  import useSlotProps from '@mui/utils/useSlotProps';
20
20
  import unsupportedProp from '@mui/utils/unsupportedProp';
21
21
  import elementTypeAcceptingRef from '@mui/utils/elementTypeAcceptingRef';
22
+ import { warnOnce } from '@mui/x-internals/warning';
22
23
  import { styled, createUseThemeProps } from "../internals/zero-styled/index.js";
23
24
  import { TreeItemContent } from "./TreeItemContent.js";
24
25
  import { treeItemClasses, getTreeItemUtilityClass } from "./treeItemClasses.js";
@@ -181,7 +182,7 @@ export const TreeItem = /*#__PURE__*/React.forwardRef(function TreeItem(inProps,
181
182
  indentationAtItemLevel
182
183
  },
183
184
  selection: {
184
- multiSelect
185
+ disableSelection
185
186
  },
186
187
  expansion: {
187
188
  expansionTrigger
@@ -220,6 +221,15 @@ export const TreeItem = /*#__PURE__*/React.forwardRef(function TreeItem(inProps,
220
221
  handleCancelItemLabelEditing,
221
222
  handleSaveItemLabel
222
223
  } = useTreeItemState(itemId);
224
+ if (process.env.NODE_ENV !== 'production') {
225
+ // Checking directly the `props` to avoid having the default value applied
226
+ if (props.ContentComponent) {
227
+ warnOnce(['MUI X: The ContentComponent prop of the TreeItem component is deprecated and will be removed in the next major release.', 'You can use the new TreeItem2 component or the new useTreeItem2 hook to customize the rendering of the content.', 'For more detail, see https://mui.com/x/react-tree-view/tree-item-customization/.']);
228
+ }
229
+ if (props.ContentProps) {
230
+ warnOnce(['MUI X: The ContentProps prop of the TreeItem component is deprecated and will be removed in the next major release.', 'You can use the new TreeItem2 component or the new useTreeItem2 hook to customize the rendering of the content.', 'For more detail, see https://mui.com/x/react-tree-view/tree-item-customization/.']);
231
+ }
232
+ }
223
233
  const {
224
234
  contentRef,
225
235
  rootRef,
@@ -308,17 +318,18 @@ export const TreeItem = /*#__PURE__*/React.forwardRef(function TreeItem(inProps,
308
318
  }),
309
319
  iconProps = _objectWithoutPropertiesLoose(_useSlotProps3, _excluded4);
310
320
  const icon = Icon ? /*#__PURE__*/_jsx(Icon, _extends({}, iconProps)) : null;
321
+
322
+ // https://www.w3.org/WAI/ARIA/apg/patterns/treeview/
311
323
  let ariaSelected;
312
- if (multiSelect) {
313
- ariaSelected = selected;
314
- } else if (selected) {
315
- /* single-selection trees unset aria-selected on un-selected items.
316
- *
317
- * If the tree does not support multiple selection, aria-selected
318
- * is set to true for the selected item and it is not present on any other item in the tree.
319
- * Source: https://www.w3.org/WAI/ARIA/apg/patterns/treeview/
320
- */
324
+ if (selected) {
325
+ // - each selected node has aria-selected set to true.
321
326
  ariaSelected = true;
327
+ } else if (disableSelection || disabled) {
328
+ // - if the tree contains nodes that are not selectable, aria-selected is not present on those nodes.
329
+ ariaSelected = undefined;
330
+ } else {
331
+ // - all nodes that are selectable but not selected have aria-selected set to false.
332
+ ariaSelected = false;
322
333
  }
323
334
  function handleFocus(event) {
324
335
  const canBeFocused = !disabled || disabledItemsFocusable;
@@ -329,7 +340,7 @@ export const TreeItem = /*#__PURE__*/React.forwardRef(function TreeItem(inProps,
329
340
  function handleBlur(event) {
330
341
  onBlur?.(event);
331
342
  if (editing ||
332
- // we can exit the editing state by clicking outside the input (within the tree item) or by pressing Enter or Escape -> we don't want to remove the focused item from the state in these cases
343
+ // we can exit the editing state by clicking outside the input (within the Tree Item) or by pressing Enter or Escape -> we don't want to remove the focused item from the state in these cases
333
344
  // we can also exit the editing state by clicking on the root itself -> want to remove the focused item from the state in this case
334
345
  event.relatedTarget && isTargetInDescendants(event.relatedTarget, rootRefObject.current) && (event.target && event.target?.dataset?.element === 'labelInput' && isTargetInDescendants(event.target, rootRefObject.current) || event.relatedTarget?.dataset?.element === 'labelInput')) {
335
346
  return;
@@ -442,11 +453,13 @@ process.env.NODE_ENV !== "production" ? TreeItem.propTypes = {
442
453
  className: PropTypes.string,
443
454
  /**
444
455
  * The component used to render the content of the item.
456
+ * @deprecated Consider using the `<TreeItem2 />` component or the `useTreeItem2` hook instead. For more details, see https://mui.com/x/react-tree-view/tree-item-customization/.
445
457
  * @default TreeItemContent
446
458
  */
447
459
  ContentComponent: elementTypeAcceptingRef,
448
460
  /**
449
461
  * Props applied to ContentComponent.
462
+ * @deprecated Consider using the `<TreeItem2 />` component or the `useTreeItem2` hook instead. For more details, see https://mui.com/x/react-tree-view/tree-item-customization/.
450
463
  */
451
464
  ContentProps: PropTypes.object,
452
465
  /**
@@ -459,7 +472,7 @@ process.env.NODE_ENV !== "production" ? TreeItem.propTypes = {
459
472
  */
460
473
  itemId: PropTypes.string.isRequired,
461
474
  /**
462
- * The tree item label.
475
+ * The Tree Item label.
463
476
  */
464
477
  label: PropTypes.node,
465
478
  /**
@@ -28,7 +28,7 @@ export interface TreeItemSlots {
28
28
  */
29
29
  endIcon?: React.ElementType;
30
30
  /**
31
- * The icon to display next to the tree item's label.
31
+ * The icon to display next to the Tree Item's label.
32
32
  */
33
33
  icon?: React.ElementType;
34
34
  /**
@@ -66,11 +66,13 @@ export interface TreeItemProps extends Omit<React.HTMLAttributes<HTMLLIElement>,
66
66
  slotProps?: TreeItemSlotProps;
67
67
  /**
68
68
  * The component used to render the content of the item.
69
+ * @deprecated Consider using the `<TreeItem2 />` component or the `useTreeItem2` hook instead. For more details, see https://mui.com/x/react-tree-view/tree-item-customization/.
69
70
  * @default TreeItemContent
70
71
  */
71
72
  ContentComponent?: React.JSXElementConstructor<TreeItemContentProps>;
72
73
  /**
73
74
  * Props applied to ContentComponent.
75
+ * @deprecated Consider using the `<TreeItem2 />` component or the `useTreeItem2` hook instead. For more details, see https://mui.com/x/react-tree-view/tree-item-customization/.
74
76
  */
75
77
  ContentProps?: React.HTMLAttributes<HTMLElement> & {
76
78
  ref?: React.Ref<HTMLElement>;
@@ -86,7 +88,7 @@ export interface TreeItemProps extends Omit<React.HTMLAttributes<HTMLLIElement>,
86
88
  */
87
89
  onFocus?: null;
88
90
  /**
89
- * The tree item label.
91
+ * The Tree Item label.
90
92
  */
91
93
  label?: React.ReactNode;
92
94
  /**
@@ -110,7 +112,7 @@ export interface TreeItemOwnerState extends TreeItemProps {
110
112
  indentationAtItemLevel: boolean;
111
113
  }
112
114
  /**
113
- * Plugins that need to be present in the Tree View in order for `TreeItem` to work correctly.
115
+ * Plugins that need to be present in the Tree View in order for Tree Item to work correctly.
114
116
  */
115
117
  export type TreeItemMinimalPlugins = readonly [
116
118
  UseTreeViewIconsSignature,
@@ -121,6 +123,6 @@ export type TreeItemMinimalPlugins = readonly [
121
123
  UseTreeViewKeyboardNavigationSignature
122
124
  ];
123
125
  /**
124
- * Plugins that `TreeItem` can use if they are present, but are not required.
126
+ * Plugins that Tree Item can use if they are present, but are not required.
125
127
  */
126
128
  export type TreeItemOptionalPlugins = readonly [];
@@ -17,7 +17,7 @@ export interface TreeItemContentProps extends React.HTMLAttributes<HTMLElement>
17
17
  focused: string;
18
18
  /** State class applied to the element when disabled. */
19
19
  disabled: string;
20
- /** Styles applied to the tree item icon and collapse/expand icon. */
20
+ /** Styles applied to the Tree Item icon and collapse/expand icon. */
21
21
  iconContainer: string;
22
22
  /** Styles applied to the label element. */
23
23
  label: string;
@@ -31,7 +31,7 @@ export interface TreeItemContentProps extends React.HTMLAttributes<HTMLElement>
31
31
  editable: string;
32
32
  };
33
33
  /**
34
- * The tree item label.
34
+ * The Tree Item label.
35
35
  */
36
36
  label?: React.ReactNode;
37
37
  /**
@@ -39,15 +39,15 @@ export interface TreeItemContentProps extends React.HTMLAttributes<HTMLElement>
39
39
  */
40
40
  itemId: string;
41
41
  /**
42
- * The icon to display next to the tree item's label.
42
+ * The icon to display next to the Tree Item's label.
43
43
  */
44
44
  icon?: React.ReactNode;
45
45
  /**
46
- * The icon to display next to the tree item's label. Either an expansion or collapse icon.
46
+ * The icon to display next to the Tree Item's label. Either an expansion or collapse icon.
47
47
  */
48
48
  expansionIcon?: React.ReactNode;
49
49
  /**
50
- * The icon to display next to the tree item's label. Either a parent or end icon.
50
+ * The icon to display next to the Tree Item's label. Either a parent or end icon.
51
51
  */
52
52
  displayIcon?: React.ReactNode;
53
53
  dragAndDropOverlayProps?: TreeItem2DragAndDropOverlayProps;
@@ -73,35 +73,31 @@ const TreeItemContent = /*#__PURE__*/React.forwardRef(function TreeItemContent(p
73
73
  }
74
74
  toggleItemEditing();
75
75
  };
76
- return (
77
- /*#__PURE__*/
78
- /* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions -- Key event is handled by the TreeView */
79
- _jsxs("div", _extends({}, other, {
80
- className: clsx(classes.root, className, expanded && classes.expanded, selected && classes.selected, focused && classes.focused, disabled && classes.disabled, editing && classes.editing, editable && classes.editable),
81
- onClick: handleClick,
82
- onMouseDown: handleMouseDown,
83
- ref: ref,
84
- children: [/*#__PURE__*/_jsx("div", {
85
- className: classes.iconContainer,
86
- children: icon
87
- }), checkboxSelection && /*#__PURE__*/_jsx(Checkbox, {
88
- className: classes.checkbox,
89
- checked: selected,
90
- onChange: handleCheckboxSelection,
91
- disabled: disabled || disableSelection,
92
- ref: checkboxRef,
93
- tabIndex: -1
94
- }), editing ? /*#__PURE__*/_jsx(TreeItem2LabelInput, _extends({}, labelInputProps, {
95
- className: classes.labelInput
96
- })) : /*#__PURE__*/_jsx("div", _extends({
97
- className: classes.label
98
- }, editable && {
99
- onDoubleClick: handleLabelDoubleClick
100
- }, {
101
- children: label
102
- })), dragAndDropOverlayProps && /*#__PURE__*/_jsx(TreeItem2DragAndDropOverlay, _extends({}, dragAndDropOverlayProps))]
103
- }))
104
- );
76
+ return /*#__PURE__*/ /* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions -- Key event is handled by the TreeView */_jsxs("div", _extends({}, other, {
77
+ className: clsx(classes.root, className, expanded && classes.expanded, selected && classes.selected, focused && classes.focused, disabled && classes.disabled, editing && classes.editing, editable && classes.editable),
78
+ onClick: handleClick,
79
+ onMouseDown: handleMouseDown,
80
+ ref: ref,
81
+ children: [/*#__PURE__*/_jsx("div", {
82
+ className: classes.iconContainer,
83
+ children: icon
84
+ }), checkboxSelection && /*#__PURE__*/_jsx(Checkbox, {
85
+ className: classes.checkbox,
86
+ checked: selected,
87
+ onChange: handleCheckboxSelection,
88
+ disabled: disabled || disableSelection,
89
+ ref: checkboxRef,
90
+ tabIndex: -1
91
+ }), editing ? /*#__PURE__*/_jsx(TreeItem2LabelInput, _extends({}, labelInputProps, {
92
+ className: classes.labelInput
93
+ })) : /*#__PURE__*/_jsx("div", _extends({
94
+ className: classes.label
95
+ }, editable && {
96
+ onDoubleClick: handleLabelDoubleClick
97
+ }, {
98
+ children: label
99
+ })), dragAndDropOverlayProps && /*#__PURE__*/_jsx(TreeItem2DragAndDropOverlay, _extends({}, dragAndDropOverlayProps))]
100
+ }));
105
101
  });
106
102
  process.env.NODE_ENV !== "production" ? TreeItemContent.propTypes = {
107
103
  // ----------------------------- Warning --------------------------------
@@ -114,7 +110,7 @@ process.env.NODE_ENV !== "production" ? TreeItemContent.propTypes = {
114
110
  classes: PropTypes.object.isRequired,
115
111
  className: PropTypes.string,
116
112
  /**
117
- * The icon to display next to the tree item's label. Either a parent or end icon.
113
+ * The icon to display next to the Tree Item's label. Either a parent or end icon.
118
114
  */
119
115
  displayIcon: PropTypes.node,
120
116
  dragAndDropOverlayProps: PropTypes.shape({
@@ -122,11 +118,11 @@ process.env.NODE_ENV !== "production" ? TreeItemContent.propTypes = {
122
118
  style: PropTypes.object
123
119
  }),
124
120
  /**
125
- * The icon to display next to the tree item's label. Either an expansion or collapse icon.
121
+ * The icon to display next to the Tree Item's label. Either an expansion or collapse icon.
126
122
  */
127
123
  expansionIcon: PropTypes.node,
128
124
  /**
129
- * The icon to display next to the tree item's label.
125
+ * The icon to display next to the Tree Item's label.
130
126
  */
131
127
  icon: PropTypes.node,
132
128
  /**
@@ -134,7 +130,7 @@ process.env.NODE_ENV !== "production" ? TreeItemContent.propTypes = {
134
130
  */
135
131
  itemId: PropTypes.string.isRequired,
136
132
  /**
137
- * The tree item label.
133
+ * The Tree Item label.
138
134
  */
139
135
  label: PropTypes.node,
140
136
  labelInputProps: PropTypes.shape({
@@ -13,7 +13,7 @@ export interface TreeItemClasses {
13
13
  focused: string;
14
14
  /** State class applied to the element when disabled. */
15
15
  disabled: string;
16
- /** Styles applied to the tree item icon. */
16
+ /** Styles applied to the Tree Item icon. */
17
17
  iconContainer: string;
18
18
  /** Styles applied to the label element. */
19
19
  label: string;
@@ -43,7 +43,7 @@ export interface TreeItem2Slots extends TreeItem2IconSlots {
43
43
  labelInput?: React.ElementType;
44
44
  /**
45
45
  * The component that renders the overlay when an item reordering is ongoing.
46
- * Warning: This slot is only useful when using the `RichTreeViewPro` component.
46
+ * Warning: This slot is only useful when using the `<RichTreeViewPro />` component.
47
47
  * @default TreeItem2DragAndDropOverlay
48
48
  */
49
49
  dragAndDropOverlay?: React.ElementType;
@@ -26,7 +26,7 @@ const TreeItem2DragAndDropOverlayRoot = styled('div', {
26
26
  style: {
27
27
  marginLeft: 'calc(var(--TreeView-indentMultiplier) * var(--TreeView-itemDepth))',
28
28
  borderRadius: theme.shape.borderRadius,
29
- backgroundColor: alpha((theme.vars || theme).palette.primary.dark, 0.15)
29
+ backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.dark} / ${0.15})` : alpha(theme.palette.primary.dark, 0.15)
30
30
  }
31
31
  }, {
32
32
  props: {
@@ -34,9 +34,9 @@ const TreeItem2DragAndDropOverlayRoot = styled('div', {
34
34
  },
35
35
  style: _extends({
36
36
  marginLeft: 'calc(var(--TreeView-indentMultiplier) * var(--TreeView-itemDepth))',
37
- borderTop: `1px solid ${alpha((theme.vars || theme).palette.grey[900], 0.6)}`
37
+ borderTop: theme.vars ? `1px solid rgba(${theme.vars.palette.grey[900]} / ${0.6})` : `1px solid ${alpha(theme.palette.grey[900], 0.6)}`
38
38
  }, theme.applyStyles('dark', {
39
- borderTopColor: alpha((theme.vars || theme).palette.grey[100], 0.6)
39
+ borderTopColor: theme.vars ? `rgba(${theme.vars.palette.grey[100]} / ${0.6})` : alpha(theme.palette.grey[100], 0.6)
40
40
  }))
41
41
  }, {
42
42
  props: {
@@ -44,9 +44,9 @@ const TreeItem2DragAndDropOverlayRoot = styled('div', {
44
44
  },
45
45
  style: _extends({
46
46
  marginLeft: 'calc(var(--TreeView-indentMultiplier) * var(--TreeView-itemDepth))',
47
- borderBottom: `1px solid ${alpha((theme.vars || theme).palette.grey[900], 0.6)}`
47
+ borderBottom: theme.vars ? `1px solid rgba(${theme.vars.palette.grey[900]} / ${0.6})` : `1px solid ${alpha(theme.palette.grey[900], 0.6)}`
48
48
  }, theme.applyStyles('dark', {
49
- borderBottomColor: alpha((theme.vars || theme).palette.grey[100], 0.6)
49
+ borderBottomColor: theme.vars ? `rgba(${theme.vars.palette.grey[100]} / ${0.6})` : alpha(theme.palette.grey[100], 0.6)
50
50
  }))
51
51
  }, {
52
52
  props: {
@@ -54,9 +54,9 @@ const TreeItem2DragAndDropOverlayRoot = styled('div', {
54
54
  },
55
55
  style: _extends({
56
56
  marginLeft: 'calc(var(--TreeView-indentMultiplier) * calc(var(--TreeView-itemDepth) - 1))',
57
- borderBottom: `1px solid ${alpha((theme.vars || theme).palette.grey[900], 0.6)}`
57
+ borderBottom: theme.vars ? `1px solid rgba(${theme.vars.palette.grey[900]} / ${0.6})` : `1px solid ${alpha(theme.palette.grey[900], 0.6)}`
58
58
  }, theme.applyStyles('dark', {
59
- borderBottomColor: alpha((theme.vars || theme).palette.grey[900], 0.6)
59
+ borderBottomColor: theme.vars ? `rgba(${theme.vars.palette.grey[100]} / ${0.6})` : alpha(theme.palette.grey[100], 0.6)
60
60
  }))
61
61
  }]
62
62
  }));
@@ -15,7 +15,7 @@ export interface TreeItem2IconSlots {
15
15
  */
16
16
  endIcon?: React.ElementType;
17
17
  /**
18
- * The icon to display next to the tree item's label.
18
+ * The icon to display next to the Tree Item's label.
19
19
  */
20
20
  icon?: React.ElementType;
21
21
  }
@@ -4,7 +4,7 @@ type TreeViewComponent = (<Multiple extends boolean | undefined = undefined>(pro
4
4
  propTypes?: any;
5
5
  };
6
6
  /**
7
- * This component has been deprecated in favor of the new `SimpleTreeView` component.
7
+ * This component has been deprecated in favor of the new Simple Tree View component.
8
8
  * You can have a look at how to migrate to the new component in the v7 [migration guide](https://mui.com/x/migration/migration-tree-view-v6/#use-simpletreeview-instead-of-treeview)
9
9
  *
10
10
  * Demos:
@@ -32,7 +32,7 @@ const warn = () => {
32
32
  };
33
33
 
34
34
  /**
35
- * This component has been deprecated in favor of the new `SimpleTreeView` component.
35
+ * This component has been deprecated in favor of the new Simple Tree View component.
36
36
  * You can have a look at how to migrate to the new component in the v7 [migration guide](https://mui.com/x/migration/migration-tree-view-v6/#use-simpletreeview-instead-of-treeview)
37
37
  *
38
38
  * Demos:
@@ -82,7 +82,7 @@ process.env.NODE_ENV !== "production" ? TreeView.propTypes = {
82
82
  })
83
83
  }),
84
84
  /**
85
- * If `true`, the tree view renders a checkbox at the left of its label that allows selecting it.
85
+ * If `true`, the Tree View renders a checkbox at the left of its label that allows selecting it.
86
86
  * @default false
87
87
  */
88
88
  checkboxSelection: PropTypes.bool,
@@ -152,39 +152,39 @@ process.env.NODE_ENV !== "production" ? TreeView.propTypes = {
152
152
  */
153
153
  multiSelect: PropTypes.bool,
154
154
  /**
155
- * Callback fired when tree items are expanded/collapsed.
155
+ * Callback fired when Tree Items are expanded/collapsed.
156
156
  * @param {React.SyntheticEvent} event The DOM event that triggered the change.
157
157
  * @param {array} itemIds The ids of the expanded items.
158
158
  */
159
159
  onExpandedItemsChange: PropTypes.func,
160
160
  /**
161
- * Callback fired when the `content` slot of a given tree item is clicked.
161
+ * Callback fired when the `content` slot of a given Tree Item is clicked.
162
162
  * @param {React.MouseEvent} event The DOM event that triggered the change.
163
163
  * @param {string} itemId The id of the focused item.
164
164
  */
165
165
  onItemClick: PropTypes.func,
166
166
  /**
167
- * Callback fired when a tree item is expanded or collapsed.
167
+ * Callback fired when a Tree Item is expanded or collapsed.
168
168
  * @param {React.SyntheticEvent} event The DOM event that triggered the change.
169
169
  * @param {array} itemId The itemId of the modified item.
170
170
  * @param {array} isExpanded `true` if the item has just been expanded, `false` if it has just been collapsed.
171
171
  */
172
172
  onItemExpansionToggle: PropTypes.func,
173
173
  /**
174
- * Callback fired when a given tree item is focused.
174
+ * Callback fired when a given Tree Item is focused.
175
175
  * @param {React.SyntheticEvent | null} event The DOM event that triggered the change. **Warning**: This is a generic event not a focus event.
176
176
  * @param {string} itemId The id of the focused item.
177
177
  */
178
178
  onItemFocus: PropTypes.func,
179
179
  /**
180
- * Callback fired when a tree item is selected or deselected.
180
+ * Callback fired when a Tree Item is selected or deselected.
181
181
  * @param {React.SyntheticEvent} event The DOM event that triggered the change.
182
182
  * @param {array} itemId The itemId of the modified item.
183
183
  * @param {array} isSelected `true` if the item has just been selected, `false` if it has just been deselected.
184
184
  */
185
185
  onItemSelectionToggle: PropTypes.func,
186
186
  /**
187
- * Callback fired when tree items are selected/deselected.
187
+ * Callback fired when Tree Items are selected/deselected.
188
188
  * @param {React.SyntheticEvent} event The DOM event that triggered the change.
189
189
  * @param {string[] | string} itemIds The ids of the selected items.
190
190
  * When `multiSelect` is `true`, this is an array of strings; when false (default) a string.
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-tree-view v7.19.0
2
+ * @mui/x-tree-view v7.21.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -0,0 +1,35 @@
1
+ import * as React from 'react';
2
+ import { SlotComponentProps } from '@mui/utils';
3
+ import { TreeItem, TreeItemProps } from '../../TreeItem';
4
+ import { TreeItem2Props } from '../../TreeItem2';
5
+ import { TreeViewItemId } from '../../models';
6
+ import { TreeViewItemToRenderProps } from '../plugins/useTreeViewItems';
7
+ interface RichTreeViewItemsOwnerState {
8
+ itemId: TreeViewItemId;
9
+ label: string;
10
+ }
11
+ export interface RichTreeViewItemsSlots {
12
+ /**
13
+ * Custom component for the item.
14
+ * @default TreeItem.
15
+ */
16
+ item?: React.JSXElementConstructor<TreeItemProps> | React.JSXElementConstructor<TreeItem2Props>;
17
+ }
18
+ export interface RichTreeViewItemsSlotProps {
19
+ item?: SlotComponentProps<typeof TreeItem, {}, RichTreeViewItemsOwnerState>;
20
+ }
21
+ export interface RichTreeViewItemsProps {
22
+ itemsToRender: TreeViewItemToRenderProps[];
23
+ /**
24
+ * Overridable component slots.
25
+ * @default {}
26
+ */
27
+ slots?: RichTreeViewItemsSlots;
28
+ /**
29
+ * The props used for each component slot.
30
+ * @default {}
31
+ */
32
+ slotProps?: RichTreeViewItemsSlotProps;
33
+ }
34
+ export declare function RichTreeViewItems(props: RichTreeViewItemsProps): React.JSX.Element;
35
+ export {};
@@ -0,0 +1,56 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["ownerState"];
4
+ import * as React from 'react';
5
+ import useSlotProps from '@mui/utils/useSlotProps';
6
+ import { TreeItem } from "../../TreeItem/index.js";
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ function WrappedTreeItem({
9
+ slots,
10
+ slotProps,
11
+ label,
12
+ id,
13
+ itemId,
14
+ itemsToRender
15
+ }) {
16
+ const Item = slots?.item ?? TreeItem;
17
+ const _useSlotProps = useSlotProps({
18
+ elementType: Item,
19
+ externalSlotProps: slotProps?.item,
20
+ additionalProps: {
21
+ itemId,
22
+ id,
23
+ label
24
+ },
25
+ ownerState: {
26
+ itemId,
27
+ label
28
+ }
29
+ }),
30
+ itemProps = _objectWithoutPropertiesLoose(_useSlotProps, _excluded);
31
+ const children = React.useMemo(() => itemsToRender ? /*#__PURE__*/_jsx(RichTreeViewItems, {
32
+ itemsToRender: itemsToRender,
33
+ slots: slots,
34
+ slotProps: slotProps
35
+ }) : null, [itemsToRender, slots, slotProps]);
36
+ return /*#__PURE__*/_jsx(Item, _extends({}, itemProps, {
37
+ children: children
38
+ }));
39
+ }
40
+ export function RichTreeViewItems(props) {
41
+ const {
42
+ itemsToRender,
43
+ slots,
44
+ slotProps
45
+ } = props;
46
+ return /*#__PURE__*/_jsx(React.Fragment, {
47
+ children: itemsToRender.map(item => /*#__PURE__*/_jsx(WrappedTreeItem, {
48
+ slots: slots,
49
+ slotProps: slotProps,
50
+ label: item.label,
51
+ id: item.id,
52
+ itemId: item.itemId,
53
+ itemsToRender: item.children
54
+ }, item.itemId))
55
+ });
56
+ }
@@ -2,7 +2,7 @@ import { UseTreeViewIdParameters } from './useTreeViewId';
2
2
  import { ConvertPluginsIntoSignatures } from '../models';
3
3
  /**
4
4
  * Internal plugins that create the tools used by the other plugins.
5
- * These plugins are used by the tree view components.
5
+ * These plugins are used by the Tree View components.
6
6
  */
7
7
  export declare const TREE_VIEW_CORE_PLUGINS: readonly [import("..").TreeViewPlugin<import("./useTreeViewInstanceEvents").UseTreeViewInstanceEventsSignature>, import("..").TreeViewPlugin<import("./useTreeViewOptionalPlugins").UseTreeViewOptionalPluginsSignature>, import("..").TreeViewPlugin<import("./useTreeViewId").UseTreeViewIdSignature>];
8
8
  export type TreeViewCorePluginSignatures = ConvertPluginsIntoSignatures<typeof TREE_VIEW_CORE_PLUGINS>;
@@ -3,6 +3,6 @@ import { useTreeViewOptionalPlugins } from "./useTreeViewOptionalPlugins/index.j
3
3
  import { useTreeViewId } from "./useTreeViewId/index.js";
4
4
  /**
5
5
  * Internal plugins that create the tools used by the other plugins.
6
- * These plugins are used by the tree view components.
6
+ * These plugins are used by the Tree View components.
7
7
  */
8
8
  export const TREE_VIEW_CORE_PLUGINS = [useTreeViewInstanceEvents, useTreeViewOptionalPlugins, useTreeViewId];
@@ -6,10 +6,9 @@ export const useTreeViewId = ({
6
6
  state,
7
7
  setState
8
8
  }) => {
9
- const treeId = state.id.treeId;
10
9
  React.useEffect(() => {
11
10
  setState(prevState => {
12
- if (prevState.id.treeId === params.id) {
11
+ if (prevState.id.treeId === params.id && prevState.id.treeId !== undefined) {
13
12
  return prevState;
14
13
  }
15
14
  return _extends({}, prevState, {
@@ -19,6 +18,7 @@ export const useTreeViewId = ({
19
18
  });
20
19
  });
21
20
  }, [setState, params.id]);
21
+ const treeId = params.id ?? state.id.treeId;
22
22
  return {
23
23
  getRootProps: () => ({
24
24
  id: treeId
@@ -35,6 +35,6 @@ useTreeViewId.getInitialState = ({
35
35
  id
36
36
  }) => ({
37
37
  id: {
38
- treeId: id ?? createTreeViewDefaultId()
38
+ treeId: id ?? undefined
39
39
  }
40
40
  });
@@ -9,7 +9,7 @@ export interface UseTreeViewIdParameters {
9
9
  export type UseTreeViewIdDefaultizedParameters = UseTreeViewIdParameters;
10
10
  export interface UseTreeViewIdState {
11
11
  id: {
12
- treeId: string;
12
+ treeId: string | undefined;
13
13
  };
14
14
  }
15
15
  interface UseTreeViewIdContextValue {