@mui/x-tree-view 7.0.0-beta.4 → 7.0.0-beta.5

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 (54) hide show
  1. package/CHANGELOG.md +138 -14
  2. package/RichTreeView/RichTreeView.js +8 -0
  3. package/RichTreeView/RichTreeView.types.d.ts +7 -1
  4. package/SimpleTreeView/SimpleTreeView.js +8 -0
  5. package/SimpleTreeView/SimpleTreeView.types.d.ts +7 -1
  6. package/TreeView/TreeView.js +8 -0
  7. package/hooks/index.d.ts +1 -0
  8. package/hooks/index.js +1 -0
  9. package/hooks/package.json +6 -0
  10. package/hooks/useTreeViewApiRef.d.ts +6 -0
  11. package/hooks/useTreeViewApiRef.js +5 -0
  12. package/index.d.ts +1 -0
  13. package/index.js +3 -2
  14. package/internals/hooks/useTimeout.d.ts +5 -3
  15. package/internals/hooks/useTimeout.js +13 -5
  16. package/internals/models/helpers.d.ts +1 -0
  17. package/internals/models/plugin.d.ts +12 -0
  18. package/internals/models/treeView.d.ts +1 -0
  19. package/internals/plugins/useTreeViewFocus/useTreeViewFocus.js +40 -22
  20. package/internals/plugins/useTreeViewFocus/useTreeViewFocus.types.d.ts +5 -0
  21. package/internals/useTreeView/useTreeView.d.ts +2 -0
  22. package/internals/useTreeView/useTreeView.js +12 -0
  23. package/internals/useTreeView/useTreeView.types.d.ts +2 -1
  24. package/internals/useTreeView/useTreeView.utils.d.ts +2 -1
  25. package/internals/useTreeView/useTreeView.utils.js +3 -0
  26. package/internals/utils/extractPluginParamsFromProps.d.ts +3 -2
  27. package/internals/utils/extractPluginParamsFromProps.js +5 -3
  28. package/internals/utils/utils.d.ts +1 -0
  29. package/internals/utils/utils.js +10 -0
  30. package/modern/RichTreeView/RichTreeView.js +8 -0
  31. package/modern/SimpleTreeView/SimpleTreeView.js +8 -0
  32. package/modern/TreeView/TreeView.js +8 -0
  33. package/modern/hooks/index.js +1 -0
  34. package/modern/hooks/useTreeViewApiRef.js +5 -0
  35. package/modern/index.js +3 -2
  36. package/modern/internals/hooks/useTimeout.js +13 -5
  37. package/modern/internals/plugins/useTreeViewFocus/useTreeViewFocus.js +40 -22
  38. package/modern/internals/useTreeView/useTreeView.js +12 -0
  39. package/modern/internals/useTreeView/useTreeView.utils.js +3 -0
  40. package/modern/internals/utils/extractPluginParamsFromProps.js +5 -3
  41. package/modern/internals/utils/utils.js +10 -0
  42. package/node/RichTreeView/RichTreeView.js +8 -0
  43. package/node/SimpleTreeView/SimpleTreeView.js +8 -0
  44. package/node/TreeView/TreeView.js +8 -0
  45. package/node/hooks/index.js +12 -0
  46. package/node/hooks/useTreeViewApiRef.js +14 -0
  47. package/node/index.js +13 -1
  48. package/node/internals/hooks/useTimeout.js +13 -4
  49. package/node/internals/plugins/useTreeViewFocus/useTreeViewFocus.js +39 -21
  50. package/node/internals/useTreeView/useTreeView.js +13 -0
  51. package/node/internals/useTreeView/useTreeView.utils.js +6 -2
  52. package/node/internals/utils/extractPluginParamsFromProps.js +5 -3
  53. package/node/internals/utils/utils.js +17 -0
  54. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -3,6 +3,89 @@
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.0.0-beta.5
7
+
8
+ _Mar 1, 2024_
9
+
10
+ We'd like to offer a big thanks to the 15 contributors who made this release possible. Here are some highlights ✨:
11
+
12
+ - 🎁 Add `getSortComparator` for more advanced sorting behaviors (#12215) @cherniavskii
13
+ - 🚀 Add `use client` directive to the Grid packages (#11803) @MBilalShafi
14
+ - 🌍 Improve Korean (ko-KR) and Chinese (zh-CN) locales on the Pickers
15
+ - 🐞 Bugfixes
16
+ - 📚 Documentation improvements
17
+
18
+ ### Data Grid
19
+
20
+ #### `@mui/x-data-grid@7.0.0-beta.5`
21
+
22
+ - [DataGrid] Add `getSortComparator` for more advanced sorting behaviors (#12215) @cherniavskii
23
+ - [DataGrid] Add `use client` directive to the Grid packages (#11803) @MBilalShafi
24
+ - [DataGrid] Fix `disableResetButton` and `disableShowHideToggle` flags to not exclude each other (#12169) @adyry
25
+ - [DataGrid] Fix cell range classnames (#12230) @romgrk
26
+ - [DataGrid] Fix wrong offset for right-pinned columns when toggling dark/light modes (#12233) @cherniavskii
27
+ - [DataGrid] Improve row virtualization and rendering performance (#12247) @romgrk
28
+ - [DataGrid] Improve performance by removing `querySelector` call (#12229) @romgrk
29
+ - [DataGrid] Fix `onColumnWidthChange` called before autosize affects column width (#12140) @shaharyar-shamshi
30
+ - [DataGrid] Fix boolean "is" filter (#12117) @shaharyar-shamshi
31
+ - [DataGrid] Fix `upsertFilterItems` removing filters that are not part of the update (#11954) @gitstart
32
+ - [DataGrid] Render scrollbars only if there is scroll (#12265) @cherniavskii
33
+
34
+ #### `@mui/x-data-grid-pro@7.0.0-beta.5` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
35
+
36
+ Same changes as in `@mui/x-data-grid@7.0.0-beta.5`, plus:
37
+
38
+ - [DataGridPro] Fix column resize errors on MacOS with automatic scrollbars enabled (#12217) @cherniavskii
39
+ - [DataGridPro] Fix lazy-loading crash (#12080) @romgrk
40
+ - [DataGridPro] Fix useGridRows not giving error on reversed data (#10821) @martijn-basesoft
41
+
42
+ #### `@mui/x-data-grid-premium@7.0.0-beta.5` [![premium](https://mui.com/r/x-premium-svg)](https://mui.com/r/x-premium-svg-link 'Premium plan')
43
+
44
+ Same changes as in `@mui/x-data-grid-pro@7.0.0-beta.5`, plus:
45
+
46
+ - [DataGridPremium] Make clipboard copy respect the sorting during cell selection (#12235) @MBilalShafi
47
+
48
+ ### Date Pickers
49
+
50
+ #### `@mui/x-date-pickers@7.0.0-beta.5`
51
+
52
+ - [pickers] Fix toolbar components props handling (#12211) @LukasTy
53
+ - [l10n] Improve Chinese (zh-CN) locale (#12245) @headironc
54
+ - [l10n] Improve Korean (ko-KR) locale (#12192) @Luzi
55
+
56
+ #### `@mui/x-date-pickers-pro@7.0.0-beta.5` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
57
+
58
+ Same changes as in `@mui/x-date-pickers@7.0.0-beta.5`.
59
+
60
+ - [DateTimeRangePicker] Fix validation behavior (#12243) @LukasTy
61
+
62
+ ### Charts / `@mui/x-charts@7.0.0-beta.5`
63
+
64
+ - [charts] Fix grid duplicated key (#12208) @alexfauquette
65
+
66
+ ### Tree View / `@mui/x-tree-view@7.0.0-beta.5`
67
+
68
+ - [TreeView] Add public API and expose focus method (#12143) @noraleonte
69
+
70
+ ### Docs
71
+
72
+ - [docs] Fix image layout shift when loading @oliviertassinari
73
+ - [docs] Match Material UI repo comment for redirections @oliviertassinari
74
+ - [docs] Non breaking spaces @oliviertassinari
75
+ - [docs] Polish the Date Picker playground (#11869) @zanivan
76
+ - [docs] Standardize WAI-ARIA references @oliviertassinari
77
+
78
+ ### Core
79
+
80
+ - [core] Allow local docs next.js settings (#12227) @romgrk
81
+ - [core] Remove grid folder from `getComponentInfo` RegExp (#12241) @flaviendelangle
82
+ - [core] Remove `window.` reference for common globals @oliviertassinari
83
+ - [core] Use runtime agnostic setTimeout type @oliviertassinari
84
+ - [docs-infra] Fix Stack Overflow breaking space @oliviertassinari
85
+ - [docs-infra] Fix missing non breaking spaces @oliviertassinari
86
+ - [github] Update `no-response` workflow (#12193) @MBilalShafi
87
+ - [infra] Fix missing permission reset @oliviertassinari
88
+
6
89
  ## 7.0.0-beta.4
7
90
 
8
91
  _Feb 23, 2024_
@@ -49,7 +132,7 @@ Same changes as in `@mui/x-data-grid-pro@7.0.0-beta.4`.
49
132
  <DateField
50
133
  - selectedSections={{ startIndex: 0, endIndex: 0 }}
51
134
  + selectedSections={0}
52
-
135
+
53
136
  // If the field has 3 sections
54
137
  - selectedSections={{ startIndex: 0, endIndex: 2 }}
55
138
  + selectedSections="all"
@@ -68,20 +151,20 @@ Same changes as in `@mui/x-data-grid-pro@7.0.0-beta.4`.
68
151
  + enableAccessibleFieldDOMStructure,
69
152
  // ... rest of the props you are using
70
153
  } = props;
71
-
154
+
72
155
  return ( /* Some UI to edit the date */ )
73
156
  }
74
-
157
+
75
158
  function MyCustomField(props) {
76
159
  const fieldResponse = useDateField<Dayjs, false, typeof textFieldProps>({
77
160
  ...props,
78
161
  + // If you only support one DOM structure, we advise you to hardcode it here to avoid unwanted switches in your application
79
162
  + enableAccessibleFieldDOMStructure: false,
80
163
  });
81
-
164
+
82
165
  return <MyCustomTextField ref={ref} {...fieldResponse} />;
83
166
  }
84
-
167
+
85
168
  function App() {
86
169
  return <DatePicker slots={{ field: MyCustomField }} />;
87
170
  }
@@ -2352,6 +2435,47 @@ Here is an example of the renaming for the `<ChartsTooltip />` component.
2352
2435
  - [core] Update release instructions as per v7 configuration (#10962) @MBilalShafi
2353
2436
  - [license] Correctly throw errors (#10924) @oliviertassinari
2354
2437
 
2438
+ ## 6.19.6
2439
+
2440
+ _Mar 1, 2024_
2441
+
2442
+ We'd like to offer a big thanks to the 4 contributors who made this release possible. Here are some highlights ✨:
2443
+
2444
+ - 🌍 Improve Korean (ko-KR) and Chinese (zh-CN) locales on the Pickers
2445
+ - 🐞 Bugfixes
2446
+ - 📚 Documentation improvements
2447
+
2448
+ ### Data Grid
2449
+
2450
+ #### `@mui/x-data-grid@6.19.6`
2451
+
2452
+ - [DataGrid] Fix error when existing rows are passed to `replaceRows` (@martijn-basesoft)
2453
+
2454
+ #### `@mui/x-data-grid-pro@6.19.6` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
2455
+
2456
+ Same changes as in `@mui/x-data-grid@6.19.6`.
2457
+
2458
+ #### `@mui/x-data-grid-premium@6.19.6` [![premium](https://mui.com/r/x-premium-svg)](https://mui.com/r/x-premium-svg-link 'Premium plan')
2459
+
2460
+ Same changes as in `@mui/x-data-grid-pro@6.19.6`, plus:
2461
+
2462
+ - [DataGridPremium] Make clipboard copy respect the sorting during cell selection (#12255) @MBilalShafi
2463
+
2464
+ ### Date Pickers
2465
+
2466
+ #### `@mui/x-date-pickers@6.19.6`
2467
+
2468
+ - [l10n] Improve Chinese (zh-CN) locale (#12250) @headironc
2469
+ - [l10n] Improve Korean (ko-KR) locale (#12186) @Luzi
2470
+
2471
+ #### `@mui/x-date-pickers-pro@6.19.6` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
2472
+
2473
+ Same changes as in `@mui/x-date-pickers@6.19.6`.
2474
+
2475
+ ### Docs
2476
+
2477
+ - [docs] Update lazy loading demo to show skeleton rows during initial rows fetch (#12062) @cherniavskii
2478
+
2355
2479
  ## 6.19.5
2356
2480
 
2357
2481
  _Feb 23, 2024_
@@ -2394,8 +2518,8 @@ Same changes as in `@mui/x-date-pickers@6.19.5`.
2394
2518
 
2395
2519
  - [docs] Clarify Pickers 'Component composition' section (#12147) @LukasTy
2396
2520
  - [docs] Fix 301 redirection to StackBlitz @oliviertassinari
2397
- - [docs] Fix 301 to Material UI @oliviertassinari
2398
- - [docs] Fix 301 to Material UI @oliviertassinari
2521
+ - [docs] Fix 301 to Material UI @oliviertassinari
2522
+ - [docs] Fix 301 to Material UI @oliviertassinari
2399
2523
  - [docs] Fix 404 links to translation source @oliviertassinari
2400
2524
  - [docs] Fix dead link to translations @oliviertassinari
2401
2525
  - [docs] Fix the Treemap illustration (#12189) @danilo-leal
@@ -4264,7 +4388,7 @@ We'd like to offer a big thanks to the 13 contributors who made this release pos
4264
4388
 
4265
4389
  #### `@mui/x-data-grid@6.9.1`
4266
4390
 
4267
- - [DataGrid] Add Joy UI `tooltip` and `loadingOverlay` slots (#9028) @cherniavskii
4391
+ - [DataGrid] Add Joy UI `tooltip` and `loadingOverlay` slots (#9028) @cherniavskii
4268
4392
  - [DataGrid] Add section about enabling pagination on Pro and Premium (#8759) @joserodolfofreitas
4269
4393
  - [DataGrid] Don't forward `editCellState` prop to DOM element (#9501) @m4theushw
4270
4394
  - [DataGrid] Add experimental API for faster filtering performance (#9254) @romgrk
@@ -4395,7 +4519,7 @@ Same changes as in `@mui/x-date-pickers@6.9.0`.
4395
4519
  - [docs] Fix random screenshot generation (#9364) @cherniavskii
4396
4520
  - [docs] Remove random generation from chart doc example (#9343) @flaviendelangle
4397
4521
  - [docs] Sync h1 with sidenav link (#9252) @oliviertassinari
4398
- - [docs] Use the mui-x Stack Overflow tag (#9352) @oliviertassinari
4522
+ - [docs] Use the mui-x Stack Overflow tag (#9352) @oliviertassinari
4399
4523
 
4400
4524
  ### Core
4401
4525
 
@@ -4722,8 +4846,8 @@ We'd like to offer a big thanks to the 12 contributors who made this release pos
4722
4846
 
4723
4847
  - [DataGrid] Fix DataGrid rendering in JSDOM (#8968) @cherniavskii
4724
4848
  - [DataGrid] Fix layout when rendered inside a parent with `display: grid` (#8577) @cherniavskii
4725
- - [DataGrid] Add Joy UI icon slots (#8940) @siriwatknp
4726
- - [DataGrid] Add Joy UI pagination slot (#8871) @cherniavskii
4849
+ - [DataGrid] Add Joy UI icon slots (#8940) @siriwatknp
4850
+ - [DataGrid] Add Joy UI pagination slot (#8871) @cherniavskii
4727
4851
  - [DataGrid] Extract `baseChip` slot (#8748) @cherniavskii
4728
4852
  - [DataGridPremium] Implement Clipboard import (#7389) @cherniavskii
4729
4853
  - [l10n] Improve French (fr-FR) locale (#8825) @allereaugabriel
@@ -4773,7 +4897,7 @@ We'd like to offer a big thanks to the 7 contributors who made this release poss
4773
4897
  - [DataGrid] Fix falsy filter values not showing in filter button tooltip (#8550) @ithrforu
4774
4898
  - [DataGrid] Fix missing watermark in Pro and Premium packages (#8797) @cherniavskii
4775
4899
  - [DataGrid] Remove unwarranted warning log (#8847) @romgrk
4776
- - [DataGrid] Add Joy UI slots (`Select`, `SelectOption`, `InputLabel`, `FormControl`) (#8747) @cherniavskii
4900
+ - [DataGrid] Add Joy UI slots (`Select`, `SelectOption`, `InputLabel`, `FormControl`) (#8747) @cherniavskii
4777
4901
  - [DataGridPremium] Fix expanded groups being collapsed after calling `updateRows` (#8823) @cherniavskii
4778
4902
 
4779
4903
  ### `@mui/x-date-pickers@6.3.1` / `@mui/x-date-pickers-pro@6.3.1`
@@ -4824,7 +4948,7 @@ We'd like to offer a big thanks to the 15 contributors who made this release pos
4824
4948
  - [DataGrid] Add overlay classes to `gridClasses` (#8686) @lindapaiste
4825
4949
  - [DataGrid] Avoid passing `api` prop to div (#8679) @someden
4826
4950
  - [DataGrid] Fix 'ResizeObserver loop limit exceeded' error (#8744) @m4theushw
4827
- - [DataGrid] Add Joy UI slots (button and switch) (#8699) @siriwatknp
4951
+ - [DataGrid] Add Joy UI slots (button and switch) (#8699) @siriwatknp
4828
4952
  - [DataGrid] Fix aggregation label alignment (#8694) @joserodolfofreitas
4829
4953
  - [DataGridPremium] Fix infinite loop when updating grouped rows (#8693) @cherniavskii
4830
4954
  - [DataGridPro] Fix error after updating `columns` and `columnGroupingModel` at once (#8730) @cherniavskii
@@ -4886,7 +5010,7 @@ We'd like to offer a big thanks to the 9 contributors who made this release poss
4886
5010
  #### Changes
4887
5011
 
4888
5012
  - [DataGrid] Add `getTogglableColumns` to `Hide all` and `Show all` actions (#8496) @MBilalShafi
4889
- - [DataGrid] Add Grid + Joy UI experiment page (#8067) @cherniavskii
5013
+ - [DataGrid] Add Grid + Joy UI experiment page (#8067) @cherniavskii
4890
5014
  - [DataGrid] Fix print style when rendering inside Shadow DOM (#8656) @Bwatermelon
4891
5015
  - [DataGrid] Replace `GridAutoSizer` with `ResizeObserver` (#8091) @m4theushw
4892
5016
  - [DataGrid] Use stable ID for the placeholder filter item (#8603) @m4theushw
@@ -134,6 +134,14 @@ process.env.NODE_ENV !== "production" ? RichTreeView.propTypes = {
134
134
  // | These PropTypes are generated from the TypeScript type definitions |
135
135
  // | To update them edit the TypeScript types and run "yarn proptypes" |
136
136
  // ----------------------------------------------------------------------
137
+ /**
138
+ * The ref object that allows Tree View manipulation. Can be instantiated with `useTreeViewApiRef()`.
139
+ */
140
+ apiRef: PropTypes.shape({
141
+ current: PropTypes.shape({
142
+ focusNode: PropTypes.func.isRequired
143
+ })
144
+ }),
137
145
  /**
138
146
  * Override or extend the styles applied to the component.
139
147
  */
@@ -3,9 +3,10 @@ import { Theme } from '@mui/material/styles';
3
3
  import { SxProps } from '@mui/system';
4
4
  import { SlotComponentProps } from '@mui/base/utils';
5
5
  import { RichTreeViewClasses } from './richTreeViewClasses';
6
- import { DefaultTreeViewPluginParameters, DefaultTreeViewPluginSlotProps, DefaultTreeViewPluginSlots } from '../internals/plugins/defaultPlugins';
6
+ import { DefaultTreeViewPluginParameters, DefaultTreeViewPluginSlotProps, DefaultTreeViewPluginSlots, DefaultTreeViewPlugins } from '../internals/plugins/defaultPlugins';
7
7
  import { TreeItem, TreeItemProps } from '../TreeItem';
8
8
  import { TreeViewItemId } from '../models';
9
+ import { TreeViewPublicAPI } from '../internals/models';
9
10
  interface RichTreeViewItemSlotOwnerState {
10
11
  nodeId: TreeViewItemId;
11
12
  label: string;
@@ -26,6 +27,7 @@ export interface RichTreeViewSlotProps<R extends {}, Multiple extends boolean |
26
27
  root?: SlotComponentProps<'ul', {}, RichTreeViewProps<R, Multiple>>;
27
28
  item?: SlotComponentProps<typeof TreeItem, {}, RichTreeViewItemSlotOwnerState>;
28
29
  }
30
+ export type RichTreeViewApiRef = React.MutableRefObject<TreeViewPublicAPI<DefaultTreeViewPlugins> | undefined>;
29
31
  export interface RichTreeViewPropsBase extends React.HTMLAttributes<HTMLUListElement> {
30
32
  className?: string;
31
33
  /**
@@ -48,5 +50,9 @@ export interface RichTreeViewProps<R extends {}, Multiple extends boolean | unde
48
50
  * @default {}
49
51
  */
50
52
  slotProps?: RichTreeViewSlotProps<R, Multiple>;
53
+ /**
54
+ * The ref object that allows Tree View manipulation. Can be instantiated with `useTreeViewApiRef()`.
55
+ */
56
+ apiRef?: RichTreeViewApiRef;
51
57
  }
52
58
  export {};
@@ -91,6 +91,14 @@ process.env.NODE_ENV !== "production" ? SimpleTreeView.propTypes = {
91
91
  // | These PropTypes are generated from the TypeScript type definitions |
92
92
  // | To update them edit the TypeScript types and run "yarn proptypes" |
93
93
  // ----------------------------------------------------------------------
94
+ /**
95
+ * The ref object that allows Tree View manipulation. Can be instantiated with `useTreeViewApiRef()`.
96
+ */
97
+ apiRef: PropTypes.shape({
98
+ current: PropTypes.shape({
99
+ focusNode: PropTypes.func.isRequired
100
+ })
101
+ }),
94
102
  /**
95
103
  * The content of the component.
96
104
  */
@@ -3,7 +3,8 @@ import { Theme } from '@mui/material/styles';
3
3
  import { SlotComponentProps } from '@mui/base/utils';
4
4
  import { SxProps } from '@mui/system';
5
5
  import { SimpleTreeViewClasses } from './simpleTreeViewClasses';
6
- import { SimpleTreeViewPluginParameters, SimpleTreeViewPluginSlotProps, SimpleTreeViewPluginSlots } from './SimpleTreeView.plugins';
6
+ import { SimpleTreeViewPluginParameters, SimpleTreeViewPluginSlotProps, SimpleTreeViewPluginSlots, SimpleTreeViewPlugins } from './SimpleTreeView.plugins';
7
+ import { TreeViewPublicAPI } from '../internals/models';
7
8
  export interface SimpleTreeViewSlots extends SimpleTreeViewPluginSlots {
8
9
  /**
9
10
  * Element rendered at the root.
@@ -14,6 +15,7 @@ export interface SimpleTreeViewSlots extends SimpleTreeViewPluginSlots {
14
15
  export interface SimpleTreeViewSlotProps extends SimpleTreeViewPluginSlotProps {
15
16
  root?: SlotComponentProps<'ul', {}, {}>;
16
17
  }
18
+ export type SimpleTreeViewApiRef = React.MutableRefObject<TreeViewPublicAPI<SimpleTreeViewPlugins> | undefined>;
17
19
  export interface SimpleTreeViewProps<Multiple extends boolean | undefined> extends SimpleTreeViewPluginParameters<Multiple>, React.HTMLAttributes<HTMLUListElement> {
18
20
  /**
19
21
  * The content of the component.
@@ -36,4 +38,8 @@ export interface SimpleTreeViewProps<Multiple extends boolean | undefined> exten
36
38
  * The system prop that allows defining system overrides as well as additional CSS styles.
37
39
  */
38
40
  sx?: SxProps<Theme>;
41
+ /**
42
+ * The ref object that allows Tree View manipulation. Can be instantiated with `useTreeViewApiRef()`.
43
+ */
44
+ apiRef?: SimpleTreeViewApiRef;
39
45
  }
@@ -64,6 +64,14 @@ process.env.NODE_ENV !== "production" ? TreeView.propTypes = {
64
64
  // | These PropTypes are generated from the TypeScript type definitions |
65
65
  // | To update them edit the TypeScript types and run "yarn proptypes" |
66
66
  // ----------------------------------------------------------------------
67
+ /**
68
+ * The ref object that allows Tree View manipulation. Can be instantiated with `useTreeViewApiRef()`.
69
+ */
70
+ apiRef: PropTypes.shape({
71
+ current: PropTypes.shape({
72
+ focusNode: PropTypes.func.isRequired
73
+ })
74
+ }),
67
75
  /**
68
76
  * The content of the component.
69
77
  */
@@ -0,0 +1 @@
1
+ export { useTreeViewApiRef } from './useTreeViewApiRef';
package/hooks/index.js ADDED
@@ -0,0 +1 @@
1
+ export { useTreeViewApiRef } from './useTreeViewApiRef';
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "./index.js",
4
+ "main": "../node/hooks/index.js",
5
+ "types": "./index.d.ts"
6
+ }
@@ -0,0 +1,6 @@
1
+ import * as React from 'react';
2
+ import { TreeViewAnyPluginSignature, TreeViewUsedPublicAPI } from '../internals/models';
3
+ /**
4
+ * Hook that instantiates a [[TreeViewApiRef]].
5
+ */
6
+ export declare const useTreeViewApiRef: <T extends TreeViewAnyPluginSignature, Api extends TreeViewUsedPublicAPI<T>>() => React.MutableRefObject<Api>;
@@ -0,0 +1,5 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Hook that instantiates a [[TreeViewApiRef]].
4
+ */
5
+ export const useTreeViewApiRef = () => React.useRef(undefined);
package/index.d.ts CHANGED
@@ -5,3 +5,4 @@ export * from './RichTreeView';
5
5
  export { unstable_resetCleanupTracking } from './internals/hooks/useInstanceEventHandler';
6
6
  export * from './models';
7
7
  export * from './icons';
8
+ export * from './hooks';
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-tree-view v7.0.0-beta.4
2
+ * @mui/x-tree-view v7.0.0-beta.5
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -11,4 +11,5 @@ export * from './SimpleTreeView';
11
11
  export * from './RichTreeView';
12
12
  export { unstable_resetCleanupTracking } from './internals/hooks/useInstanceEventHandler';
13
13
  export * from './models';
14
- export * from './icons';
14
+ export * from './icons';
15
+ export * from './hooks';
@@ -1,9 +1,11 @@
1
- declare class Timeout {
1
+ export declare class Timeout {
2
2
  static create(): Timeout;
3
- currentId: number;
3
+ currentId: ReturnType<typeof setTimeout> | null;
4
+ /**
5
+ * Executes `fn` after `delay`, clearing any previously scheduled call.
6
+ */
4
7
  start(delay: number, fn: Function): void;
5
8
  clear: () => void;
6
9
  disposeEffect: () => () => void;
7
10
  }
8
11
  export declare function useTimeout(): Timeout;
9
- export {};
@@ -1,12 +1,14 @@
1
+ 'use client';
2
+
1
3
  import { useLazyRef } from './useLazyRef';
2
4
  import { useOnMount } from './useOnMount';
3
- class Timeout {
5
+ export class Timeout {
4
6
  constructor() {
5
- this.currentId = 0;
7
+ this.currentId = null;
6
8
  this.clear = () => {
7
- if (this.currentId !== 0) {
9
+ if (this.currentId !== null) {
8
10
  clearTimeout(this.currentId);
9
- this.currentId = 0;
11
+ this.currentId = null;
10
12
  }
11
13
  };
12
14
  this.disposeEffect = () => {
@@ -16,9 +18,15 @@ class Timeout {
16
18
  static create() {
17
19
  return new Timeout();
18
20
  }
21
+ /**
22
+ * Executes `fn` after `delay`, clearing any previously scheduled call.
23
+ */
19
24
  start(delay, fn) {
20
25
  this.clear();
21
- this.currentId = setTimeout(fn, delay);
26
+ this.currentId = setTimeout(() => {
27
+ this.currentId = null;
28
+ fn();
29
+ }, delay);
22
30
  }
23
31
  }
24
32
  export function useTimeout() {
@@ -7,6 +7,7 @@ export type ConvertPluginsIntoSignatures<TPlugins extends readonly any[]> = TPlu
7
7
  export interface MergePlugins<TPlugins extends readonly any[]> {
8
8
  state: MergePluginsProperty<TPlugins, 'state'>;
9
9
  instance: MergePluginsProperty<TPlugins, 'instance'>;
10
+ publicAPI: MergePluginsProperty<TPlugins, 'publicAPI'>;
10
11
  params: MergePluginsProperty<TPlugins, 'params'>;
11
12
  defaultizedParams: MergePluginsProperty<TPlugins, 'defaultizedParams'>;
12
13
  dependantPlugins: MergePluginsProperty<TPlugins, 'dependantPlugins'>;
@@ -7,6 +7,7 @@ import type { TreeViewCorePluginsSignature } from '../corePlugins';
7
7
  import type { TreeItemProps } from '../../TreeItem';
8
8
  export interface TreeViewPluginOptions<TSignature extends TreeViewAnyPluginSignature> {
9
9
  instance: TreeViewUsedInstance<TSignature>;
10
+ publicAPI: TreeViewUsedPublicAPI<TSignature>;
10
11
  params: TreeViewUsedDefaultizedParams<TSignature>;
11
12
  state: TreeViewUsedState<TSignature>;
12
13
  slots: TSignature['slots'];
@@ -27,6 +28,7 @@ export type TreeViewPluginSignature<T extends {
27
28
  params?: {};
28
29
  defaultizedParams?: {};
29
30
  instance?: {};
31
+ publicAPI?: {};
30
32
  events?: {
31
33
  [key in keyof T['events']]: TreeViewEventLookupElement;
32
34
  };
@@ -50,6 +52,9 @@ export type TreeViewPluginSignature<T extends {
50
52
  instance: T extends {
51
53
  instance: {};
52
54
  } ? T['instance'] : {};
55
+ publicAPI: T extends {
56
+ publicAPI: {};
57
+ } ? T['publicAPI'] : {};
53
58
  events: T extends {
54
59
  events: {};
55
60
  } ? T['events'] : {};
@@ -86,6 +91,7 @@ export type TreeViewAnyPluginSignature = {
86
91
  slots: any;
87
92
  slotProps: any;
88
93
  models: any;
94
+ publicAPI: any;
89
95
  };
90
96
  type TreeViewUsedPlugins<TSignature extends TreeViewAnyPluginSignature> = [
91
97
  TreeViewCorePluginsSignature,
@@ -99,6 +105,12 @@ export type TreeViewUsedInstance<TSignature extends TreeViewAnyPluginSignature>
99
105
  */
100
106
  $$signature: TSignature;
101
107
  };
108
+ export type TreeViewUsedPublicAPI<TSignature extends TreeViewAnyPluginSignature> = TSignature['publicAPI'] & MergePluginsProperty<TreeViewUsedPlugins<TSignature>, 'publicAPI'> & {
109
+ /**
110
+ * Private property only defined in TypeScript to be able to access the plugin signature from the publicAPI object.
111
+ */
112
+ $$signature: TSignature;
113
+ };
102
114
  type TreeViewUsedState<TSignature extends TreeViewAnyPluginSignature> = TSignature['state'] & MergePluginsProperty<TreeViewUsedPlugins<TSignature>, 'state'>;
103
115
  type RemoveSetValue<Models extends Record<string, TreeViewModel<any>>> = {
104
116
  [K in keyof Models]: Omit<Models[K], 'setValue'>;
@@ -24,3 +24,4 @@ export interface TreeViewModel<TValue> {
24
24
  setControlledValue: (value: TValue | ((prevValue: TValue) => TValue)) => void;
25
25
  }
26
26
  export type TreeViewInstance<TSignatures extends readonly TreeViewAnyPluginSignature[]> = MergePluginsProperty<TSignatures, 'instance'>;
27
+ export type TreeViewPublicAPI<TSignatures extends readonly TreeViewAnyPluginSignature[]> = MergePluginsProperty<TSignatures, 'publicAPI'>;
@@ -2,10 +2,12 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import useEventCallback from '@mui/utils/useEventCallback';
4
4
  import ownerDocument from '@mui/utils/ownerDocument';
5
- import { populateInstance } from '../../useTreeView/useTreeView.utils';
5
+ import { populateInstance, populatePublicAPI } from '../../useTreeView/useTreeView.utils';
6
6
  import { useInstanceEventHandler } from '../../hooks/useInstanceEventHandler';
7
+ import { getActiveElement } from '../../utils/utils';
7
8
  export const useTreeViewFocus = ({
8
9
  instance,
10
+ publicAPI,
9
11
  params,
10
12
  state,
11
13
  setState,
@@ -14,19 +16,45 @@ export const useTreeViewFocus = ({
14
16
  }) => {
15
17
  const setFocusedNodeId = useEventCallback(nodeId => {
16
18
  const cleanNodeId = typeof nodeId === 'function' ? nodeId(state.focusedNodeId) : nodeId;
17
- setState(prevState => _extends({}, prevState, {
18
- focusedNodeId: cleanNodeId
19
- }));
19
+ if (state.focusedNodeId !== cleanNodeId) {
20
+ setState(prevState => _extends({}, prevState, {
21
+ focusedNodeId: cleanNodeId
22
+ }));
23
+ }
20
24
  });
21
- const isNodeFocused = React.useCallback(nodeId => state.focusedNodeId === nodeId, [state.focusedNodeId]);
25
+ const isTreeViewFocused = React.useCallback(() => !!rootRef.current && rootRef.current === getActiveElement(ownerDocument(rootRef.current)), [rootRef]);
26
+ const isNodeFocused = React.useCallback(nodeId => state.focusedNodeId === nodeId && isTreeViewFocused(), [state.focusedNodeId, isTreeViewFocused]);
27
+ const isNodeVisible = nodeId => {
28
+ const node = instance.getNode(nodeId);
29
+ return node && (node.parentId == null || instance.isNodeExpanded(node.parentId));
30
+ };
22
31
  const focusNode = useEventCallback((event, nodeId) => {
23
- if (nodeId) {
32
+ // if we receive a nodeId, and it is visible, the focus will be set to it
33
+ if (nodeId && isNodeVisible(nodeId)) {
34
+ if (!isTreeViewFocused()) {
35
+ instance.focusRoot();
36
+ }
24
37
  setFocusedNodeId(nodeId);
25
38
  if (params.onNodeFocus) {
26
39
  params.onNodeFocus(event, nodeId);
27
40
  }
28
41
  }
29
42
  });
43
+ const focusDefaultNode = useEventCallback(event => {
44
+ let nodeToFocusId;
45
+ if (Array.isArray(models.selectedNodes.value)) {
46
+ nodeToFocusId = models.selectedNodes.value.find(isNodeVisible);
47
+ } else if (models.selectedNodes.value != null && isNodeVisible(models.selectedNodes.value)) {
48
+ nodeToFocusId = models.selectedNodes.value;
49
+ }
50
+ if (nodeToFocusId == null) {
51
+ nodeToFocusId = instance.getNavigableChildrenIds(null)[0];
52
+ }
53
+ setFocusedNodeId(nodeToFocusId);
54
+ if (params.onNodeFocus) {
55
+ params.onNodeFocus(event, nodeToFocusId);
56
+ }
57
+ });
30
58
  const focusRoot = useEventCallback(() => {
31
59
  var _rootRef$current;
32
60
  (_rootRef$current = rootRef.current) == null || _rootRef$current.focus({
@@ -36,7 +64,11 @@ export const useTreeViewFocus = ({
36
64
  populateInstance(instance, {
37
65
  isNodeFocused,
38
66
  focusNode,
39
- focusRoot
67
+ focusRoot,
68
+ focusDefaultNode
69
+ });
70
+ populatePublicAPI(publicAPI, {
71
+ focusNode
40
72
  });
41
73
  useInstanceEventHandler(instance, 'removeNode', ({
42
74
  id
@@ -51,23 +83,9 @@ export const useTreeViewFocus = ({
51
83
  const createHandleFocus = otherHandlers => event => {
52
84
  var _otherHandlers$onFocu;
53
85
  (_otherHandlers$onFocu = otherHandlers.onFocus) == null || _otherHandlers$onFocu.call(otherHandlers, event);
54
-
55
86
  // if the event bubbled (which is React specific) we don't want to steal focus
56
87
  if (event.target === event.currentTarget) {
57
- const isNodeVisible = nodeId => {
58
- const node = instance.getNode(nodeId);
59
- return node && (node.parentId == null || instance.isNodeExpanded(node.parentId));
60
- };
61
- let nodeToFocusId;
62
- if (Array.isArray(models.selectedNodes.value)) {
63
- nodeToFocusId = models.selectedNodes.value.find(isNodeVisible);
64
- } else if (models.selectedNodes.value != null && isNodeVisible(models.selectedNodes.value)) {
65
- nodeToFocusId = models.selectedNodes.value;
66
- }
67
- if (nodeToFocusId == null) {
68
- nodeToFocusId = instance.getNavigableChildrenIds(null)[0];
69
- }
70
- instance.focusNode(event, nodeToFocusId);
88
+ instance.focusDefaultNode(event);
71
89
  }
72
90
  };
73
91
  const createHandleBlur = otherHandlers => event => {
@@ -7,8 +7,12 @@ import { UseTreeViewExpansionSignature } from '../useTreeViewExpansion';
7
7
  export interface UseTreeViewFocusInstance {
8
8
  isNodeFocused: (nodeId: string) => boolean;
9
9
  focusNode: (event: React.SyntheticEvent, nodeId: string | null) => void;
10
+ focusDefaultNode: (event: React.SyntheticEvent) => void;
10
11
  focusRoot: () => void;
11
12
  }
13
+ export interface UseTreeViewFocusPublicAPI {
14
+ focusNode: (event: React.SyntheticEvent, nodeId: string | null) => void;
15
+ }
12
16
  export interface UseTreeViewFocusParameters {
13
17
  /**
14
18
  * Callback fired when tree items are focused.
@@ -26,6 +30,7 @@ export type UseTreeViewFocusSignature = TreeViewPluginSignature<{
26
30
  params: UseTreeViewFocusParameters;
27
31
  defaultizedParams: UseTreeViewFocusDefaultizedParameters;
28
32
  instance: UseTreeViewFocusInstance;
33
+ publicAPI: UseTreeViewFocusPublicAPI;
29
34
  state: UseTreeViewFocusState;
30
35
  dependantPlugins: [
31
36
  UseTreeViewIdSignature,
@@ -1,3 +1,5 @@
1
+ import * as React from 'react';
1
2
  import { TreeViewAnyPluginSignature, TreeViewPlugin, ConvertPluginsIntoSignatures } from '../models';
2
3
  import { UseTreeViewParameters, UseTreeViewReturnValue } from './useTreeView.types';
4
+ export declare function useTreeViewApiInitialization<T>(inputApiRef: React.MutableRefObject<T> | undefined): T;
3
5
  export declare const useTreeView: <Plugins extends readonly TreeViewPlugin<TreeViewAnyPluginSignature>[]>(inParams: UseTreeViewParameters<Plugins>) => UseTreeViewReturnValue<ConvertPluginsIntoSignatures<Plugins>>;