@mui/x-tree-view 7.20.0 → 7.22.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 (78) hide show
  1. package/CHANGELOG.md +200 -31
  2. package/RichTreeView/RichTreeView.js +8 -8
  3. package/SimpleTreeView/SimpleTreeView.js +8 -8
  4. package/TreeItem/TreeItem.js +15 -14
  5. package/TreeItem/TreeItem.types.d.ts +8 -9
  6. package/TreeItem/TreeItemContent.d.ts +5 -5
  7. package/TreeItem/TreeItemContent.js +4 -4
  8. package/TreeItem/treeItemClasses.d.ts +1 -1
  9. package/TreeItem/useTreeItemState.d.ts +2 -2
  10. package/TreeItem2/TreeItem2.types.d.ts +4 -4
  11. package/TreeItem2DragAndDropOverlay/TreeItem2DragAndDropOverlay.js +7 -7
  12. package/TreeItem2Icon/TreeItem2Icon.types.d.ts +1 -1
  13. package/TreeItem2LabelInput/TreeItem2LabelInput.types.d.ts +3 -3
  14. package/TreeView/TreeView.d.ts +1 -1
  15. package/TreeView/TreeView.js +8 -8
  16. package/index.js +1 -1
  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 -1
  24. package/internals/models/index.d.ts +0 -1
  25. package/internals/models/index.js +1 -2
  26. package/internals/models/treeView.d.ts +2 -2
  27. package/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.types.d.ts +2 -2
  28. package/internals/plugins/useTreeViewFocus/useTreeViewFocus.types.d.ts +1 -1
  29. package/internals/plugins/useTreeViewIcons/useTreeViewIcons.types.d.ts +1 -1
  30. package/internals/plugins/useTreeViewItems/useTreeViewItems.types.d.ts +2 -2
  31. package/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.js +1 -1
  32. package/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js +3 -3
  33. package/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.types.d.ts +4 -4
  34. package/internals/plugins/useTreeViewLabel/useTreeViewLabel.js +1 -1
  35. package/internals/plugins/useTreeViewLabel/useTreeViewLabel.types.d.ts +1 -1
  36. package/internals/plugins/useTreeViewSelection/useTreeViewSelection.types.d.ts +3 -3
  37. package/models/events.d.ts +4 -0
  38. package/models/index.d.ts +1 -0
  39. package/models/index.js +1 -0
  40. package/modern/RichTreeView/RichTreeView.js +8 -8
  41. package/modern/SimpleTreeView/SimpleTreeView.js +8 -8
  42. package/modern/TreeItem/TreeItem.js +15 -14
  43. package/modern/TreeItem/TreeItemContent.js +4 -4
  44. package/modern/TreeItem2DragAndDropOverlay/TreeItem2DragAndDropOverlay.js +7 -7
  45. package/modern/TreeView/TreeView.js +8 -8
  46. package/modern/index.js +1 -1
  47. package/modern/internals/corePlugins/corePlugins.js +1 -1
  48. package/modern/internals/corePlugins/useTreeViewId/useTreeViewId.js +3 -3
  49. package/modern/internals/corePlugins/useTreeViewId/useTreeViewId.utils.js +1 -1
  50. package/modern/internals/models/index.js +1 -2
  51. package/modern/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.js +1 -1
  52. package/modern/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js +3 -3
  53. package/modern/internals/plugins/useTreeViewLabel/useTreeViewLabel.js +1 -1
  54. package/modern/models/index.js +1 -0
  55. package/modern/useTreeItem2/useTreeItem2.js +11 -11
  56. package/node/RichTreeView/RichTreeView.js +8 -8
  57. package/node/SimpleTreeView/SimpleTreeView.js +8 -8
  58. package/node/TreeItem/TreeItem.js +15 -14
  59. package/node/TreeItem/TreeItemContent.js +4 -4
  60. package/node/TreeItem2DragAndDropOverlay/TreeItem2DragAndDropOverlay.js +7 -7
  61. package/node/TreeView/TreeView.js +8 -8
  62. package/node/index.js +1 -1
  63. package/node/internals/corePlugins/corePlugins.js +1 -1
  64. package/node/internals/corePlugins/useTreeViewId/useTreeViewId.js +3 -3
  65. package/node/internals/corePlugins/useTreeViewId/useTreeViewId.utils.js +1 -1
  66. package/node/internals/models/index.js +0 -11
  67. package/node/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.js +1 -1
  68. package/node/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js +3 -3
  69. package/node/internals/plugins/useTreeViewLabel/useTreeViewLabel.js +1 -1
  70. package/node/models/index.js +11 -0
  71. package/node/useTreeItem2/useTreeItem2.js +11 -11
  72. package/package.json +2 -2
  73. package/useTreeItem2/useTreeItem2.js +11 -11
  74. package/useTreeItem2/useTreeItem2.types.d.ts +11 -11
  75. package/internals/models/MuiCancellableEvent.d.ts +0 -4
  76. /package/{internals/models/MuiCancellableEvent.js → models/events.js} +0 -0
  77. /package/modern/{internals/models/MuiCancellableEvent.js → models/events.js} +0 -0
  78. /package/node/{internals/models/MuiCancellableEvent.js → models/events.js} +0 -0
