@mui/x-tree-view 7.8.0 → 7.9.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.
- package/CHANGELOG.md +66 -0
- package/RichTreeView/RichTreeView.js +7 -5
- package/SimpleTreeView/SimpleTreeView.js +7 -5
- package/TreeItem/useTreeItemState.js +16 -3
- package/TreeView/TreeView.js +7 -5
- package/hooks/useTreeItem2Utils/useTreeItem2Utils.js +16 -3
- package/index.js +1 -1
- package/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.types.d.ts +7 -7
- package/internals/plugins/useTreeViewFocus/useTreeViewFocus.js +1 -2
- package/internals/plugins/useTreeViewFocus/useTreeViewFocus.types.d.ts +2 -2
- package/internals/plugins/useTreeViewItems/useTreeViewItems.js +10 -1
- package/internals/plugins/useTreeViewItems/useTreeViewItems.types.d.ts +7 -1
- package/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js +15 -5
- package/internals/plugins/useTreeViewSelection/useTreeViewSelection.js +12 -4
- package/internals/plugins/useTreeViewSelection/useTreeViewSelection.types.d.ts +25 -16
- package/modern/RichTreeView/RichTreeView.js +7 -5
- package/modern/SimpleTreeView/SimpleTreeView.js +7 -5
- package/modern/TreeItem/useTreeItemState.js +16 -3
- package/modern/TreeView/TreeView.js +7 -5
- package/modern/hooks/useTreeItem2Utils/useTreeItem2Utils.js +16 -3
- package/modern/index.js +1 -1
- package/modern/internals/plugins/useTreeViewFocus/useTreeViewFocus.js +1 -2
- package/modern/internals/plugins/useTreeViewItems/useTreeViewItems.js +10 -1
- package/modern/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js +15 -5
- package/modern/internals/plugins/useTreeViewSelection/useTreeViewSelection.js +12 -4
- package/node/RichTreeView/RichTreeView.js +7 -5
- package/node/SimpleTreeView/SimpleTreeView.js +7 -5
- package/node/TreeItem/useTreeItemState.js +16 -3
- package/node/TreeView/TreeView.js +7 -5
- package/node/hooks/useTreeItem2Utils/useTreeItem2Utils.js +16 -3
- package/node/index.js +1 -1
- package/node/internals/plugins/useTreeViewFocus/useTreeViewFocus.js +1 -2
- package/node/internals/plugins/useTreeViewItems/useTreeViewItems.js +10 -1
- package/node/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js +15 -5
- package/node/internals/plugins/useTreeViewSelection/useTreeViewSelection.js +12 -4
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,72 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 7.9.0
|
|
7
|
+
|
|
8
|
+
_Jul 5, 2024_
|
|
9
|
+
|
|
10
|
+
We'd like to offer a big thanks to the 7 contributors who made this release possible. Here are some highlights ✨:
|
|
11
|
+
|
|
12
|
+
- 🔄 Add loading overlay variants, including a skeleton loader option to the Data Grid component. See [Loading overlay docs](https://mui.com/x/react-data-grid/overlays/#loading-overlay) for more details.
|
|
13
|
+
- 🌳 Add `selectItem` and `getItemDOMElement` methods to the TreeView component public API
|
|
14
|
+
- ⛏️ Make the `usePickersTranslations` hook public in the pickers component
|
|
15
|
+
- 🐞 Bugfixes
|
|
16
|
+
|
|
17
|
+
<!--/ HIGHLIGHT_ABOVE_SEPARATOR /-->
|
|
18
|
+
|
|
19
|
+
### Data Grid
|
|
20
|
+
|
|
21
|
+
#### `@mui/x-data-grid@7.9.0`
|
|
22
|
+
|
|
23
|
+
- [DataGrid] Add skeleton loading overlay support (#13293) @KenanYusuf
|
|
24
|
+
- [DataGrid] Fix pagination when `pagination={undefined}` (#13349) @sai6855
|
|
25
|
+
|
|
26
|
+
#### `@mui/x-data-grid-pro@7.9.0` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
27
|
+
|
|
28
|
+
Same changes as in `@mui/x-data-grid@7.9.0`.
|
|
29
|
+
|
|
30
|
+
#### `@mui/x-data-grid-premium@7.9.0` [](https://mui.com/r/x-premium-svg-link 'Premium plan')
|
|
31
|
+
|
|
32
|
+
Same changes as in `@mui/x-data-grid-pro@7.9.0`.
|
|
33
|
+
|
|
34
|
+
### Date and Time Pickers
|
|
35
|
+
|
|
36
|
+
#### `@mui/x-date-pickers@7.9.0`
|
|
37
|
+
|
|
38
|
+
- [pickers] Make the `usePickersTranslations` hook public (#13657) @flaviendelangle
|
|
39
|
+
|
|
40
|
+
#### `@mui/x-date-pickers-pro@7.9.0` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
41
|
+
|
|
42
|
+
Same changes as in `@mui/x-date-pickers@7.9.0`.
|
|
43
|
+
|
|
44
|
+
### Charts
|
|
45
|
+
|
|
46
|
+
#### `@mui/x-charts@7.9.0`
|
|
47
|
+
|
|
48
|
+
- [charts] Add Heatmap (unreleased) (#13209) @alexfauquette
|
|
49
|
+
- [charts] Add initial `Zoom&Pan` to the Pro charts (unreleased) (#13405) @JCQuintas
|
|
50
|
+
- [charts] Fix Axis Highlight on horizontal bar charts regression (#13717) @JCQuintas
|
|
51
|
+
- [charts] Improve charts interaction for mobile users (#13692) @JCQuintas
|
|
52
|
+
- [charts] Add documentation on how to disable the tooltip on charts (#13724) @JCQuintas
|
|
53
|
+
|
|
54
|
+
### Tree View
|
|
55
|
+
|
|
56
|
+
#### `@mui/x-tree-view@7.9.0`
|
|
57
|
+
|
|
58
|
+
- [TreeView] Add `selectItem` and `getItemDOMElement` methods to the public API (#13485) @flaviendelangle
|
|
59
|
+
|
|
60
|
+
### Docs
|
|
61
|
+
|
|
62
|
+
- [docs] Fix custom "no results overlay" demo in dark mode (#13715) @KenanYusuf
|
|
63
|
+
|
|
64
|
+
### Core
|
|
65
|
+
|
|
66
|
+
- [core] Add `react_next` workflow in CircleCI (#13360) @cherniavskii
|
|
67
|
+
- [core] Create a new package to share utils across X packages (#13528) @flaviendelangle
|
|
68
|
+
- [core] Fix dependency setup (#13684) @LukasTy
|
|
69
|
+
- [core] Remove `jscodeshift-add-imports` package (#13720) @LukasTy
|
|
70
|
+
- [code-infra] Cleanup monorepo and `@mui/docs` usage (#13713) @LukasTy
|
|
71
|
+
|
|
6
72
|
## 7.8.0
|
|
7
73
|
|
|
8
74
|
_Jun 28, 2024_
|
|
@@ -137,6 +137,8 @@ process.env.NODE_ENV !== "production" ? RichTreeView.propTypes = {
|
|
|
137
137
|
current: PropTypes.shape({
|
|
138
138
|
focusItem: PropTypes.func.isRequired,
|
|
139
139
|
getItem: PropTypes.func.isRequired,
|
|
140
|
+
getItemDOMElement: PropTypes.func.isRequired,
|
|
141
|
+
selectItem: PropTypes.func.isRequired,
|
|
140
142
|
setItemExpansion: PropTypes.func.isRequired
|
|
141
143
|
})
|
|
142
144
|
}),
|
|
@@ -234,34 +236,34 @@ process.env.NODE_ENV !== "production" ? RichTreeView.propTypes = {
|
|
|
234
236
|
multiSelect: PropTypes.bool,
|
|
235
237
|
/**
|
|
236
238
|
* Callback fired when tree items are expanded/collapsed.
|
|
237
|
-
* @param {React.SyntheticEvent} event The event
|
|
239
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
238
240
|
* @param {array} itemIds The ids of the expanded items.
|
|
239
241
|
*/
|
|
240
242
|
onExpandedItemsChange: PropTypes.func,
|
|
241
243
|
/**
|
|
242
244
|
* Callback fired when a tree item is expanded or collapsed.
|
|
243
|
-
* @param {React.SyntheticEvent} event The event
|
|
245
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
244
246
|
* @param {array} itemId The itemId of the modified item.
|
|
245
247
|
* @param {array} isExpanded `true` if the item has just been expanded, `false` if it has just been collapsed.
|
|
246
248
|
*/
|
|
247
249
|
onItemExpansionToggle: PropTypes.func,
|
|
248
250
|
/**
|
|
249
251
|
* Callback fired when tree items are focused.
|
|
250
|
-
* @param {React.SyntheticEvent} event The event
|
|
252
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change. **Warning**: This is a generic event not a focus event.
|
|
251
253
|
* @param {string} itemId The id of the focused item.
|
|
252
254
|
* @param {string} value of the focused item.
|
|
253
255
|
*/
|
|
254
256
|
onItemFocus: PropTypes.func,
|
|
255
257
|
/**
|
|
256
258
|
* Callback fired when a tree item is selected or deselected.
|
|
257
|
-
* @param {React.SyntheticEvent} event The event
|
|
259
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
258
260
|
* @param {array} itemId The itemId of the modified item.
|
|
259
261
|
* @param {array} isSelected `true` if the item has just been selected, `false` if it has just been deselected.
|
|
260
262
|
*/
|
|
261
263
|
onItemSelectionToggle: PropTypes.func,
|
|
262
264
|
/**
|
|
263
265
|
* Callback fired when tree items are selected/deselected.
|
|
264
|
-
* @param {React.SyntheticEvent} event The event
|
|
266
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
265
267
|
* @param {string[] | string} itemIds The ids of the selected items.
|
|
266
268
|
* When `multiSelect` is `true`, this is an array of strings; when false (default) a string.
|
|
267
269
|
*/
|
|
@@ -95,6 +95,8 @@ process.env.NODE_ENV !== "production" ? SimpleTreeView.propTypes = {
|
|
|
95
95
|
current: PropTypes.shape({
|
|
96
96
|
focusItem: PropTypes.func.isRequired,
|
|
97
97
|
getItem: PropTypes.func.isRequired,
|
|
98
|
+
getItemDOMElement: PropTypes.func.isRequired,
|
|
99
|
+
selectItem: PropTypes.func.isRequired,
|
|
98
100
|
setItemExpansion: PropTypes.func.isRequired
|
|
99
101
|
})
|
|
100
102
|
}),
|
|
@@ -170,34 +172,34 @@ process.env.NODE_ENV !== "production" ? SimpleTreeView.propTypes = {
|
|
|
170
172
|
multiSelect: PropTypes.bool,
|
|
171
173
|
/**
|
|
172
174
|
* Callback fired when tree items are expanded/collapsed.
|
|
173
|
-
* @param {React.SyntheticEvent} event The event
|
|
175
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
174
176
|
* @param {array} itemIds The ids of the expanded items.
|
|
175
177
|
*/
|
|
176
178
|
onExpandedItemsChange: PropTypes.func,
|
|
177
179
|
/**
|
|
178
180
|
* Callback fired when a tree item is expanded or collapsed.
|
|
179
|
-
* @param {React.SyntheticEvent} event The event
|
|
181
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
180
182
|
* @param {array} itemId The itemId of the modified item.
|
|
181
183
|
* @param {array} isExpanded `true` if the item has just been expanded, `false` if it has just been collapsed.
|
|
182
184
|
*/
|
|
183
185
|
onItemExpansionToggle: PropTypes.func,
|
|
184
186
|
/**
|
|
185
187
|
* Callback fired when tree items are focused.
|
|
186
|
-
* @param {React.SyntheticEvent} event The event
|
|
188
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change. **Warning**: This is a generic event not a focus event.
|
|
187
189
|
* @param {string} itemId The id of the focused item.
|
|
188
190
|
* @param {string} value of the focused item.
|
|
189
191
|
*/
|
|
190
192
|
onItemFocus: PropTypes.func,
|
|
191
193
|
/**
|
|
192
194
|
* Callback fired when a tree item is selected or deselected.
|
|
193
|
-
* @param {React.SyntheticEvent} event The event
|
|
195
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
194
196
|
* @param {array} itemId The itemId of the modified item.
|
|
195
197
|
* @param {array} isSelected `true` if the item has just been selected, `false` if it has just been deselected.
|
|
196
198
|
*/
|
|
197
199
|
onItemSelectionToggle: PropTypes.func,
|
|
198
200
|
/**
|
|
199
201
|
* Callback fired when tree items are selected/deselected.
|
|
200
|
-
* @param {React.SyntheticEvent} event The event
|
|
202
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
201
203
|
* @param {string[] | string} itemIds The ids of the selected items.
|
|
202
204
|
* When `multiSelect` is `true`, this is an array of strings; when false (default) a string.
|
|
203
205
|
*/
|
|
@@ -39,10 +39,18 @@ export function useTreeItemState(itemId) {
|
|
|
39
39
|
if (event.shiftKey) {
|
|
40
40
|
instance.expandSelectionRange(event, itemId);
|
|
41
41
|
} else {
|
|
42
|
-
instance.selectItem(
|
|
42
|
+
instance.selectItem({
|
|
43
|
+
event,
|
|
44
|
+
itemId,
|
|
45
|
+
keepExistingSelection: true
|
|
46
|
+
});
|
|
43
47
|
}
|
|
44
48
|
} else {
|
|
45
|
-
instance.selectItem(
|
|
49
|
+
instance.selectItem({
|
|
50
|
+
event,
|
|
51
|
+
itemId,
|
|
52
|
+
shouldBeSelected: true
|
|
53
|
+
});
|
|
46
54
|
}
|
|
47
55
|
}
|
|
48
56
|
};
|
|
@@ -54,7 +62,12 @@ export function useTreeItemState(itemId) {
|
|
|
54
62
|
if (multiSelect && hasShift) {
|
|
55
63
|
instance.expandSelectionRange(event, itemId);
|
|
56
64
|
} else {
|
|
57
|
-
instance.selectItem(
|
|
65
|
+
instance.selectItem({
|
|
66
|
+
event,
|
|
67
|
+
itemId,
|
|
68
|
+
keepExistingSelection: multiSelect,
|
|
69
|
+
shouldBeSelected: event.target.checked
|
|
70
|
+
});
|
|
58
71
|
}
|
|
59
72
|
};
|
|
60
73
|
const preventSelection = event => {
|
package/TreeView/TreeView.js
CHANGED
|
@@ -72,6 +72,8 @@ process.env.NODE_ENV !== "production" ? TreeView.propTypes = {
|
|
|
72
72
|
current: PropTypes.shape({
|
|
73
73
|
focusItem: PropTypes.func.isRequired,
|
|
74
74
|
getItem: PropTypes.func.isRequired,
|
|
75
|
+
getItemDOMElement: PropTypes.func.isRequired,
|
|
76
|
+
selectItem: PropTypes.func.isRequired,
|
|
75
77
|
setItemExpansion: PropTypes.func.isRequired
|
|
76
78
|
})
|
|
77
79
|
}),
|
|
@@ -147,34 +149,34 @@ process.env.NODE_ENV !== "production" ? TreeView.propTypes = {
|
|
|
147
149
|
multiSelect: PropTypes.bool,
|
|
148
150
|
/**
|
|
149
151
|
* Callback fired when tree items are expanded/collapsed.
|
|
150
|
-
* @param {React.SyntheticEvent} event The event
|
|
152
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
151
153
|
* @param {array} itemIds The ids of the expanded items.
|
|
152
154
|
*/
|
|
153
155
|
onExpandedItemsChange: PropTypes.func,
|
|
154
156
|
/**
|
|
155
157
|
* Callback fired when a tree item is expanded or collapsed.
|
|
156
|
-
* @param {React.SyntheticEvent} event The event
|
|
158
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
157
159
|
* @param {array} itemId The itemId of the modified item.
|
|
158
160
|
* @param {array} isExpanded `true` if the item has just been expanded, `false` if it has just been collapsed.
|
|
159
161
|
*/
|
|
160
162
|
onItemExpansionToggle: PropTypes.func,
|
|
161
163
|
/**
|
|
162
164
|
* Callback fired when tree items are focused.
|
|
163
|
-
* @param {React.SyntheticEvent} event The event
|
|
165
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change. **Warning**: This is a generic event not a focus event.
|
|
164
166
|
* @param {string} itemId The id of the focused item.
|
|
165
167
|
* @param {string} value of the focused item.
|
|
166
168
|
*/
|
|
167
169
|
onItemFocus: PropTypes.func,
|
|
168
170
|
/**
|
|
169
171
|
* Callback fired when a tree item is selected or deselected.
|
|
170
|
-
* @param {React.SyntheticEvent} event The event
|
|
172
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
171
173
|
* @param {array} itemId The itemId of the modified item.
|
|
172
174
|
* @param {array} isSelected `true` if the item has just been selected, `false` if it has just been deselected.
|
|
173
175
|
*/
|
|
174
176
|
onItemSelectionToggle: PropTypes.func,
|
|
175
177
|
/**
|
|
176
178
|
* Callback fired when tree items are selected/deselected.
|
|
177
|
-
* @param {React.SyntheticEvent} event The event
|
|
179
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
178
180
|
* @param {string[] | string} itemIds The ids of the selected items.
|
|
179
181
|
* When `multiSelect` is `true`, this is an array of strings; when false (default) a string.
|
|
180
182
|
*/
|
|
@@ -57,10 +57,18 @@ export const useTreeItem2Utils = ({
|
|
|
57
57
|
if (event.shiftKey) {
|
|
58
58
|
instance.expandSelectionRange(event, itemId);
|
|
59
59
|
} else {
|
|
60
|
-
instance.selectItem(
|
|
60
|
+
instance.selectItem({
|
|
61
|
+
event,
|
|
62
|
+
itemId,
|
|
63
|
+
keepExistingSelection: true
|
|
64
|
+
});
|
|
61
65
|
}
|
|
62
66
|
} else {
|
|
63
|
-
instance.selectItem(
|
|
67
|
+
instance.selectItem({
|
|
68
|
+
event,
|
|
69
|
+
itemId,
|
|
70
|
+
shouldBeSelected: true
|
|
71
|
+
});
|
|
64
72
|
}
|
|
65
73
|
};
|
|
66
74
|
const handleCheckboxSelection = event => {
|
|
@@ -68,7 +76,12 @@ export const useTreeItem2Utils = ({
|
|
|
68
76
|
if (multiSelect && hasShift) {
|
|
69
77
|
instance.expandSelectionRange(event, itemId);
|
|
70
78
|
} else {
|
|
71
|
-
instance.selectItem(
|
|
79
|
+
instance.selectItem({
|
|
80
|
+
event,
|
|
81
|
+
itemId,
|
|
82
|
+
keepExistingSelection: multiSelect,
|
|
83
|
+
shouldBeSelected: event.target.checked
|
|
84
|
+
});
|
|
72
85
|
}
|
|
73
86
|
};
|
|
74
87
|
const interactions = {
|
package/index.js
CHANGED
|
@@ -5,9 +5,9 @@ import { TreeViewItemId } from '../../../models';
|
|
|
5
5
|
export interface UseTreeViewExpansionPublicAPI {
|
|
6
6
|
/**
|
|
7
7
|
* Change the expansion status of a given item.
|
|
8
|
-
* @param {React.SyntheticEvent} event The
|
|
9
|
-
* @param {string} itemId The id of the item to
|
|
10
|
-
* @param {boolean} isExpanded
|
|
8
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
9
|
+
* @param {string} itemId The id of the item to expand of collapse.
|
|
10
|
+
* @param {boolean} isExpanded If `true` the item will be expanded. If `false` the item will be collapsed.
|
|
11
11
|
*/
|
|
12
12
|
setItemExpansion: (event: React.SyntheticEvent, itemId: string, isExpanded: boolean) => void;
|
|
13
13
|
}
|
|
@@ -29,13 +29,13 @@ export interface UseTreeViewExpansionInstance extends UseTreeViewExpansionPublic
|
|
|
29
29
|
/**
|
|
30
30
|
* Toggle the current expansion of an item.
|
|
31
31
|
* If it is expanded, it will be collapsed, and vice versa.
|
|
32
|
-
* @param {React.SyntheticEvent} event The
|
|
32
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
33
33
|
* @param {TreeViewItemId} itemId The id of the item to toggle.
|
|
34
34
|
*/
|
|
35
35
|
toggleItemExpansion: (event: React.SyntheticEvent, itemId: TreeViewItemId) => void;
|
|
36
36
|
/**
|
|
37
37
|
* Expand all the siblings (i.e.: the items that have the same parent) of a given item.
|
|
38
|
-
* @param {React.SyntheticEvent} event The
|
|
38
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
39
39
|
* @param {TreeViewItemId} itemId The id of the item whose siblings will be expanded.
|
|
40
40
|
*/
|
|
41
41
|
expandAllSiblings: (event: React.KeyboardEvent, itemId: TreeViewItemId) => void;
|
|
@@ -54,13 +54,13 @@ export interface UseTreeViewExpansionParameters {
|
|
|
54
54
|
defaultExpandedItems?: string[];
|
|
55
55
|
/**
|
|
56
56
|
* Callback fired when tree items are expanded/collapsed.
|
|
57
|
-
* @param {React.SyntheticEvent} event The event
|
|
57
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
58
58
|
* @param {array} itemIds The ids of the expanded items.
|
|
59
59
|
*/
|
|
60
60
|
onExpandedItemsChange?: (event: React.SyntheticEvent, itemIds: string[]) => void;
|
|
61
61
|
/**
|
|
62
62
|
* Callback fired when a tree item is expanded or collapsed.
|
|
63
|
-
* @param {React.SyntheticEvent} event The event
|
|
63
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
64
64
|
* @param {array} itemId The itemId of the modified item.
|
|
65
65
|
* @param {array} isExpanded `true` if the item has just been expanded, `false` if it has just been collapsed.
|
|
66
66
|
*/
|
|
@@ -43,8 +43,7 @@ export const useTreeViewFocus = ({
|
|
|
43
43
|
return itemMeta && (itemMeta.parentId == null || instance.isItemExpanded(itemMeta.parentId));
|
|
44
44
|
};
|
|
45
45
|
const innerFocusItem = (event, itemId) => {
|
|
46
|
-
const
|
|
47
|
-
const itemElement = document.getElementById(instance.getTreeItemIdAttribute(itemId, itemMeta.idAttribute));
|
|
46
|
+
const itemElement = instance.getItemDOMElement(itemId);
|
|
48
47
|
if (itemElement) {
|
|
49
48
|
itemElement.focus();
|
|
50
49
|
}
|
|
@@ -10,7 +10,7 @@ export interface UseTreeViewFocusPublicAPI {
|
|
|
10
10
|
*
|
|
11
11
|
* If the item is the child of a collapsed item, then this method will do nothing.
|
|
12
12
|
* Make sure to expand the ancestors of the item before calling this method if needed.
|
|
13
|
-
* @param {React.SyntheticEvent} event The event
|
|
13
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
14
14
|
* @param {TreeViewItemId} itemId The id of the item to focus.
|
|
15
15
|
*/
|
|
16
16
|
focusItem: (event: React.SyntheticEvent, itemId: string) => void;
|
|
@@ -38,7 +38,7 @@ export interface UseTreeViewFocusInstance extends UseTreeViewFocusPublicAPI {
|
|
|
38
38
|
export interface UseTreeViewFocusParameters {
|
|
39
39
|
/**
|
|
40
40
|
* Callback fired when tree items are focused.
|
|
41
|
-
* @param {React.SyntheticEvent} event The event
|
|
41
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change. **Warning**: This is a generic event not a focus event.
|
|
42
42
|
* @param {string} itemId The id of the focused item.
|
|
43
43
|
* @param {string} value of the focused item.
|
|
44
44
|
*/
|
|
@@ -92,6 +92,13 @@ export const useTreeViewItems = ({
|
|
|
92
92
|
return state.items.itemChildrenIndexes[parentId][itemId];
|
|
93
93
|
}, [instance, state.items.itemChildrenIndexes]);
|
|
94
94
|
const getItemOrderedChildrenIds = React.useCallback(itemId => state.items.itemOrderedChildrenIds[itemId ?? TREE_VIEW_ROOT_PARENT_ID] ?? [], [state.items.itemOrderedChildrenIds]);
|
|
95
|
+
const getItemDOMElement = itemId => {
|
|
96
|
+
const itemMeta = instance.getItemMeta(itemId);
|
|
97
|
+
if (itemMeta == null) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
return document.getElementById(instance.getTreeItemIdAttribute(itemId, itemMeta.idAttribute));
|
|
101
|
+
};
|
|
95
102
|
const isItemNavigable = itemId => {
|
|
96
103
|
if (params.disabledItemsFocusable) {
|
|
97
104
|
return true;
|
|
@@ -145,13 +152,15 @@ export const useTreeViewItems = ({
|
|
|
145
152
|
}
|
|
146
153
|
}),
|
|
147
154
|
publicAPI: {
|
|
148
|
-
getItem
|
|
155
|
+
getItem,
|
|
156
|
+
getItemDOMElement
|
|
149
157
|
},
|
|
150
158
|
instance: {
|
|
151
159
|
getItemMeta,
|
|
152
160
|
getItem,
|
|
153
161
|
getItemsToRender,
|
|
154
162
|
getItemIndex,
|
|
163
|
+
getItemDOMElement,
|
|
155
164
|
getItemOrderedChildrenIds,
|
|
156
165
|
isItemDisabled,
|
|
157
166
|
isItemNavigable,
|
|
@@ -10,10 +10,16 @@ export interface UseTreeViewItemsPublicAPI<R extends {}> {
|
|
|
10
10
|
/**
|
|
11
11
|
* Get the item with the given id.
|
|
12
12
|
* When used in the `SimpleTreeView`, it returns an object with the `id` and `label` properties.
|
|
13
|
-
* @param {string} itemId The id of the item to
|
|
13
|
+
* @param {string} itemId The id of the item to retrieve.
|
|
14
14
|
* @returns {R} The item with the given id.
|
|
15
15
|
*/
|
|
16
16
|
getItem: (itemId: TreeViewItemId) => R;
|
|
17
|
+
/**
|
|
18
|
+
* Get the DOM element of the item with the given id.
|
|
19
|
+
* @param {TreeViewItemId} itemId The id of the item to get the DOM element of.
|
|
20
|
+
* @returns {HTMLElement | null} The DOM element of the item with the given id.
|
|
21
|
+
*/
|
|
22
|
+
getItemDOMElement: (itemId: TreeViewItemId) => HTMLElement | null;
|
|
17
23
|
}
|
|
18
24
|
export interface UseTreeViewItemsInstance<R extends {}> extends UseTreeViewItemsPublicAPI<R> {
|
|
19
25
|
/**
|
|
@@ -74,10 +74,13 @@ export const useTreeViewKeyboardNavigation = ({
|
|
|
74
74
|
event.preventDefault();
|
|
75
75
|
if (params.multiSelect && event.shiftKey) {
|
|
76
76
|
instance.expandSelectionRange(event, itemId);
|
|
77
|
-
} else if (params.multiSelect) {
|
|
78
|
-
instance.selectItem(event, itemId, true);
|
|
79
77
|
} else {
|
|
80
|
-
instance.selectItem(
|
|
78
|
+
instance.selectItem({
|
|
79
|
+
event,
|
|
80
|
+
itemId,
|
|
81
|
+
keepExistingSelection: params.multiSelect,
|
|
82
|
+
shouldBeSelected: params.multiSelect ? undefined : true
|
|
83
|
+
});
|
|
81
84
|
}
|
|
82
85
|
break;
|
|
83
86
|
}
|
|
@@ -92,9 +95,16 @@ export const useTreeViewKeyboardNavigation = ({
|
|
|
92
95
|
} else if (canToggleItemSelection(itemId)) {
|
|
93
96
|
if (params.multiSelect) {
|
|
94
97
|
event.preventDefault();
|
|
95
|
-
instance.selectItem(
|
|
98
|
+
instance.selectItem({
|
|
99
|
+
event,
|
|
100
|
+
itemId,
|
|
101
|
+
keepExistingSelection: true
|
|
102
|
+
});
|
|
96
103
|
} else if (!instance.isItemSelected(itemId)) {
|
|
97
|
-
instance.selectItem(
|
|
104
|
+
instance.selectItem({
|
|
105
|
+
event,
|
|
106
|
+
itemId
|
|
107
|
+
});
|
|
98
108
|
event.preventDefault();
|
|
99
109
|
}
|
|
100
110
|
}
|
|
@@ -46,7 +46,12 @@ export const useTreeViewSelection = ({
|
|
|
46
46
|
models.selectedItems.setControlledValue(newSelectedItems);
|
|
47
47
|
};
|
|
48
48
|
const isItemSelected = itemId => selectedItemsMap.has(itemId);
|
|
49
|
-
const selectItem = (
|
|
49
|
+
const selectItem = ({
|
|
50
|
+
event,
|
|
51
|
+
itemId,
|
|
52
|
+
keepExistingSelection = false,
|
|
53
|
+
shouldBeSelected
|
|
54
|
+
}) => {
|
|
50
55
|
if (params.disableSelection) {
|
|
51
56
|
return;
|
|
52
57
|
}
|
|
@@ -54,16 +59,16 @@ export const useTreeViewSelection = ({
|
|
|
54
59
|
if (keepExistingSelection) {
|
|
55
60
|
const cleanSelectedItems = convertSelectedItemsToArray(models.selectedItems.value);
|
|
56
61
|
const isSelectedBefore = instance.isItemSelected(itemId);
|
|
57
|
-
if (isSelectedBefore && (
|
|
62
|
+
if (isSelectedBefore && (shouldBeSelected === false || shouldBeSelected == null)) {
|
|
58
63
|
newSelected = cleanSelectedItems.filter(id => id !== itemId);
|
|
59
|
-
} else if (!isSelectedBefore && (
|
|
64
|
+
} else if (!isSelectedBefore && (shouldBeSelected === true || shouldBeSelected == null)) {
|
|
60
65
|
newSelected = [itemId].concat(cleanSelectedItems);
|
|
61
66
|
} else {
|
|
62
67
|
newSelected = cleanSelectedItems;
|
|
63
68
|
}
|
|
64
69
|
} else {
|
|
65
70
|
// eslint-disable-next-line no-lonely-if
|
|
66
|
-
if (
|
|
71
|
+
if (shouldBeSelected === false || shouldBeSelected == null && instance.isItemSelected(itemId)) {
|
|
67
72
|
newSelected = params.multiSelect ? [] : null;
|
|
68
73
|
} else {
|
|
69
74
|
newSelected = params.multiSelect ? [itemId] : itemId;
|
|
@@ -142,6 +147,9 @@ export const useTreeViewSelection = ({
|
|
|
142
147
|
getRootProps: () => ({
|
|
143
148
|
'aria-multiselectable': params.multiSelect
|
|
144
149
|
}),
|
|
150
|
+
publicAPI: {
|
|
151
|
+
selectItem
|
|
152
|
+
},
|
|
145
153
|
instance: {
|
|
146
154
|
isItemSelected,
|
|
147
155
|
selectItem,
|
|
@@ -2,47 +2,55 @@ import * as React from 'react';
|
|
|
2
2
|
import type { DefaultizedProps, TreeViewPluginSignature } from '../../models';
|
|
3
3
|
import { UseTreeViewItemsSignature } from '../useTreeViewItems';
|
|
4
4
|
import { UseTreeViewExpansionSignature } from '../useTreeViewExpansion';
|
|
5
|
-
export interface
|
|
5
|
+
export interface UseTreeViewSelectionPublicAPI {
|
|
6
|
+
/**
|
|
7
|
+
* Select or deselect an item.
|
|
8
|
+
* @param {object} params The params of the method.
|
|
9
|
+
* @param {React.SyntheticEvent} params.event The DOM event that triggered the change.
|
|
10
|
+
* @param {string} params.itemId The id of the item to select or deselect.
|
|
11
|
+
* @param {boolean} params.keepExistingSelection If `true`, the other already selected items will remain selected, otherwise, they will be deselected. This parameter is only relevant when `multiSelect` is `true`
|
|
12
|
+
* @param {boolean | undefined} params.shouldBeSelected If `true` the item will be selected. If `false` the item will be deselected. If not defined, the item's new selection status will be the opposite of its current one.
|
|
13
|
+
*/
|
|
14
|
+
selectItem: (params: {
|
|
15
|
+
event: React.SyntheticEvent;
|
|
16
|
+
itemId: string;
|
|
17
|
+
keepExistingSelection?: boolean;
|
|
18
|
+
shouldBeSelected?: boolean;
|
|
19
|
+
}) => void;
|
|
20
|
+
}
|
|
21
|
+
export interface UseTreeViewSelectionInstance extends UseTreeViewSelectionPublicAPI {
|
|
6
22
|
/**
|
|
7
23
|
* Check if an item is selected.
|
|
8
24
|
* @param {TreeViewItemId} itemId The id of the item to check.
|
|
9
25
|
* @returns {boolean} `true` if the item is selected, `false` otherwise.
|
|
10
26
|
*/
|
|
11
27
|
isItemSelected: (itemId: string) => boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Select or deselect an item.
|
|
14
|
-
* @param {React.SyntheticEvent} event The event source of the callback.
|
|
15
|
-
* @param {string} itemId The id of the item to select or deselect.
|
|
16
|
-
* @param {boolean} keepExistingSelection If `true`, don't remove the other selected items.
|
|
17
|
-
* @param {boolean | undefined} newValue The new selection status of the item. If not defined, the new state will be the opposite of the current state.
|
|
18
|
-
*/
|
|
19
|
-
selectItem: (event: React.SyntheticEvent, itemId: string, keepExistingSelection: boolean, newValue?: boolean) => void;
|
|
20
28
|
/**
|
|
21
29
|
* Select all the navigable items in the tree.
|
|
22
|
-
* @param {React.SyntheticEvent} event The event
|
|
30
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
23
31
|
*/
|
|
24
32
|
selectAllNavigableItems: (event: React.SyntheticEvent) => void;
|
|
25
33
|
/**
|
|
26
34
|
* Expand the current selection range up to the given item.
|
|
27
|
-
* @param {React.SyntheticEvent} event The event
|
|
35
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
28
36
|
* @param {string} itemId The id of the item to expand the selection to.
|
|
29
37
|
*/
|
|
30
38
|
expandSelectionRange: (event: React.SyntheticEvent, itemId: string) => void;
|
|
31
39
|
/**
|
|
32
40
|
* Expand the current selection range from the first navigable item to the given item.
|
|
33
|
-
* @param {React.SyntheticEvent} event The event
|
|
41
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
34
42
|
* @param {string} itemId The id of the item up to which the selection range should be expanded.
|
|
35
43
|
*/
|
|
36
44
|
selectRangeFromStartToItem: (event: React.SyntheticEvent, itemId: string) => void;
|
|
37
45
|
/**
|
|
38
46
|
* Expand the current selection range from the given item to the last navigable item.
|
|
39
|
-
* @param {React.SyntheticEvent} event The event
|
|
47
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
40
48
|
* @param {string} itemId The id of the item from which the selection range should be expanded.
|
|
41
49
|
*/
|
|
42
50
|
selectRangeFromItemToEnd: (event: React.SyntheticEvent, itemId: string) => void;
|
|
43
51
|
/**
|
|
44
52
|
* Update the selection when navigating with ArrowUp / ArrowDown keys.
|
|
45
|
-
* @param {React.SyntheticEvent} event The event
|
|
53
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
46
54
|
* @param {string} currentItemId The id of the active item before the keyboard navigation.
|
|
47
55
|
* @param {string} nextItemId The id of the active item after the keyboard navigation.
|
|
48
56
|
*/
|
|
@@ -78,14 +86,14 @@ export interface UseTreeViewSelectionParameters<Multiple extends boolean | undef
|
|
|
78
86
|
checkboxSelection?: boolean;
|
|
79
87
|
/**
|
|
80
88
|
* Callback fired when tree items are selected/deselected.
|
|
81
|
-
* @param {React.SyntheticEvent} event The event
|
|
89
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
82
90
|
* @param {string[] | string} itemIds The ids of the selected items.
|
|
83
91
|
* When `multiSelect` is `true`, this is an array of strings; when false (default) a string.
|
|
84
92
|
*/
|
|
85
93
|
onSelectedItemsChange?: (event: React.SyntheticEvent, itemIds: TreeViewSelectionValue<Multiple>) => void;
|
|
86
94
|
/**
|
|
87
95
|
* Callback fired when a tree item is selected or deselected.
|
|
88
|
-
* @param {React.SyntheticEvent} event The event
|
|
96
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
89
97
|
* @param {array} itemId The itemId of the modified item.
|
|
90
98
|
* @param {array} isSelected `true` if the item has just been selected, `false` if it has just been deselected.
|
|
91
99
|
*/
|
|
@@ -99,6 +107,7 @@ export type UseTreeViewSelectionSignature = TreeViewPluginSignature<{
|
|
|
99
107
|
params: UseTreeViewSelectionParameters<any>;
|
|
100
108
|
defaultizedParams: UseTreeViewSelectionDefaultizedParameters<any>;
|
|
101
109
|
instance: UseTreeViewSelectionInstance;
|
|
110
|
+
publicAPI: UseTreeViewSelectionPublicAPI;
|
|
102
111
|
contextValue: UseTreeViewSelectionContextValue;
|
|
103
112
|
modelNames: 'selectedItems';
|
|
104
113
|
dependencies: [
|
|
@@ -137,6 +137,8 @@ process.env.NODE_ENV !== "production" ? RichTreeView.propTypes = {
|
|
|
137
137
|
current: PropTypes.shape({
|
|
138
138
|
focusItem: PropTypes.func.isRequired,
|
|
139
139
|
getItem: PropTypes.func.isRequired,
|
|
140
|
+
getItemDOMElement: PropTypes.func.isRequired,
|
|
141
|
+
selectItem: PropTypes.func.isRequired,
|
|
140
142
|
setItemExpansion: PropTypes.func.isRequired
|
|
141
143
|
})
|
|
142
144
|
}),
|
|
@@ -234,34 +236,34 @@ process.env.NODE_ENV !== "production" ? RichTreeView.propTypes = {
|
|
|
234
236
|
multiSelect: PropTypes.bool,
|
|
235
237
|
/**
|
|
236
238
|
* Callback fired when tree items are expanded/collapsed.
|
|
237
|
-
* @param {React.SyntheticEvent} event The event
|
|
239
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
238
240
|
* @param {array} itemIds The ids of the expanded items.
|
|
239
241
|
*/
|
|
240
242
|
onExpandedItemsChange: PropTypes.func,
|
|
241
243
|
/**
|
|
242
244
|
* Callback fired when a tree item is expanded or collapsed.
|
|
243
|
-
* @param {React.SyntheticEvent} event The event
|
|
245
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
244
246
|
* @param {array} itemId The itemId of the modified item.
|
|
245
247
|
* @param {array} isExpanded `true` if the item has just been expanded, `false` if it has just been collapsed.
|
|
246
248
|
*/
|
|
247
249
|
onItemExpansionToggle: PropTypes.func,
|
|
248
250
|
/**
|
|
249
251
|
* Callback fired when tree items are focused.
|
|
250
|
-
* @param {React.SyntheticEvent} event The event
|
|
252
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change. **Warning**: This is a generic event not a focus event.
|
|
251
253
|
* @param {string} itemId The id of the focused item.
|
|
252
254
|
* @param {string} value of the focused item.
|
|
253
255
|
*/
|
|
254
256
|
onItemFocus: PropTypes.func,
|
|
255
257
|
/**
|
|
256
258
|
* Callback fired when a tree item is selected or deselected.
|
|
257
|
-
* @param {React.SyntheticEvent} event The event
|
|
259
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
258
260
|
* @param {array} itemId The itemId of the modified item.
|
|
259
261
|
* @param {array} isSelected `true` if the item has just been selected, `false` if it has just been deselected.
|
|
260
262
|
*/
|
|
261
263
|
onItemSelectionToggle: PropTypes.func,
|
|
262
264
|
/**
|
|
263
265
|
* Callback fired when tree items are selected/deselected.
|
|
264
|
-
* @param {React.SyntheticEvent} event The event
|
|
266
|
+
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
265
267
|
* @param {string[] | string} itemIds The ids of the selected items.
|
|
266
268
|
* When `multiSelect` is `true`, this is an array of strings; when false (default) a string.
|
|
267
269
|
*/
|