@mui/x-tree-view 7.20.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 (61) hide show
  1. package/CHANGELOG.md +120 -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 +6 -6
  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/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/corePlugins/corePlugins.d.ts +1 -1
  16. package/internals/corePlugins/corePlugins.js +1 -1
  17. package/internals/corePlugins/useTreeViewId/useTreeViewId.js +3 -3
  18. package/internals/corePlugins/useTreeViewId/useTreeViewId.types.d.ts +1 -1
  19. package/internals/corePlugins/useTreeViewId/useTreeViewId.utils.d.ts +1 -1
  20. package/internals/corePlugins/useTreeViewId/useTreeViewId.utils.js +1 -1
  21. package/internals/models/treeView.d.ts +2 -2
  22. package/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.types.d.ts +2 -2
  23. package/internals/plugins/useTreeViewFocus/useTreeViewFocus.types.d.ts +1 -1
  24. package/internals/plugins/useTreeViewIcons/useTreeViewIcons.types.d.ts +1 -1
  25. package/internals/plugins/useTreeViewItems/useTreeViewItems.types.d.ts +2 -2
  26. package/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.js +1 -1
  27. package/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js +3 -3
  28. package/internals/plugins/useTreeViewLabel/useTreeViewLabel.js +1 -1
  29. package/internals/plugins/useTreeViewLabel/useTreeViewLabel.types.d.ts +1 -1
  30. package/internals/plugins/useTreeViewSelection/useTreeViewSelection.types.d.ts +3 -3
  31. package/modern/RichTreeView/RichTreeView.js +8 -8
  32. package/modern/SimpleTreeView/SimpleTreeView.js +8 -8
  33. package/modern/TreeItem/TreeItem.js +15 -14
  34. package/modern/TreeItem/TreeItemContent.js +4 -4
  35. package/modern/TreeItem2DragAndDropOverlay/TreeItem2DragAndDropOverlay.js +7 -7
  36. package/modern/TreeView/TreeView.js +8 -8
  37. package/modern/index.js +1 -1
  38. package/modern/internals/corePlugins/corePlugins.js +1 -1
  39. package/modern/internals/corePlugins/useTreeViewId/useTreeViewId.js +3 -3
  40. package/modern/internals/corePlugins/useTreeViewId/useTreeViewId.utils.js +1 -1
  41. package/modern/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.js +1 -1
  42. package/modern/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js +3 -3
  43. package/modern/internals/plugins/useTreeViewLabel/useTreeViewLabel.js +1 -1
  44. package/modern/useTreeItem2/useTreeItem2.js +11 -11
  45. package/node/RichTreeView/RichTreeView.js +8 -8
  46. package/node/SimpleTreeView/SimpleTreeView.js +8 -8
  47. package/node/TreeItem/TreeItem.js +15 -14
  48. package/node/TreeItem/TreeItemContent.js +4 -4
  49. package/node/TreeItem2DragAndDropOverlay/TreeItem2DragAndDropOverlay.js +7 -7
  50. package/node/TreeView/TreeView.js +8 -8
  51. package/node/index.js +1 -1
  52. package/node/internals/corePlugins/corePlugins.js +1 -1
  53. package/node/internals/corePlugins/useTreeViewId/useTreeViewId.js +3 -3
  54. package/node/internals/corePlugins/useTreeViewId/useTreeViewId.utils.js +1 -1
  55. package/node/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.js +1 -1
  56. package/node/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js +3 -3
  57. package/node/internals/plugins/useTreeViewLabel/useTreeViewLabel.js +1 -1
  58. package/node/useTreeItem2/useTreeItem2.js +11 -11
  59. package/package.json +2 -2
  60. package/useTreeItem2/useTreeItem2.js +11 -11
  61. package/useTreeItem2/useTreeItem2.types.d.ts +1 -1
@@ -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.
@@ -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, {
@@ -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.21.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,
@@ -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
  */