@@ -60,7 +60,7 @@ const SimpleTreeView = exports.SimpleTreeView = /*#__PURE__*/React.forwardRef(fu
60
60
  const ownerState = props;
61
61
  if (process.env.NODE_ENV !== 'production') {
62
62
  if (props.items != null) {
63
- (0, _warning.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/.']);
63
+ (0, _warning.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/.']);
64
64
  }
65
65
  }
66
66
  const {
@@ -111,7 +111,7 @@ process.env.NODE_ENV !== "production" ? SimpleTreeView.propTypes = {
111
111
  })
112
112
  }),
113
113
  /**
114
- * If `true`, the tree view renders a checkbox at the left of its label that allows selecting it.
114
+ * If `true`, the Tree View renders a checkbox at the left of its label that allows selecting it.
115
115
  * @default false
116
116
  */
117
117
  checkboxSelection: _propTypes.default.bool,
@@ -181,39 +181,39 @@ process.env.NODE_ENV !== "production" ? SimpleTreeView.propTypes = {
181
181
  */
182
182
  multiSelect: _propTypes.default.bool,
183
183
  /**
184
- * Callback fired when tree items are expanded/collapsed.
184
+ * Callback fired when Tree Items are expanded/collapsed.
185
185
  * @param {React.SyntheticEvent} event The DOM event that triggered the change.
186
186
  * @param {array} itemIds The ids of the expanded items.
187
187
  */
188
188
  onExpandedItemsChange: _propTypes.default.func,
189
189
  /**
190
- * Callback fired when the `content` slot of a given tree item is clicked.
190
+ * Callback fired when the `content` slot of a given Tree Item is clicked.
191
191
  * @param {React.MouseEvent} event The DOM event that triggered the change.
192
192
  * @param {string} itemId The id of the focused item.
193
193
  */
194
194
  onItemClick: _propTypes.default.func,
195
195
  /**
196
- * Callback fired when a tree item is expanded or collapsed.
196
+ * Callback fired when a Tree Item is expanded or collapsed.
197
197
  * @param {React.SyntheticEvent} event The DOM event that triggered the change.
198
198
  * @param {array} itemId The itemId of the modified item.
199
199
  * @param {array} isExpanded `true` if the item has just been expanded, `false` if it has just been collapsed.
200
200
  */
201
201
  onItemExpansionToggle: _propTypes.default.func,
202
202
  /**
203
- * Callback fired when a given tree item is focused.
203
+ * Callback fired when a given Tree Item is focused.
204
204
  * @param {React.SyntheticEvent | null} event The DOM event that triggered the change. **Warning**: This is a generic event not a focus event.
205
205
  * @param {string} itemId The id of the focused item.
206
206
  */
207
207
  onItemFocus: _propTypes.default.func,
208
208
  /**
209
- * Callback fired when a tree item is selected or deselected.
209
+ * Callback fired when a Tree Item is selected or deselected.
210
210
  * @param {React.SyntheticEvent} event The DOM event that triggered the change.
211
211
  * @param {array} itemId The itemId of the modified item.
212
212
  * @param {array} isSelected `true` if the item has just been selected, `false` if it has just been deselected.
213
213
  */
214
214
  onItemSelectionToggle: _propTypes.default.func,
215
215
  /**
216
- * Callback fired when tree items are selected/deselected.
216
+ * Callback fired when Tree Items are selected/deselected.
217
217
  * @param {React.SyntheticEvent} event The DOM event that triggered the change.
218
218
  * @param {string[] | string} itemIds The ids of the selected items.
219
219
  * When `multiSelect` is `true`, this is an array of strings; when false (default) a string.
@@ -189,7 +189,7 @@ const TreeItem = exports.TreeItem = /*#__PURE__*/React.forwardRef(function TreeI
189
189
  indentationAtItemLevel
190
190
  },
191
191
  selection: {
192
- multiSelect
192
+ disableSelection
193
193
  },
194
194
  expansion: {
195
195
  expansionTrigger
@@ -325,17 +325,18 @@ const TreeItem = exports.TreeItem = /*#__PURE__*/React.forwardRef(function TreeI
325
325
  }),
326
326
  iconProps = (0, _objectWithoutPropertiesLoose2.default)(_useSlotProps3, _excluded4);
327
327
  const icon = Icon ? /*#__PURE__*/(0, _jsxRuntime.jsx)(Icon, (0, _extends2.default)({}, iconProps)) : null;
328
+
329
+ // https://www.w3.org/WAI/ARIA/apg/patterns/treeview/
328
330
  let ariaSelected;
329
- if (multiSelect) {
330
- ariaSelected = selected;
331
- } else if (selected) {
332
- /* single-selection trees unset aria-selected on un-selected items.
333
- *
334
- * If the tree does not support multiple selection, aria-selected
335
- * is set to true for the selected item and it is not present on any other item in the tree.
336
- * Source: https://www.w3.org/WAI/ARIA/apg/patterns/treeview/
337
- */
331
+ if (selected) {
332
+ // - each selected node has aria-selected set to true.
338
333
  ariaSelected = true;
334
+ } else if (disableSelection || disabled) {
335
+ // - if the tree contains nodes that are not selectable, aria-selected is not present on those nodes.
336
+ ariaSelected = undefined;
337
+ } else {
338
+ // - all nodes that are selectable but not selected have aria-selected set to false.
339
+ ariaSelected = false;
339
340
  }
340
341
  function handleFocus(event) {
341
342
  const canBeFocused = !disabled || disabledItemsFocusable;
@@ -346,7 +347,7 @@ const TreeItem = exports.TreeItem = /*#__PURE__*/React.forwardRef(function TreeI
346
347
  function handleBlur(event) {
347
348
  onBlur?.(event);
348
349
  if (editing ||
349
- // 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
350
+ // 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
350
351
  // 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
351
352
  event.relatedTarget && (0, _tree.isTargetInDescendants)(event.relatedTarget, rootRefObject.current) && (event.target && event.target?.dataset?.element === 'labelInput' && (0, _tree.isTargetInDescendants)(event.target, rootRefObject.current) || event.relatedTarget?.dataset?.element === 'labelInput')) {
352
353
  return;
@@ -459,13 +460,13 @@ process.env.NODE_ENV !== "production" ? TreeItem.propTypes = {
459
460
  className: _propTypes.default.string,
460
461
  /**
461
462
  * The component used to render the content of the item.
462
- * @deprecated Consider using the `TreeItem2` component or the `useTreeItem2` hook instead. For more detail, see https://mui.com/x/react-tree-view/tree-item-customization/.
463
+ * @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/.
463
464
  * @default TreeItemContent
464
465
  */
465
466
  ContentComponent: _elementTypeAcceptingRef.default,
466
467
  /**
467
468
  * Props applied to ContentComponent.
468
- * @deprecated Consider using the `TreeItem2` component or the `useTreeItem2` hook instead. For more detail, see https://mui.com/x/react-tree-view/tree-item-customization/.
469
+ * @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/.
469
470
  */
470
471
  ContentProps: _propTypes.default.object,
471
472
  /**
@@ -478,7 +479,7 @@ process.env.NODE_ENV !== "production" ? TreeItem.propTypes = {
478
479
  */
479
480
  itemId: _propTypes.default.string.isRequired,
480
481
  /**
481
- * The tree item label.
482
+ * The Tree Item label.
482
483
  */
483
484
  label: _propTypes.default.node,
484
485
  /**
@@ -118,7 +118,7 @@ process.env.NODE_ENV !== "production" ? TreeItemContent.propTypes = {
118
118
  classes: _propTypes.default.object.isRequired,
119
119
  className: _propTypes.default.string,
120
120
  /**
121
- * The icon to display next to the tree item's label. Either a parent or end icon.
121
+ * The icon to display next to the Tree Item's label. Either a parent or end icon.
122
122
  */
123
123
  displayIcon: _propTypes.default.node,
124
124
  dragAndDropOverlayProps: _propTypes.default.shape({
@@ -126,11 +126,11 @@ process.env.NODE_ENV !== "production" ? TreeItemContent.propTypes = {
126
126
  style: _propTypes.default.object
127
127
  }),
128
128
  /**
129
- * The icon to display next to the tree item's label. Either an expansion or collapse icon.
129
+ * The icon to display next to the Tree Item's label. Either an expansion or collapse icon.
130
130
  */
131
131
  expansionIcon: _propTypes.default.node,
132
132
  /**
133
- * The icon to display next to the tree item's label.
133
+ * The icon to display next to the Tree Item's label.
134
134
  */
135
135
  icon: _propTypes.default.node,
136
136
  /**
@@ -138,7 +138,7 @@ process.env.NODE_ENV !== "production" ? TreeItemContent.propTypes = {
138
138
  */
139
139
  itemId: _propTypes.default.string.isRequired,
140
140
  /**
141
- * The tree item label.
141
+ * The Tree Item label.
142
142
  */
143
143
  label: _propTypes.default.node,
144
144
  labelInputProps: _propTypes.default.shape({
@@ -34,7 +34,7 @@ const TreeItem2DragAndDropOverlayRoot = (0, _zeroStyled.styled)('div', {
34
34
  style: {
35
35
  marginLeft: 'calc(var(--TreeView-indentMultiplier) * var(--TreeView-itemDepth))',
36
36
  borderRadius: theme.shape.borderRadius,
37
- backgroundColor: (0, _styles.alpha)((theme.vars || theme).palette.primary.dark, 0.15)
37
+ backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.dark} / ${0.15})` : (0, _styles.alpha)(theme.palette.primary.dark, 0.15)
38
38
  }
39
39
  }, {
40
40
  props: {
@@ -42,9 +42,9 @@ const TreeItem2DragAndDropOverlayRoot = (0, _zeroStyled.styled)('div', {
42
42
  },
43
43
  style: (0, _extends2.default)({
44
44
  marginLeft: 'calc(var(--TreeView-indentMultiplier) * var(--TreeView-itemDepth))',
45
- borderTop: `1px solid ${(0, _styles.alpha)((theme.vars || theme).palette.grey[900], 0.6)}`
45
+ borderTop: theme.vars ? `1px solid rgba(${theme.vars.palette.grey[900]} / ${0.6})` : `1px solid ${(0, _styles.alpha)(theme.palette.grey[900], 0.6)}`
46
46
  }, theme.applyStyles('dark', {
47
- borderTopColor: (0, _styles.alpha)((theme.vars || theme).palette.grey[100], 0.6)
47
+ borderTopColor: theme.vars ? `rgba(${theme.vars.palette.grey[100]} / ${0.6})` : (0, _styles.alpha)(theme.palette.grey[100], 0.6)
48
48
  }))
49
49
  }, {
50
50
  props: {
@@ -52,9 +52,9 @@ const TreeItem2DragAndDropOverlayRoot = (0, _zeroStyled.styled)('div', {
52
52
  },
53
53
  style: (0, _extends2.default)({
54
54
  marginLeft: 'calc(var(--TreeView-indentMultiplier) * var(--TreeView-itemDepth))',
55
- borderBottom: `1px solid ${(0, _styles.alpha)((theme.vars || theme).palette.grey[900], 0.6)}`
55
+ borderBottom: theme.vars ? `1px solid rgba(${theme.vars.palette.grey[900]} / ${0.6})` : `1px solid ${(0, _styles.alpha)(theme.palette.grey[900], 0.6)}`
56
56
  }, theme.applyStyles('dark', {
57
- borderBottomColor: (0, _styles.alpha)((theme.vars || theme).palette.grey[100], 0.6)
57
+ borderBottomColor: theme.vars ? `rgba(${theme.vars.palette.grey[100]} / ${0.6})` : (0, _styles.alpha)(theme.palette.grey[100], 0.6)
58
58
  }))
59
59
  }, {
60
60
  props: {
@@ -62,9 +62,9 @@ const TreeItem2DragAndDropOverlayRoot = (0, _zeroStyled.styled)('div', {
62
62
  },
63
63
  style: (0, _extends2.default)({
64
64
  marginLeft: 'calc(var(--TreeView-indentMultiplier) * calc(var(--TreeView-itemDepth) - 1))',
65
- borderBottom: `1px solid ${(0, _styles.alpha)((theme.vars || theme).palette.grey[900], 0.6)}`
65
+ borderBottom: theme.vars ? `1px solid rgba(${theme.vars.palette.grey[900]} / ${0.6})` : `1px solid ${(0, _styles.alpha)(theme.palette.grey[900], 0.6)}`
66
66
  }, theme.applyStyles('dark', {
67
- borderBottomColor: (0, _styles.alpha)((theme.vars || theme).palette.grey[900], 0.6)
67
+ borderBottomColor: theme.vars ? `rgba(${theme.vars.palette.grey[100]} / ${0.6})` : (0, _styles.alpha)(theme.palette.grey[100], 0.6)
68
68
  }))
69
69
  }]
70
70
  }));
@@ -39,7 +39,7 @@ const warn = () => {
39
39
  };
40
40
 
41
41
  /**
42
- * This component has been deprecated in favor of the new `SimpleTreeView` component.
42
+ * This component has been deprecated in favor of the new Simple Tree View component.
43
43
  * 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)
44
44
  *
45
45
  * Demos:
@@ -89,7 +89,7 @@ process.env.NODE_ENV !== "production" ? TreeView.propTypes = {
89
89
  })
90
90
  }),
91
91
  /**
92
- * If `true`, the tree view renders a checkbox at the left of its label that allows selecting it.
92
+ * If `true`, the Tree View renders a checkbox at the left of its label that allows selecting it.
93
93
  * @default false
94
94
  */
95
95
  checkboxSelection: _propTypes.default.bool,
@@ -159,39 +159,39 @@ process.env.NODE_ENV !== "production" ? TreeView.propTypes = {
159
159
  */
160
160
  multiSelect: _propTypes.default.bool,
161
161
  /**
162
- * Callback fired when tree items are expanded/collapsed.
162
+ * Callback fired when Tree Items are expanded/collapsed.
163
163
  * @param {React.SyntheticEvent} event The DOM event that triggered the change.
164
164
  * @param {array} itemIds The ids of the expanded items.
165
165
  */
166
166
  onExpandedItemsChange: _propTypes.default.func,
167
167
  /**
168
- * Callback fired when the `content` slot of a given tree item is clicked.
168
+ * Callback fired when the `content` slot of a given Tree Item is clicked.
169
169
  * @param {React.MouseEvent} event The DOM event that triggered the change.
170
170
  * @param {string} itemId The id of the focused item.
171
171
  */
172
172
  onItemClick: _propTypes.default.func,
173
173
  /**
174
- * Callback fired when a tree item is expanded or collapsed.
174
+ * Callback fired when a Tree Item is expanded or collapsed.
175
175
  * @param {React.SyntheticEvent} event The DOM event that triggered the change.
176
176
  * @param {array} itemId The itemId of the modified item.
177
177
  * @param {array} isExpanded `true` if the item has just been expanded, `false` if it has just been collapsed.
178
178
  */
179
179
  onItemExpansionToggle: _propTypes.default.func,
180
180
  /**
181
- * Callback fired when a given tree item is focused.
181
+ * Callback fired when a given Tree Item is focused.
182
182
  * @param {React.SyntheticEvent | null} event The DOM event that triggered the change. **Warning**: This is a generic event not a focus event.
183
183
  * @param {string} itemId The id of the focused item.
184
184
  */
185
185
  onItemFocus: _propTypes.default.func,
186
186
  /**
187
- * Callback fired when a tree item is selected or deselected.
187
+ * Callback fired when a Tree Item is selected or deselected.
188
188
  * @param {React.SyntheticEvent} event The DOM event that triggered the change.
189
189
  * @param {array} itemId The itemId of the modified item.
190
190
  * @param {array} isSelected `true` if the item has just been selected, `false` if it has just been deselected.
191
191
  */
192
192
  onItemSelectionToggle: _propTypes.default.func,
193
193
  /**
194
- * Callback fired when tree items are selected/deselected.
194
+ * Callback fired when Tree Items are selected/deselected.
195
195
  * @param {React.SyntheticEvent} event The DOM event that triggered the change.
196
196
  * @param {string[] | string} itemIds The ids of the selected items.
197
197
  * When `multiSelect` is `true`, this is an array of strings; when false (default) a string.
package/node/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-tree-view v7.20.0
2
+ * @mui/x-tree-view v7.22.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -9,6 +9,6 @@ var _useTreeViewOptionalPlugins = require("./useTreeViewOptionalPlugins");
9
9
  var _useTreeViewId = require("./useTreeViewId");
10
10
  /**
11
11
  * Internal plugins that create the tools used by the other plugins.
12
- * These plugins are used by the tree view components.
12
+ * These plugins are used by the Tree View components.
13
13
  */
14
14
  const TREE_VIEW_CORE_PLUGINS = exports.TREE_VIEW_CORE_PLUGINS = [_useTreeViewInstanceEvents.useTreeViewInstanceEvents, _useTreeViewOptionalPlugins.useTreeViewOptionalPlugins, _useTreeViewId.useTreeViewId];
@@ -14,10 +14,9 @@ const useTreeViewId = ({
14
14
  state,
15
15
  setState
16
16
  }) => {
17
- const treeId = state.id.treeId;
18
17
  React.useEffect(() => {
19
18
  setState(prevState => {
20
- if (prevState.id.treeId === params.id) {
19
+ if (prevState.id.treeId === params.id && prevState.id.treeId !== undefined) {
21
20
  return prevState;
22
21
  }
23
22
  return (0, _extends2.default)({}, prevState, {
@@ -27,6 +26,7 @@ const useTreeViewId = ({
27
26
  });
28
27
  });
29
28
  }, [setState, params.id]);
29
+ const treeId = params.id ?? state.id.treeId;
30
30
  return {
31
31
  getRootProps: () => ({
32
32
  id: treeId
@@ -44,6 +44,6 @@ useTreeViewId.getInitialState = ({
44
44
  id
45
45
  }) => ({
46
46
  id: {
47
- treeId: id ?? (0, _useTreeViewId.createTreeViewDefaultId)()
47
+ treeId: id ?? undefined
48
48
  }
49
49
  });
@@ -11,7 +11,7 @@ const createTreeViewDefaultId = () => {
11
11
  };
12
12
 
13
13
  /**
14
- * Generate the id attribute (i.e.: the `id` attribute passed to the DOM element) of a tree item.
14
+ * Generate the id attribute (i.e.: the `id` attribute passed to the DOM element) of a Tree Item.
15
15
  * If the user explicitly defined an id attribute, it will be returned.
16
16
  * Otherwise, the method creates a unique id for the item based on the Tree View id attribute and the item `itemId`
17
17
  * @param {object} params The parameters to determine the id attribute of the item.
@@ -46,15 +46,4 @@ Object.keys(_treeView).forEach(function (key) {
46
46
  return _treeView[key];
47
47
  }
48
48
  });
49
- });
50
- var _MuiCancellableEvent = require("./MuiCancellableEvent");
51
- Object.keys(_MuiCancellableEvent).forEach(function (key) {
52
- if (key === "default" || key === "__esModule") return;
53
- if (key in exports && exports[key] === _MuiCancellableEvent[key]) return;
54
- Object.defineProperty(exports, key, {
55
- enumerable: true,
56
- get: function () {
57
- return _MuiCancellableEvent[key];
58
- }
59
- });
60
49
  });
@@ -33,7 +33,7 @@ const useTreeViewJSXItems = ({
33
33
  itemMetaMap: (0, _extends2.default)({}, prevState.items.itemMetaMap, {
34
34
  [item.id]: item
35
35
  }),
36
- // For `SimpleTreeView`, we don't have a proper `item` object, so we create a very basic one.
36
+ // For Simple Tree View, we don't have a proper `item` object, so we create a very basic one.
37
37
  itemMap: (0, _extends2.default)({}, prevState.items.itemMap, {
38
38
  [item.id]: {
39
39
  id: item.id,
@@ -12,7 +12,7 @@ var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallb
12
12
  var _tree = require("../../utils/tree");
13
13
  var _plugins = require("../../utils/plugins");
14
14
  var _useTreeViewLabel = require("../useTreeViewLabel");
15
- function isPrintableCharacter(string) {
15
+ function isPrintableKey(string) {
16
16
  return !!string && string.length === 1 && !!string.match(/\S/);
17
17
  }
18
18
  const useTreeViewKeyboardNavigation = ({
@@ -235,7 +235,7 @@ const useTreeViewKeyboardNavigation = ({
235
235
 
236
236
  // Multi select behavior when pressing Ctrl + a
237
237
  // Selects all the items
238
- case key === 'a' && ctrlPressed && params.multiSelect && !params.disableSelection:
238
+ case String.fromCharCode(event.keyCode) === 'A' && ctrlPressed && params.multiSelect && !params.disableSelection:
239
239
  {
240
240
  instance.selectAllNavigableItems(event);
241
241
  event.preventDefault();
@@ -244,7 +244,7 @@ const useTreeViewKeyboardNavigation = ({
244
244
 
245
245
  // Type-ahead
246
246
  // TODO: Support typing multiple characters
247
- case !ctrlPressed && !event.shiftKey && isPrintableCharacter(key):
247
+ case !ctrlPressed && !event.shiftKey && isPrintableKey(key):
248
248
  {
249
249
  const matchingItem = getFirstMatchingItem(itemId, key);
250
250
  if (matchingItem != null) {
@@ -82,7 +82,7 @@ useTreeViewLabel.getDefaultizedParams = ({
82
82
  const canUseFeature = experimentalFeatures?.labelEditing;
83
83
  if (process.env.NODE_ENV !== 'production') {
84
84
  if (params.isItemEditable && !canUseFeature) {
85
- (0, _warning.warnOnce)(['MUI X: The label editing feature requires the `labelEditing` experimental feature to be enabled.', 'You can do it by passing `experimentalFeatures={{ labelEditing: true}}` to the `RichTreeViewPro` component.', 'Check the documentation for more details: https://mui.com/x/react-tree-view/rich-tree-view/editing/']);
85
+ (0, _warning.warnOnce)(['MUI X: The label editing feature requires the `labelEditing` experimental feature to be enabled.', 'You can do it by passing `experimentalFeatures={{ labelEditing: true}}` to the Rich Tree View Pro component.', 'Check the documentation for more details: https://mui.com/x/react-tree-view/rich-tree-view/editing/']);
86
86
  }
87
87
  }
88
88
  return (0, _extends2.default)({}, params, {
@@ -13,4 +13,15 @@ Object.keys(_items).forEach(function (key) {
13
13
  return _items[key];
14
14
  }
15
15
  });
16
+ });
17
+ var _events = require("./events");
18
+ Object.keys(_events).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _events[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _events[key];
25
+ }
26
+ });
16
27
  });
@@ -24,7 +24,6 @@ const useTreeItem2 = parameters => {
24
24
  indentationAtItemLevel
25
25
  },
26
26
  selection: {
27
- multiSelect,
28
27
  disableSelection,
29
28
  checkboxSelection
30
29
  },
@@ -92,7 +91,7 @@ const useTreeItem2 = parameters => {
92
91
  // the input that triggers the root blur can be either the relatedTarget (when entering editing state) or the target (when exiting editing state)
93
92
  // when we enter the editing state, we focus the input -> we don't want to remove the focused item from the state
94
93
  if (status.editing ||
95
- // 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
94
+ // 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
96
95
  // 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
97
96
  event.relatedTarget && (0, _tree.isTargetInDescendants)(event.relatedTarget, rootElement) && (event.target && event.target?.dataset?.element === 'labelInput' && (0, _tree.isTargetInDescendants)(event.target, rootElement) || event.relatedTarget?.dataset?.element === 'labelInput')) {
98
97
  return;
@@ -158,17 +157,18 @@ const useTreeItem2 = parameters => {
158
157
  };
159
158
  const getRootProps = (externalProps = {}) => {
160
159
  const externalEventHandlers = (0, _extends2.default)({}, (0, _extractEventHandlers.default)(parameters), (0, _extractEventHandlers.default)(externalProps));
160
+
161
+ // https://www.w3.org/WAI/ARIA/apg/patterns/treeview/
161
162
  let ariaSelected;
162
- if (multiSelect) {
163
- ariaSelected = status.selected;
164
- } else if (status.selected) {
165
- /* single-selection trees unset aria-selected on un-selected items.
166
- *
167
- * If the tree does not support multiple selection, aria-selected
168
- * is set to true for the selected item and it is not present on any other item in the tree.
169
- * Source: https://www.w3.org/WAI/ARIA/apg/patterns/treeview/
170
- */
163
+ if (status.selected) {
164
+ // - each selected node has aria-selected set to true.
171
165
  ariaSelected = true;
166
+ } else if (disableSelection || status.disabled) {
167
+ // - if the tree contains nodes that are not selectable, aria-selected is not present on those nodes.
168
+ ariaSelected = undefined;
169
+ } else {
170
+ // - all nodes that are selectable but not selected have aria-selected set to false.
171
+ ariaSelected = false;
172
172
  }
173
173
  const props = (0, _extends2.default)({}, externalEventHandlers, {
174
174
  ref: handleRootRef,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-tree-view",
3
- "version": "7.20.0",
3
+ "version": "7.22.0",
4
4
  "description": "The community edition of the Tree View components (MUI X).",
5
5
  "author": "MUI Team",
6
6
  "main": "./node/index.js",
@@ -39,7 +39,7 @@
39
39
  "clsx": "^2.1.1",
40
40
  "prop-types": "^15.8.1",
41
41
  "react-transition-group": "^4.4.5",
42
- "@mui/x-internals": "7.20.0"
42
+ "@mui/x-internals": "7.21.0"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@emotion/react": "^11.9.0",
@@ -16,7 +16,6 @@ export const useTreeItem2 = parameters => {
16
16
  indentationAtItemLevel
17
17
  },
18
18
  selection: {
19
- multiSelect,
20
19
  disableSelection,
21
20
  checkboxSelection
22
21
  },
@@ -84,7 +83,7 @@ export const useTreeItem2 = parameters => {
84
83
  // the input that triggers the root blur can be either the relatedTarget (when entering editing state) or the target (when exiting editing state)
85
84
  // when we enter the editing state, we focus the input -> we don't want to remove the focused item from the state
86
85
  if (status.editing ||
87
- // 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
86
+ // 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
88
87
  // 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
89
88
  event.relatedTarget && isTargetInDescendants(event.relatedTarget, rootElement) && (event.target && event.target?.dataset?.element === 'labelInput' && isTargetInDescendants(event.target, rootElement) || event.relatedTarget?.dataset?.element === 'labelInput')) {
90
89
  return;
@@ -150,17 +149,18 @@ export const useTreeItem2 = parameters => {
150
149
  };
151
150
  const getRootProps = (externalProps = {}) => {
152
151
  const externalEventHandlers = _extends({}, extractEventHandlers(parameters), extractEventHandlers(externalProps));
152
+
153
+ // https://www.w3.org/WAI/ARIA/apg/patterns/treeview/
153
154
  let ariaSelected;
154
- if (multiSelect) {
155
- ariaSelected = status.selected;
156
- } else if (status.selected) {
157
- /* single-selection trees unset aria-selected on un-selected items.
158
- *
159
- * If the tree does not support multiple selection, aria-selected
160
- * is set to true for the selected item and it is not present on any other item in the tree.
161
- * Source: https://www.w3.org/WAI/ARIA/apg/patterns/treeview/
162
- */
155
+ if (status.selected) {
156
+ // - each selected node has aria-selected set to true.
163
157
  ariaSelected = true;
158
+ } else if (disableSelection || status.disabled) {
159
+ // - if the tree contains nodes that are not selectable, aria-selected is not present on those nodes.
160
+ ariaSelected = undefined;
161
+ } else {
162
+ // - all nodes that are selectable but not selected have aria-selected set to false.
163
+ ariaSelected = false;
164
164
  }
165
165
  const props = _extends({}, externalEventHandlers, {
166
166
  ref: handleRootRef,
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
- import { TreeViewItemId } from '../models';
3
- import { TreeViewPublicAPI, MuiCancellableEventHandler } from '../internals/models';
2
+ import { TreeViewItemId, TreeViewCancellableEventHandler } from '../models';
3
+ import { TreeViewPublicAPI } from '../internals/models';
4
4
  import { UseTreeViewSelectionSignature } from '../internals/plugins/useTreeViewSelection';
5
5
  import { UseTreeViewItemsSignature } from '../internals/plugins/useTreeViewItems';
6
6
  import { UseTreeViewFocusSignature } from '../internals/plugins/useTreeViewFocus';
@@ -39,9 +39,9 @@ export interface UseTreeItem2RootSlotPropsFromUseTreeItem {
39
39
  'aria-expanded': React.AriaAttributes['aria-expanded'];
40
40
  'aria-selected': React.AriaAttributes['aria-selected'];
41
41
  'aria-disabled': React.AriaAttributes['aria-disabled'];
42
- onFocus: MuiCancellableEventHandler<React.FocusEvent<HTMLElement>>;
43
- onBlur: MuiCancellableEventHandler<React.FocusEvent<HTMLElement>>;
44
- onKeyDown: MuiCancellableEventHandler<React.KeyboardEvent<HTMLElement>>;
42
+ onFocus: TreeViewCancellableEventHandler<React.FocusEvent<HTMLElement>>;
43
+ onBlur: TreeViewCancellableEventHandler<React.FocusEvent<HTMLElement>>;
44
+ onKeyDown: TreeViewCancellableEventHandler<React.KeyboardEvent<HTMLElement>>;
45
45
  ref: React.RefCallback<HTMLLIElement>;
46
46
  /**
47
47
  * Only defined when the `indentationAtItemLevel` experimental feature is enabled.
@@ -52,8 +52,8 @@ export interface UseTreeItem2RootSlotOwnProps extends UseTreeItem2RootSlotPropsF
52
52
  }
53
53
  export type UseTreeItem2RootSlotProps<ExternalProps = {}> = ExternalProps & UseTreeItem2RootSlotOwnProps;
54
54
  export interface UseTreeItem2ContentSlotPropsFromUseTreeItem {
55
- onClick: MuiCancellableEventHandler<React.MouseEvent>;
56
- onMouseDown: MuiCancellableEventHandler<React.MouseEvent>;
55
+ onClick: TreeViewCancellableEventHandler<React.MouseEvent>;
56
+ onMouseDown: TreeViewCancellableEventHandler<React.MouseEvent>;
57
57
  ref: React.RefCallback<HTMLDivElement> | null;
58
58
  status: UseTreeItem2Status;
59
59
  /**
@@ -65,12 +65,12 @@ export interface UseTreeItem2ContentSlotOwnProps extends UseTreeItem2ContentSlot
65
65
  }
66
66
  export type UseTreeItem2ContentSlotProps<ExternalProps = {}> = ExternalProps & UseTreeItem2ContentSlotOwnProps;
67
67
  export interface UseTreeItem2IconContainerSlotOwnProps {
68
- onClick: MuiCancellableEventHandler<React.MouseEvent>;
68
+ onClick: TreeViewCancellableEventHandler<React.MouseEvent>;
69
69
  }
70
70
  export type UseTreeItemIconContainerSlotProps<ExternalProps = {}> = ExternalProps & UseTreeItem2IconContainerSlotOwnProps;
71
71
  export interface UseTreeItem2LabelSlotOwnProps {
72
72
  children: React.ReactNode;
73
- onDoubleClick: MuiCancellableEventHandler<React.MouseEvent>;
73
+ onDoubleClick: TreeViewCancellableEventHandler<React.MouseEvent>;
74
74
  /**
75
75
  * Only defined when the `isItemEditable` experimental feature is enabled.
76
76
  */
@@ -83,7 +83,7 @@ export type UseTreeItem2LabelInputSlotProps<ExternalProps = {}> = ExternalProps
83
83
  export interface UseTreeItem2CheckboxSlotOwnProps {
84
84
  visible: boolean;
85
85
  checked: boolean;
86
- onChange: MuiCancellableEventHandler<React.ChangeEvent<HTMLInputElement>>;
86
+ onChange: TreeViewCancellableEventHandler<React.ChangeEvent<HTMLInputElement>>;
87
87
  disabled: boolean;
88
88
  ref: React.RefObject<HTMLButtonElement>;
89
89
  tabIndex: -1;
@@ -158,7 +158,7 @@ export interface UseTreeItem2ReturnValue<TSignatures extends UseTreeItem2Minimal
158
158
  getGroupTransitionProps: <ExternalProps extends Record<string, any> = {}>(externalProps?: ExternalProps) => UseTreeItem2GroupTransitionSlotProps<ExternalProps>;
159
159
  /**
160
160
  * Resolver for the DragAndDropOverlay slot's props.
161
- * Warning: This slot is only useful when using the `RichTreeViewPro` component.
161
+ * Warning: This slot is only useful when using the `<RichTreeViewPro />` component.
162
162
  * @param {ExternalProps} externalProps Additional props for the DragAndDropOverlay slot.
163
163
  * @returns {UseTreeItem2DragAndDropOverlaySlotProps<ExternalProps>} Props that should be spread on the DragAndDropOverlay slot.
164
164
  */
@@ -1,4 +0,0 @@
1
- export type MuiCancellableEvent = {
2
- defaultMuiPrevented?: boolean;
3
- };
4
- export type MuiCancellableEventHandler<Event> = (event: Event & MuiCancellableEvent) => void;