@fluentui/react-menu 9.0.4 → 9.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. package/CHANGELOG.json +141 -5
  2. package/CHANGELOG.md +41 -6
  3. package/dist/index.d.ts +26 -28
  4. package/lib/components/Menu/Menu.types.js.map +1 -1
  5. package/lib/components/Menu/useMenu.js +46 -22
  6. package/lib/components/Menu/useMenu.js.map +1 -1
  7. package/lib/components/MenuItem/MenuItem.types.js.map +1 -1
  8. package/lib/components/MenuItem/useCharacterSearch.js +2 -4
  9. package/lib/components/MenuItem/useCharacterSearch.js.map +1 -1
  10. package/lib/components/MenuItem/useMenuItem.js +58 -72
  11. package/lib/components/MenuItem/useMenuItem.js.map +1 -1
  12. package/lib/components/MenuItem/useMenuItemStyles.js +50 -30
  13. package/lib/components/MenuItem/useMenuItemStyles.js.map +1 -1
  14. package/lib/components/MenuItemCheckbox/useMenuItemCheckbox.js +25 -27
  15. package/lib/components/MenuItemCheckbox/useMenuItemCheckbox.js.map +1 -1
  16. package/lib/components/MenuItemCheckbox/useMenuItemCheckboxStyles.js.map +1 -1
  17. package/lib/components/MenuItemRadio/useMenuItemRadio.js +24 -30
  18. package/lib/components/MenuItemRadio/useMenuItemRadio.js.map +1 -1
  19. package/lib/components/MenuItemRadio/useMenuItemRadioStyles.js.map +1 -1
  20. package/lib/components/MenuPopover/useMenuPopover.js +6 -2
  21. package/lib/components/MenuPopover/useMenuPopover.js.map +1 -1
  22. package/lib/components/MenuTrigger/MenuTrigger.types.js.map +1 -1
  23. package/lib/components/MenuTrigger/useMenuTrigger.js +18 -23
  24. package/lib/components/MenuTrigger/useMenuTrigger.js.map +1 -1
  25. package/lib/contexts/menuContext.js +8 -6
  26. package/lib/contexts/menuContext.js.map +1 -1
  27. package/lib/contexts/menuGroupContext.js +9 -5
  28. package/lib/contexts/menuGroupContext.js.map +1 -1
  29. package/lib/contexts/menuListContext.js +5 -5
  30. package/lib/contexts/menuListContext.js.map +1 -1
  31. package/lib/contexts/menuTriggerContext.js +7 -3
  32. package/lib/contexts/menuTriggerContext.js.map +1 -1
  33. package/lib/selectable/types.js.map +1 -1
  34. package/lib-commonjs/components/Menu/useMenu.js +47 -22
  35. package/lib-commonjs/components/Menu/useMenu.js.map +1 -1
  36. package/lib-commonjs/components/MenuItem/useCharacterSearch.js +2 -4
  37. package/lib-commonjs/components/MenuItem/useCharacterSearch.js.map +1 -1
  38. package/lib-commonjs/components/MenuItem/useMenuItem.js +59 -71
  39. package/lib-commonjs/components/MenuItem/useMenuItem.js.map +1 -1
  40. package/lib-commonjs/components/MenuItem/useMenuItemStyles.js +50 -30
  41. package/lib-commonjs/components/MenuItem/useMenuItemStyles.js.map +1 -1
  42. package/lib-commonjs/components/MenuItemCheckbox/useMenuItemCheckbox.js +26 -28
  43. package/lib-commonjs/components/MenuItemCheckbox/useMenuItemCheckbox.js.map +1 -1
  44. package/lib-commonjs/components/MenuItemCheckbox/useMenuItemCheckboxStyles.js.map +1 -1
  45. package/lib-commonjs/components/MenuItemRadio/useMenuItemRadio.js +25 -31
  46. package/lib-commonjs/components/MenuItemRadio/useMenuItemRadio.js.map +1 -1
  47. package/lib-commonjs/components/MenuItemRadio/useMenuItemRadioStyles.js.map +1 -1
  48. package/lib-commonjs/components/MenuPopover/useMenuPopover.js +6 -2
  49. package/lib-commonjs/components/MenuPopover/useMenuPopover.js.map +1 -1
  50. package/lib-commonjs/components/MenuTrigger/useMenuTrigger.js +17 -22
  51. package/lib-commonjs/components/MenuTrigger/useMenuTrigger.js.map +1 -1
  52. package/lib-commonjs/contexts/menuContext.js +8 -6
  53. package/lib-commonjs/contexts/menuContext.js.map +1 -1
  54. package/lib-commonjs/contexts/menuGroupContext.js +9 -5
  55. package/lib-commonjs/contexts/menuGroupContext.js.map +1 -1
  56. package/lib-commonjs/contexts/menuListContext.js +5 -5
  57. package/lib-commonjs/contexts/menuListContext.js.map +1 -1
  58. package/lib-commonjs/contexts/menuTriggerContext.js +7 -3
  59. package/lib-commonjs/contexts/menuTriggerContext.js.map +1 -1
  60. package/package.json +15 -14
  61. package/dist/tsdoc-metadata.json +0 -11
package/CHANGELOG.json CHANGED
@@ -2,7 +2,143 @@
2
2
  "name": "@fluentui/react-menu",
3
3
  "entries": [
4
4
  {
5
- "date": "Wed, 03 Aug 2022 16:00:18 GMT",
5
+ "date": "Tue, 20 Sep 2022 20:54:07 GMT",
6
+ "tag": "@fluentui/react-menu_v9.2.0",
7
+ "version": "9.2.0",
8
+ "comments": {
9
+ "minor": [
10
+ {
11
+ "author": "bernardo.sunderhus@gmail.com",
12
+ "package": "@fluentui/react-menu",
13
+ "commit": "e8f84e8262c165e5809b4ffc18381e6398b12c4f",
14
+ "comment": "feat: replace keydown handlers by useARIAButtonShorthand on MenuItem"
15
+ },
16
+ {
17
+ "author": "beachball",
18
+ "package": "@fluentui/react-menu",
19
+ "comment": "Bump @fluentui/react-conformance-griffel to v9.0.0-beta.14",
20
+ "commit": "9617a5a46ef4c5e310a066a5374ff2ed61db3c66"
21
+ }
22
+ ]
23
+ }
24
+ },
25
+ {
26
+ "date": "Thu, 15 Sep 2022 09:49:08 GMT",
27
+ "tag": "@fluentui/react-menu_v9.1.0",
28
+ "version": "9.1.0",
29
+ "comments": {
30
+ "patch": [
31
+ {
32
+ "author": "behowell@microsoft.com",
33
+ "package": "@fluentui/react-menu",
34
+ "commit": "e598325b985cad3e5057f00893e0176416edd292",
35
+ "comment": "refactor: Replace useMergedEventCallbacks utility with mergeCallbacks"
36
+ },
37
+ {
38
+ "author": "olfedias@microsoft.com",
39
+ "package": "@fluentui/react-menu",
40
+ "commit": "e610024474cfe5d45f61501a8b6a21daf4c794a2",
41
+ "comment": "chore: Update Griffel to latest version"
42
+ },
43
+ {
44
+ "author": "bernardo.sunderhus@gmail.com",
45
+ "package": "@fluentui/react-menu",
46
+ "commit": "6c6fe4c8246abec30d9cd3ba2079d379c4d7acb8",
47
+ "comment": "bugfix: stops propagation on Escape keydown"
48
+ },
49
+ {
50
+ "author": "lingfangao@hotmail.com",
51
+ "package": "@fluentui/react-menu",
52
+ "commit": "a0cfab0e5f74e3a3bfa9c269fff574295042d7f2",
53
+ "comment": "chore: fix no-context-default-value lint violations"
54
+ }
55
+ ],
56
+ "none": [
57
+ {
58
+ "author": "martinhochel@microsoft.com",
59
+ "package": "@fluentui/react-menu",
60
+ "commit": "e6cf183695d6d67a24e038c49a876224e5ed35e5",
61
+ "comment": "chore: update package scaffold"
62
+ },
63
+ {
64
+ "author": "martinhochel@microsoft.com",
65
+ "package": "@fluentui/react-menu",
66
+ "commit": "ba9444d594f3a960cc590eae5237c08bf7c5a07f",
67
+ "comment": "chore: consume cypress.config from it's package boundary"
68
+ },
69
+ {
70
+ "author": "bernardo.sunderhus@gmail.com",
71
+ "package": "@fluentui/react-menu",
72
+ "commit": "a105236ca0a6eac1035fee7bfca274972fb89da1",
73
+ "comment": "chore(react-menu): stop spreading props on state"
74
+ }
75
+ ],
76
+ "minor": [
77
+ {
78
+ "author": "bernardo.sunderhus@gmail.com",
79
+ "package": "@fluentui/react-menu",
80
+ "commit": "0547583ebcebe746110e5ef8d0599b0972b1f4c6",
81
+ "comment": "chore(react-menu): Updates trigger to use useARIAButton"
82
+ },
83
+ {
84
+ "author": "beachball",
85
+ "package": "@fluentui/react-menu",
86
+ "comment": "Bump @fluentui/react-aria to v9.2.0",
87
+ "commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
88
+ },
89
+ {
90
+ "author": "beachball",
91
+ "package": "@fluentui/react-menu",
92
+ "comment": "Bump @fluentui/react-context-selector to v9.0.3",
93
+ "commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
94
+ },
95
+ {
96
+ "author": "beachball",
97
+ "package": "@fluentui/react-menu",
98
+ "comment": "Bump @fluentui/react-portal to v9.0.5",
99
+ "commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
100
+ },
101
+ {
102
+ "author": "beachball",
103
+ "package": "@fluentui/react-menu",
104
+ "comment": "Bump @fluentui/react-positioning to v9.2.0",
105
+ "commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
106
+ },
107
+ {
108
+ "author": "beachball",
109
+ "package": "@fluentui/react-menu",
110
+ "comment": "Bump @fluentui/react-shared-contexts to v9.0.1",
111
+ "commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
112
+ },
113
+ {
114
+ "author": "beachball",
115
+ "package": "@fluentui/react-menu",
116
+ "comment": "Bump @fluentui/react-tabster to v9.1.1",
117
+ "commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
118
+ },
119
+ {
120
+ "author": "beachball",
121
+ "package": "@fluentui/react-menu",
122
+ "comment": "Bump @fluentui/react-theme to v9.1.0",
123
+ "commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
124
+ },
125
+ {
126
+ "author": "beachball",
127
+ "package": "@fluentui/react-menu",
128
+ "comment": "Bump @fluentui/react-utilities to v9.1.0",
129
+ "commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
130
+ },
131
+ {
132
+ "author": "beachball",
133
+ "package": "@fluentui/react-menu",
134
+ "comment": "Bump @fluentui/react-conformance-griffel to v9.0.0-beta.13",
135
+ "commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
136
+ }
137
+ ]
138
+ }
139
+ },
140
+ {
141
+ "date": "Wed, 03 Aug 2022 16:03:51 GMT",
6
142
  "tag": "@fluentui/react-menu_v9.0.4",
7
143
  "version": "9.0.4",
8
144
  "comments": {
@@ -37,25 +173,25 @@
37
173
  "author": "beachball",
38
174
  "package": "@fluentui/react-menu",
39
175
  "comment": "Bump @fluentui/react-portal to v9.0.4",
40
- "commit": "54bc6105c5c9c9023da35d4670239e44117ed4a5"
176
+ "commit": "ee4a8be0d0831a6615f878f98db6a97cc61a802d"
41
177
  },
42
178
  {
43
179
  "author": "beachball",
44
180
  "package": "@fluentui/react-menu",
45
181
  "comment": "Bump @fluentui/react-positioning to v9.1.2",
46
- "commit": "54bc6105c5c9c9023da35d4670239e44117ed4a5"
182
+ "commit": "ee4a8be0d0831a6615f878f98db6a97cc61a802d"
47
183
  },
48
184
  {
49
185
  "author": "beachball",
50
186
  "package": "@fluentui/react-menu",
51
187
  "comment": "Bump @fluentui/react-tabster to v9.1.0",
52
- "commit": "54bc6105c5c9c9023da35d4670239e44117ed4a5"
188
+ "commit": "ee4a8be0d0831a6615f878f98db6a97cc61a802d"
53
189
  },
54
190
  {
55
191
  "author": "beachball",
56
192
  "package": "@fluentui/react-menu",
57
193
  "comment": "Bump @fluentui/react-conformance-griffel to v9.0.0-beta.12",
58
- "commit": "54bc6105c5c9c9023da35d4670239e44117ed4a5"
194
+ "commit": "ee4a8be0d0831a6615f878f98db6a97cc61a802d"
59
195
  }
60
196
  ]
61
197
  }
package/CHANGELOG.md CHANGED
@@ -1,22 +1,57 @@
1
1
  # Change Log - @fluentui/react-menu
2
2
 
3
- This log was last generated on Wed, 03 Aug 2022 16:00:18 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 20 Sep 2022 20:54:07 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.2.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-menu_v9.2.0)
8
+
9
+ Tue, 20 Sep 2022 20:54:07 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-menu_v9.1.0..@fluentui/react-menu_v9.2.0)
11
+
12
+ ### Minor changes
13
+
14
+ - feat: replace keydown handlers by useARIAButtonShorthand on MenuItem ([PR #24738](https://github.com/microsoft/fluentui/pull/24738) by bernardo.sunderhus@gmail.com)
15
+ - Bump @fluentui/react-conformance-griffel to v9.0.0-beta.14 ([PR #24870](https://github.com/microsoft/fluentui/pull/24870) by beachball)
16
+
17
+ ## [9.1.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-menu_v9.1.0)
18
+
19
+ Thu, 15 Sep 2022 09:49:08 GMT
20
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-menu_v9.0.4..@fluentui/react-menu_v9.1.0)
21
+
22
+ ### Minor changes
23
+
24
+ - chore(react-menu): Updates trigger to use useARIAButton ([PR #24177](https://github.com/microsoft/fluentui/pull/24177) by bernardo.sunderhus@gmail.com)
25
+ - Bump @fluentui/react-aria to v9.2.0 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
26
+ - Bump @fluentui/react-context-selector to v9.0.3 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
27
+ - Bump @fluentui/react-portal to v9.0.5 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
28
+ - Bump @fluentui/react-positioning to v9.2.0 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
29
+ - Bump @fluentui/react-shared-contexts to v9.0.1 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
30
+ - Bump @fluentui/react-tabster to v9.1.1 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
31
+ - Bump @fluentui/react-theme to v9.1.0 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
32
+ - Bump @fluentui/react-utilities to v9.1.0 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
33
+ - Bump @fluentui/react-conformance-griffel to v9.0.0-beta.13 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
34
+
35
+ ### Patches
36
+
37
+ - refactor: Replace useMergedEventCallbacks utility with mergeCallbacks ([PR #24152](https://github.com/microsoft/fluentui/pull/24152) by behowell@microsoft.com)
38
+ - chore: Update Griffel to latest version ([PR #24221](https://github.com/microsoft/fluentui/pull/24221) by olfedias@microsoft.com)
39
+ - bugfix: stops propagation on Escape keydown ([PR #24750](https://github.com/microsoft/fluentui/pull/24750) by bernardo.sunderhus@gmail.com)
40
+ - chore: fix no-context-default-value lint violations ([PR #24276](https://github.com/microsoft/fluentui/pull/24276) by lingfangao@hotmail.com)
41
+
7
42
  ## [9.0.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-menu_v9.0.4)
8
43
 
9
- Wed, 03 Aug 2022 16:00:18 GMT
44
+ Wed, 03 Aug 2022 16:03:51 GMT
10
45
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-menu_v9.0.3..@fluentui/react-menu_v9.0.4)
11
46
 
12
47
  ### Patches
13
48
 
14
49
  - chore: Bump Griffel dependencies ([PR #24114](https://github.com/microsoft/fluentui/pull/24114) by miroslav.stastny@microsoft.com)
15
50
  - fix: Fix tabbing from within menu ([PR #24101](https://github.com/microsoft/fluentui/pull/24101) by lingfangao@hotmail.com)
16
- - Bump @fluentui/react-portal to v9.0.4 ([PR #24201](https://github.com/microsoft/fluentui/pull/24201) by beachball)
17
- - Bump @fluentui/react-positioning to v9.1.2 ([PR #24201](https://github.com/microsoft/fluentui/pull/24201) by beachball)
18
- - Bump @fluentui/react-tabster to v9.1.0 ([PR #24201](https://github.com/microsoft/fluentui/pull/24201) by beachball)
19
- - Bump @fluentui/react-conformance-griffel to v9.0.0-beta.12 ([PR #24201](https://github.com/microsoft/fluentui/pull/24201) by beachball)
51
+ - Bump @fluentui/react-portal to v9.0.4 ([PR #24131](https://github.com/microsoft/fluentui/pull/24131) by beachball)
52
+ - Bump @fluentui/react-positioning to v9.1.2 ([PR #24131](https://github.com/microsoft/fluentui/pull/24131) by beachball)
53
+ - Bump @fluentui/react-tabster to v9.1.0 ([PR #24131](https://github.com/microsoft/fluentui/pull/24131) by beachball)
54
+ - Bump @fluentui/react-conformance-griffel to v9.0.0-beta.12 ([PR #24131](https://github.com/microsoft/fluentui/pull/24131) by beachball)
20
55
 
21
56
  ## [9.0.3](https://github.com/microsoft/fluentui/tree/@fluentui/react-menu_v9.0.3)
22
57
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  /// <reference types="react" />
2
2
 
3
+ import type { ARIAButtonElement } from '@fluentui/react-aria';
4
+ import { ARIAButtonResultProps } from '@fluentui/react-aria';
5
+ import type { ARIAButtonSlotProps } from '@fluentui/react-aria';
6
+ import { ARIAButtonType } from '@fluentui/react-aria';
3
7
  import type { ComponentProps } from '@fluentui/react-utilities';
4
8
  import type { ComponentState } from '@fluentui/react-utilities';
5
9
  import type { ContextSelector } from '@fluentui/react-context-selector';
@@ -30,7 +34,7 @@ export declare type MenuCheckedValueChangeEvent = React_2.MouseEvent | React_2.K
30
34
  *
31
35
  * Extends and drills down MenuList props to simplify API
32
36
  */
33
- export declare type MenuContextValue = MenuListProps & Pick<MenuState, 'openOnHover' | 'openOnContext' | 'triggerRef' | 'menuPopoverRef' | 'setOpen' | 'isSubmenu' | 'triggerId' | 'hasIcons' | 'hasCheckmarks' | 'persistOnItemClick' | 'inline'> & {
37
+ export declare type MenuContextValue = Pick<MenuState, 'openOnHover' | 'openOnContext' | 'triggerRef' | 'menuPopoverRef' | 'setOpen' | 'isSubmenu' | 'triggerId' | 'hasIcons' | 'hasCheckmarks' | 'persistOnItemClick' | 'inline' | 'checkedValues' | 'onCheckedValueChange' | 'defaultCheckedValues'> & {
34
38
  open: boolean;
35
39
  triggerId: string;
36
40
  };
@@ -125,12 +129,6 @@ export declare type MenuItemCheckboxState = MenuItemState & MenuItemSelectableSt
125
129
  export declare const menuItemClassNames: SlotClassNames<MenuItemSlots>;
126
130
 
127
131
  export declare type MenuItemProps = ComponentProps<Partial<MenuItemSlots>> & {
128
- /**
129
- * Applies disabled styles to menu item but remains focusable
130
- *
131
- * @default false
132
- */
133
- disabled?: boolean;
134
132
  /**
135
133
  * If the menu item is a trigger for a submenu
136
134
  *
@@ -176,14 +174,6 @@ export declare type MenuItemSelectableProps = {
176
174
  * State for selectable menu items
177
175
  */
178
176
  export declare type MenuItemSelectableState = MenuItemSelectableProps & {
179
- /**
180
- * Checked items for a value with `name`
181
- */
182
- checkedItems: string[];
183
- /**
184
- * Callback when checked items changes for a given value with `name`
185
- */
186
- onCheckedValueChange: (e: React_2.MouseEvent | React_2.KeyboardEvent, name: string, checkedItems: string[]) => void;
187
177
  /**
188
178
  * Selectable is checked
189
179
  */
@@ -191,7 +181,7 @@ export declare type MenuItemSelectableState = MenuItemSelectableProps & {
191
181
  };
192
182
 
193
183
  export declare type MenuItemSlots = {
194
- root: Slot<'div'>;
184
+ root: Slot<ARIAButtonSlotProps<'div'>>;
195
185
  /**
196
186
  * Icon slot rendered before children content
197
187
  */
@@ -216,7 +206,9 @@ export declare type MenuItemSlots = {
216
206
  secondaryContent?: Slot<'span'>;
217
207
  };
218
208
 
219
- export declare type MenuItemState = ComponentState<MenuItemSlots> & Pick<MenuItemProps, 'disabled' | 'hasSubmenu' | 'persistOnClick'>;
209
+ export declare type MenuItemState = ComponentState<MenuItemSlots> & Required<Pick<MenuItemProps, 'disabled' | 'hasSubmenu' | 'persistOnClick'>> & {
210
+ isNativeButton: boolean;
211
+ };
220
212
 
221
213
  /**
222
214
  * Define a styled MenuList, using the `useMenuList_unstable` hook.
@@ -292,6 +284,8 @@ export declare type MenuOpenChangeData = {
292
284
  bubble?: boolean;
293
285
  /**
294
286
  * Indicates whether the change of state was a keyboard interaction
287
+ * @deprecated
288
+ * This should not be used, since `Enter`, `Space` and click should be interpreted as the same thing as a click
295
289
  */
296
290
  keyboard?: boolean;
297
291
  open: boolean;
@@ -421,7 +415,7 @@ export declare type MenuSplitGroupSlots = {
421
415
  */
422
416
  export declare type MenuSplitGroupState = ComponentState<MenuSplitGroupSlots>;
423
417
 
424
- export declare type MenuState = ComponentState<MenuSlots> & Pick<MenuProps, 'defaultCheckedValues' | 'hasCheckmarks' | 'hasIcons' | 'inline' | 'onOpenChange' | 'openOnContext' | 'persistOnItemClick'> & Required<Pick<MenuProps, 'checkedValues' | 'onCheckedValueChange' | 'open' | 'openOnHover' | 'closeOnScroll'>> & {
418
+ export declare type MenuState = ComponentState<MenuSlots> & Pick<MenuProps, 'onOpenChange' | 'defaultCheckedValues'> & Required<Pick<MenuProps, 'hasCheckmarks' | 'hasIcons' | 'inline' | 'checkedValues' | 'onCheckedValueChange' | 'open' | 'openOnHover' | 'closeOnScroll' | 'hoverDelay' | 'openOnContext' | 'persistOnItemClick'>> & {
425
419
  /**
426
420
  * Anchors the popper to the mouse click for context events
427
421
  */
@@ -469,10 +463,16 @@ export declare const MenuTrigger: React_2.FC<MenuTriggerProps> & FluentTriggerCo
469
463
  /**
470
464
  * Props that are passed to the child of the MenuTrigger when cloned to ensure correct behaviour for the Menu
471
465
  */
472
- export declare type MenuTriggerChildProps = Required<Pick<React_2.HTMLAttributes<HTMLElement>, 'onClick' | 'onMouseEnter' | 'onMouseLeave' | 'onMouseMove' | 'onContextMenu' | 'onKeyDown' | 'aria-haspopup' | 'id'>> & {
473
- ref?: React_2.Ref<never>;
474
- 'aria-expanded': boolean | undefined;
475
- };
466
+ export declare type MenuTriggerChildProps<Type extends ARIAButtonType = ARIAButtonType, Props = {}> = ARIAButtonResultProps<Type, Props & {
467
+ 'aria-haspopup': 'menu';
468
+ 'aria-expanded'?: boolean;
469
+ id: string;
470
+ ref: React_2.Ref<never>;
471
+ onMouseEnter: React_2.MouseEventHandler<HTMLButtonElement & HTMLAnchorElement & HTMLDivElement>;
472
+ onMouseLeave: React_2.MouseEventHandler<HTMLButtonElement & HTMLAnchorElement & HTMLDivElement>;
473
+ onMouseMove: React_2.MouseEventHandler<HTMLButtonElement & HTMLAnchorElement & HTMLDivElement>;
474
+ onContextMenu: React_2.MouseEventHandler<HTMLButtonElement & HTMLAnchorElement & HTMLDivElement>;
475
+ }>;
476
476
 
477
477
  export declare const MenuTriggerContextProvider: React_2.Provider<boolean>;
478
478
 
@@ -480,9 +480,7 @@ export declare type MenuTriggerProps = {
480
480
  /**
481
481
  * Explicitly require single child or render function
482
482
  */
483
- children: (React_2.ReactElement & {
484
- ref?: React_2.Ref<unknown>;
485
- }) | ((props: MenuTriggerChildProps) => React_2.ReactElement | null);
483
+ children: React_2.ReactElement | ((props: MenuTriggerChildProps) => React_2.ReactElement | null);
486
484
  };
487
485
 
488
486
  export declare type MenuTriggerState = {
@@ -602,17 +600,17 @@ export declare const useMenuGroupStyles_unstable: (state: MenuGroupState) => Men
602
600
  /**
603
601
  * Returns the props and state required to render the component
604
602
  */
605
- export declare const useMenuItem_unstable: (props: MenuItemProps, ref: React_2.Ref<HTMLElement>) => MenuItemState;
603
+ export declare const useMenuItem_unstable: (props: MenuItemProps, ref: React_2.Ref<ARIAButtonElement<'div'>>) => MenuItemState;
606
604
 
607
605
  /** Returns the props and state required to render the component */
608
- export declare const useMenuItemCheckbox_unstable: (props: MenuItemCheckboxProps, ref: React_2.Ref<HTMLElement>) => MenuItemCheckboxState;
606
+ export declare const useMenuItemCheckbox_unstable: (props: MenuItemCheckboxProps, ref: React_2.Ref<ARIAButtonElement<'div'>>) => MenuItemCheckboxState;
609
607
 
610
608
  export declare const useMenuItemCheckboxStyles_unstable: (state: MenuItemCheckboxState) => void;
611
609
 
612
610
  /**
613
611
  * Given user props, returns state and render function for a MenuItemRadio.
614
612
  */
615
- export declare const useMenuItemRadio_unstable: (props: MenuItemRadioProps, ref: React_2.Ref<HTMLElement>) => MenuItemRadioState;
613
+ export declare const useMenuItemRadio_unstable: (props: MenuItemRadioProps, ref: React_2.Ref<ARIAButtonElement<'div'>>) => MenuItemRadioState;
616
614
 
617
615
  export declare const useMenuItemRadioStyles_unstable: (state: MenuItemRadioState) => void;
618
616
 
@@ -1 +1 @@
1
- {"version":3,"file":"Menu.types.js","sourceRoot":"../src/","sources":["components/Menu/Menu.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport { usePositioningMouseTarget } from '@fluentui/react-positioning';\nimport type { PositioningShorthand } from '@fluentui/react-positioning';\nimport type { ComponentProps, ComponentState } from '@fluentui/react-utilities';\nimport type { MenuContextValue } from '../../contexts/menuContext';\nimport type { MenuListProps } from '../MenuList/MenuList.types';\n\nexport type MenuSlots = {};\n\n/**\n * Extends and drills down Menulist props to simplify API\n */\nexport type MenuProps = ComponentProps<MenuSlots> &\n Pick<\n MenuListProps,\n 'checkedValues' | 'defaultCheckedValues' | 'hasCheckmarks' | 'hasIcons' | 'onCheckedValueChange'\n > & {\n /**\n * Can contain two children including {@link MenuTrigger} and {@link MenuPopover}.\n * Alternatively can only contain {@link MenuPopover} if using a custom `target`.\n */\n children: [JSX.Element, JSX.Element] | JSX.Element;\n\n /**\n * Whether the popup is open by default\n *\n * @default false\n */\n defaultOpen?: boolean;\n\n /**\n * Sets the delay for mouse open/close for the popover one mouse enter/leave\n */\n hoverDelay?: number;\n\n /**\n * Root menus are rendered out of DOM order on `document.body`, use this to render the menu in DOM order\n * This option is disregarded for submenus\n *\n * @default false\n */\n inline?: boolean;\n\n /**\n * Call back when the component requests to change value\n * The `open` value is used as a hint when directly controlling the component\n */\n onOpenChange?: (e: MenuOpenEvents, data: MenuOpenChangeData) => void;\n\n /**\n * Whether the popup is open\n *\n * @default false\n */\n open?: boolean;\n\n /**\n * Opens the menu on right click (context menu), removes all other menu open interactions\n *\n * @default false\n */\n openOnContext?: boolean;\n\n /**\n * Opens the menu on hover\n *\n * @default false\n */\n openOnHover?: boolean;\n\n /**\n * Do not dismiss the menu when a menu item is clicked\n *\n * @default false\n */\n persistOnItemClick?: boolean;\n\n /**\n * Configures the positioned menu\n */\n positioning?: PositioningShorthand;\n\n /**\n * Close when scroll outside of it\n *\n * @default false\n */\n closeOnScroll?: boolean;\n };\n\nexport type MenuState = ComponentState<MenuSlots> &\n Pick<\n MenuProps,\n | 'defaultCheckedValues'\n | 'hasCheckmarks'\n | 'hasIcons'\n | 'inline'\n | 'onOpenChange'\n | 'openOnContext'\n | 'persistOnItemClick'\n > &\n Required<Pick<MenuProps, 'checkedValues' | 'onCheckedValueChange' | 'open' | 'openOnHover' | 'closeOnScroll'>> & {\n /**\n * Anchors the popper to the mouse click for context events\n */\n contextTarget: ReturnType<typeof usePositioningMouseTarget>[0];\n\n /**\n * Whether this menu is a submenu\n */\n isSubmenu: boolean;\n\n /**\n * Internal react node that just simplifies handling children\n */\n menuPopover: React.ReactNode;\n\n /**\n * The ref for the popup\n */\n menuPopoverRef: React.MutableRefObject<HTMLElement>;\n\n /**\n * Internal react node that just simplifies handling children\n */\n menuTrigger: React.ReactNode;\n\n /**\n * A callback to set the target of the popper to the mouse click for context events\n */\n setContextTarget: ReturnType<typeof usePositioningMouseTarget>[1];\n\n /**\n * Callback to open/close the popup\n */\n setOpen: (e: MenuOpenEvents, data: MenuOpenChangeData) => void;\n\n /**\n * Id for the MenuTrigger element for aria relationship\n */\n triggerId: string;\n\n /**\n * The ref for the MenuTrigger, used for popup positioning\n */\n triggerRef: React.MutableRefObject<HTMLElement>;\n };\n\n/**\n * Data attached to open/close events\n */\nexport type MenuOpenChangeData = {\n /**\n * indicates whether the request for the open state was bubbled from a nested menu\n */\n bubble?: boolean;\n /**\n * Indicates whether the change of state was a keyboard interaction\n */\n keyboard?: boolean;\n open: boolean;\n};\n\nexport type MenuContextValues = {\n menu: MenuContextValue;\n};\n\n/**\n * The supported events that will trigger open/close of the menu\n */\nexport type MenuOpenEvents =\n | MouseEvent\n | TouchEvent\n | React.FocusEvent<HTMLElement>\n | React.KeyboardEvent<HTMLElement>\n | React.MouseEvent<HTMLElement>;\n"]}
1
+ {"version":3,"file":"Menu.types.js","sourceRoot":"../src/","sources":["components/Menu/Menu.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport { usePositioningMouseTarget } from '@fluentui/react-positioning';\nimport type { PositioningShorthand } from '@fluentui/react-positioning';\nimport type { ComponentProps, ComponentState } from '@fluentui/react-utilities';\nimport type { MenuContextValue } from '../../contexts/menuContext';\nimport type { MenuListProps } from '../MenuList/MenuList.types';\n\nexport type MenuSlots = {};\n\n/**\n * Extends and drills down Menulist props to simplify API\n */\nexport type MenuProps = ComponentProps<MenuSlots> &\n Pick<\n MenuListProps,\n 'checkedValues' | 'defaultCheckedValues' | 'hasCheckmarks' | 'hasIcons' | 'onCheckedValueChange'\n > & {\n /**\n * Can contain two children including {@link MenuTrigger} and {@link MenuPopover}.\n * Alternatively can only contain {@link MenuPopover} if using a custom `target`.\n */\n children: [JSX.Element, JSX.Element] | JSX.Element;\n\n /**\n * Whether the popup is open by default\n *\n * @default false\n */\n defaultOpen?: boolean;\n\n /**\n * Sets the delay for mouse open/close for the popover one mouse enter/leave\n */\n hoverDelay?: number;\n\n /**\n * Root menus are rendered out of DOM order on `document.body`, use this to render the menu in DOM order\n * This option is disregarded for submenus\n *\n * @default false\n */\n inline?: boolean;\n\n /**\n * Call back when the component requests to change value\n * The `open` value is used as a hint when directly controlling the component\n */\n onOpenChange?: (e: MenuOpenEvents, data: MenuOpenChangeData) => void;\n\n /**\n * Whether the popup is open\n *\n * @default false\n */\n open?: boolean;\n\n /**\n * Opens the menu on right click (context menu), removes all other menu open interactions\n *\n * @default false\n */\n openOnContext?: boolean;\n\n /**\n * Opens the menu on hover\n *\n * @default false\n */\n openOnHover?: boolean;\n\n /**\n * Do not dismiss the menu when a menu item is clicked\n *\n * @default false\n */\n persistOnItemClick?: boolean;\n\n /**\n * Configures the positioned menu\n */\n positioning?: PositioningShorthand;\n\n /**\n * Close when scroll outside of it\n *\n * @default false\n */\n closeOnScroll?: boolean;\n };\n\nexport type MenuState = ComponentState<MenuSlots> &\n Pick<MenuProps, 'onOpenChange' | 'defaultCheckedValues'> &\n Required<\n Pick<\n MenuProps,\n | 'hasCheckmarks'\n | 'hasIcons'\n | 'inline'\n | 'checkedValues'\n | 'onCheckedValueChange'\n | 'open'\n | 'openOnHover'\n | 'closeOnScroll'\n | 'hoverDelay'\n | 'openOnContext'\n | 'persistOnItemClick'\n >\n > & {\n /**\n * Anchors the popper to the mouse click for context events\n */\n contextTarget: ReturnType<typeof usePositioningMouseTarget>[0];\n\n /**\n * Whether this menu is a submenu\n */\n isSubmenu: boolean;\n\n /**\n * Internal react node that just simplifies handling children\n */\n menuPopover: React.ReactNode;\n\n /**\n * The ref for the popup\n */\n menuPopoverRef: React.MutableRefObject<HTMLElement>;\n\n /**\n * Internal react node that just simplifies handling children\n */\n menuTrigger: React.ReactNode;\n\n /**\n * A callback to set the target of the popper to the mouse click for context events\n */\n setContextTarget: ReturnType<typeof usePositioningMouseTarget>[1];\n\n /**\n * Callback to open/close the popup\n */\n setOpen: (e: MenuOpenEvents, data: MenuOpenChangeData) => void;\n\n /**\n * Id for the MenuTrigger element for aria relationship\n */\n triggerId: string;\n\n /**\n * The ref for the MenuTrigger, used for popup positioning\n */\n triggerRef: React.MutableRefObject<HTMLElement>;\n };\n\n/**\n * Data attached to open/close events\n */\nexport type MenuOpenChangeData = {\n /**\n * indicates whether the request for the open state was bubbled from a nested menu\n */\n bubble?: boolean;\n /**\n * Indicates whether the change of state was a keyboard interaction\n * @deprecated\n * This should not be used, since `Enter`, `Space` and click should be interpreted as the same thing as a click\n */\n keyboard?: boolean;\n open: boolean;\n};\n\nexport type MenuContextValues = {\n menu: MenuContextValue;\n};\n\n/**\n * The supported events that will trigger open/close of the menu\n */\nexport type MenuOpenEvents =\n | MouseEvent\n | TouchEvent\n | React.FocusEvent<HTMLElement>\n | React.KeyboardEvent<HTMLElement>\n | React.MouseEvent<HTMLElement>;\n"]}
@@ -7,6 +7,7 @@ import { useFocusFinders } from '@fluentui/react-tabster';
7
7
  import { useMenuContext_unstable } from '../../contexts/menuContext';
8
8
  import { MENU_ENTER_EVENT, useOnMenuMouseEnter } from '../../utils/index';
9
9
  import { useIsSubmenu } from '../../utils/useIsSubmenu';
10
+ import { Tab } from '@fluentui/keyboard-keys';
10
11
  /**
11
12
  * Create the state required to render Menu.
12
13
  *
@@ -17,8 +18,16 @@ import { useIsSubmenu } from '../../utils/useIsSubmenu';
17
18
  */
18
19
 
19
20
  export const useMenu_unstable = props => {
20
- var _a;
21
-
21
+ const {
22
+ hoverDelay = 500,
23
+ inline = false,
24
+ hasCheckmarks = false,
25
+ hasIcons = false,
26
+ closeOnScroll = false,
27
+ openOnContext = false,
28
+ persistOnItemClick = false,
29
+ defaultCheckedValues
30
+ } = props;
22
31
  const triggerId = useId('menu');
23
32
  const isSubmenu = useIsSubmenu();
24
33
  const [contextTarget, setContextTarget] = usePositioningMouseTarget();
@@ -55,30 +64,48 @@ export const useMenu_unstable = props => {
55
64
  const {
56
65
  targetRef: triggerRef,
57
66
  containerRef: menuPopoverRef
58
- } = usePositioning(positioningState);
59
- const initialState = {
60
- hoverDelay: 500,
67
+ } = usePositioning(positioningState); // TODO Better way to narrow types ?
68
+
69
+ const [open, setOpen] = useMenuOpenState({
70
+ hoverDelay,
71
+ isSubmenu,
72
+ setContextTarget,
73
+ closeOnScroll,
74
+ menuPopoverRef,
75
+ triggerRef,
76
+ open: props.open,
77
+ defaultOpen: props.defaultOpen,
78
+ onOpenChange: props.onOpenChange,
79
+ openOnContext
80
+ });
81
+ const [checkedValues, onCheckedValueChange] = useMenuSelectableState({
82
+ checkedValues: props.checkedValues,
83
+ defaultCheckedValues,
84
+ onCheckedValueChange: props.onCheckedValueChange
85
+ });
86
+ return {
87
+ inline,
88
+ hoverDelay,
61
89
  triggerId,
62
- isSubmenu: !!isSubmenu,
63
- openOnHover: !!isSubmenu,
90
+ isSubmenu,
91
+ openOnHover: isSubmenu,
64
92
  contextTarget,
65
93
  setContextTarget,
66
- ...props,
67
- closeOnScroll: (_a = props.closeOnScroll) !== null && _a !== void 0 ? _a : false,
94
+ hasCheckmarks,
95
+ hasIcons,
96
+ closeOnScroll,
68
97
  menuTrigger,
69
98
  menuPopover,
70
99
  triggerRef,
71
100
  menuPopoverRef,
72
- components: {}
73
- }; // TODO Better way to narrow types ?
74
-
75
- const [open, setOpen] = useMenuOpenState(initialState);
76
- const [checkedValues, onCheckedValueChange] = useMenuSelectableState(initialState);
77
- return { ...initialState,
101
+ components: {},
102
+ openOnContext,
78
103
  open,
79
104
  setOpen,
80
105
  checkedValues,
81
- onCheckedValueChange
106
+ defaultCheckedValues,
107
+ onCheckedValueChange,
108
+ persistOnItemClick
82
109
  };
83
110
  };
84
111
  /**
@@ -127,7 +154,6 @@ const useMenuOpenState = state => {
127
154
 
128
155
  return (_a = state.onOpenChange) === null || _a === void 0 ? void 0 : _a.call(state, e, data);
129
156
  });
130
- const shouldHandleKeyboardRef = React.useRef(false);
131
157
  const shouldHandleTabRef = React.useRef(false);
132
158
  const pressedShiftRef = React.useRef(false);
133
159
  const setOpenTimeout = React.useRef(0);
@@ -150,9 +176,8 @@ const useMenuOpenState = state => {
150
176
  state.setContextTarget(undefined);
151
177
  }
152
178
 
153
- if (data.keyboard) {
154
- shouldHandleKeyboardRef.current = true;
155
- shouldHandleTabRef.current = e.key === 'Tab';
179
+ if (e.type === 'keydown' && e.key === Tab) {
180
+ shouldHandleTabRef.current = true;
156
181
  pressedShiftRef.current = e.shiftKey;
157
182
  }
158
183
 
@@ -257,7 +282,7 @@ const useMenuOpenState = state => {
257
282
  focusFirst();
258
283
  }
259
284
 
260
- if (shouldHandleKeyboardRef.current && !open) {
285
+ if (!open) {
261
286
  if (shouldHandleTabRef.current && !state.isSubmenu) {
262
287
  pressedShiftRef.current ? focusBeforeMenuTrigger() : focusAfterMenuTrigger();
263
288
  } else {
@@ -265,7 +290,6 @@ const useMenuOpenState = state => {
265
290
  }
266
291
  }
267
292
 
268
- shouldHandleKeyboardRef.current = false;
269
293
  shouldHandleTabRef.current = false;
270
294
  pressedShiftRef.current = false;
271
295
  }, [state.triggerRef, state.isSubmenu, open, focusFirst, focusAfterMenuTrigger, focusBeforeMenuTrigger]);
@@ -1 +1 @@
1
- {"version":3,"sources":["components/Menu/useMenu.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,yBAAT,EAAoC,cAApC,EAAoD,2BAApD,QAAuF,6BAAvF;AACA,SACE,oBADF,EAEE,KAFF,EAGE,iBAHF,EAIE,gBAJF,EAKE,kBALF,QAMO,2BANP;AAOA,SAAS,kBAAkB,IAAI,SAA/B,QAAgD,iCAAhD;AACA,SAAS,eAAT,QAAgC,wBAAhC;AACA,SAAS,eAAT,QAAgC,yBAAhC;AACA,SAAS,uBAAT,QAAwC,4BAAxC;AACA,SAAS,gBAAT,EAA2B,mBAA3B,QAAsD,mBAAt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,KAAA,CAAJ,GAAA,IAAA,GAAQ,KAAT,EAAgB,OAAhB,CAAP;AACD,CA/JD","sourcesContent":["import * as React from 'react';\nimport { usePositioningMouseTarget, usePositioning, resolvePositioningShorthand } from '@fluentui/react-positioning';\nimport {\n useControllableState,\n useId,\n useOnClickOutside,\n useEventCallback,\n useOnScrollOutside,\n} from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { elementContains } from '@fluentui/react-portal';\nimport { useFocusFinders } from '@fluentui/react-tabster';\nimport { useMenuContext_unstable } from '../../contexts/menuContext';\nimport { MENU_ENTER_EVENT, useOnMenuMouseEnter } from '../../utils/index';\nimport { useIsSubmenu } from '../../utils/useIsSubmenu';\nimport type { MenuOpenChangeData, MenuOpenEvents, MenuProps, MenuState } from './Menu.types';\n\n/**\n * Create the state required to render Menu.\n *\n * The returned state can be modified with hooks such as useMenuStyles,\n * before being passed to renderMenu_unstable.\n *\n * @param props - props from this instance of Menu\n */\nexport const useMenu_unstable = (props: MenuProps): MenuState => {\n const triggerId = useId('menu');\n const isSubmenu = useIsSubmenu();\n const [contextTarget, setContextTarget] = usePositioningMouseTarget();\n\n const positioningState = {\n position: isSubmenu ? ('after' as const) : ('below' as const),\n align: isSubmenu ? ('top' as const) : ('start' as const),\n target: props.openOnContext ? contextTarget : undefined,\n ...resolvePositioningShorthand(props.positioning),\n };\n\n const children = React.Children.toArray(props.children) as React.ReactElement[];\n\n if (process.env.NODE_ENV !== 'production') {\n if (children.length === 0) {\n // eslint-disable-next-line no-console\n console.warn('Menu must contain at least one child');\n }\n\n if (children.length > 2) {\n // eslint-disable-next-line no-console\n console.warn('Menu must contain at most two children');\n }\n }\n\n let menuTrigger: React.ReactElement | undefined = undefined;\n let menuPopover: React.ReactElement | undefined = undefined;\n if (children.length === 2) {\n menuTrigger = children[0];\n menuPopover = children[1];\n } else if (children.length === 1) {\n menuPopover = children[0];\n }\n const { targetRef: triggerRef, containerRef: menuPopoverRef } = usePositioning(positioningState);\n\n const initialState = {\n hoverDelay: 500,\n triggerId,\n isSubmenu: !!isSubmenu,\n openOnHover: !!isSubmenu,\n contextTarget,\n setContextTarget,\n ...props,\n closeOnScroll: props.closeOnScroll ?? false,\n menuTrigger,\n menuPopover,\n triggerRef,\n menuPopoverRef,\n components: {},\n } as const;\n\n // TODO Better way to narrow types ?\n\n const [open, setOpen] = useMenuOpenState(initialState);\n const [checkedValues, onCheckedValueChange] = useMenuSelectableState(initialState);\n\n return {\n ...initialState,\n open,\n setOpen,\n checkedValues,\n onCheckedValueChange,\n };\n};\n\n/**\n * Adds appropriate state values and handlers for selectable items\n * i.e checkboxes and radios\n */\nconst useMenuSelectableState = (\n state: Pick<MenuProps, 'checkedValues' | 'defaultCheckedValues' | 'onCheckedValueChange'>,\n) => {\n const [checkedValues, setCheckedValues] = useControllableState({\n state: state.checkedValues,\n defaultState: state.defaultCheckedValues,\n initialState: {},\n });\n const { onCheckedValueChange: onCheckedValueChangeOriginal } = state;\n const onCheckedValueChange: MenuState['onCheckedValueChange'] = useEventCallback((e, { name, checkedItems }) => {\n if (onCheckedValueChangeOriginal) {\n onCheckedValueChangeOriginal(e, { name, checkedItems });\n }\n\n setCheckedValues(s => {\n return s ? { ...s, [name]: checkedItems } : { [name]: checkedItems };\n });\n });\n\n return [checkedValues, onCheckedValueChange] as const;\n};\n\nconst useMenuOpenState = (\n state: Pick<\n MenuState,\n | 'isSubmenu'\n | 'menuPopoverRef'\n | 'onOpenChange'\n | 'setContextTarget'\n | 'triggerRef'\n | 'openOnContext'\n | 'closeOnScroll'\n > &\n Pick<MenuProps, 'open' | 'defaultOpen'>,\n) => {\n const { targetDocument } = useFluent();\n const parentSetOpen = useMenuContext_unstable(context => context.setOpen);\n const onOpenChange: MenuState['onOpenChange'] = useEventCallback((e, data) => state.onOpenChange?.(e, data));\n\n const shouldHandleKeyboardRef = React.useRef(false);\n const shouldHandleTabRef = React.useRef(false);\n const pressedShiftRef = React.useRef(false);\n const setOpenTimeout = React.useRef(0);\n const enteringTriggerRef = React.useRef(false);\n\n const [open, setOpenState] = useControllableState({\n state: state.open,\n defaultState: state.defaultOpen,\n initialState: false,\n });\n\n const trySetOpen = useEventCallback((e: MenuOpenEvents, data: MenuOpenChangeData) => {\n const event = e instanceof CustomEvent && e.type === MENU_ENTER_EVENT ? e.detail.nativeEvent : e;\n onOpenChange?.(event, { ...data });\n if (data.open && e.type === 'contextmenu') {\n state.setContextTarget(e as React.MouseEvent);\n }\n\n if (!data.open) {\n state.setContextTarget(undefined);\n }\n\n if (data.keyboard) {\n shouldHandleKeyboardRef.current = true;\n shouldHandleTabRef.current = (e as React.KeyboardEvent).key === 'Tab';\n pressedShiftRef.current = (e as React.KeyboardEvent).shiftKey;\n }\n\n if (data.bubble) {\n parentSetOpen(e, { ...data });\n }\n\n setOpenState(data.open);\n });\n\n const setOpen = useEventCallback((e: MenuOpenEvents, data: MenuOpenChangeData) => {\n clearTimeout(setOpenTimeout.current);\n if (!(e instanceof Event) && e.persist) {\n // < React 17 still uses pooled synthetic events\n e.persist();\n }\n\n if (e.type === 'mouseleave' || e.type === 'mouseenter' || e.type === 'mousemove' || e.type === MENU_ENTER_EVENT) {\n if (state.triggerRef.current?.contains(e.target as HTMLElement)) {\n enteringTriggerRef.current = e.type === 'mouseenter' || e.type === 'mousemove';\n }\n\n // FIXME leaking Node timeout type\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n setOpenTimeout.current = setTimeout(() => trySetOpen(e, data), state.hoverDelay);\n } else {\n trySetOpen(e, data);\n }\n });\n\n useOnClickOutside({\n contains: elementContains,\n disabled: !open,\n element: targetDocument,\n refs: [state.menuPopoverRef, !state.openOnContext && state.triggerRef].filter(\n Boolean,\n ) as React.MutableRefObject<HTMLElement>[],\n callback: e => setOpen(e, { open: false }),\n });\n\n // only close on scroll for context, or when closeOnScroll is specified\n const closeOnScroll = state.openOnContext || state.closeOnScroll;\n useOnScrollOutside({\n contains: elementContains,\n element: targetDocument,\n callback: ev => setOpen(ev, { open: false }),\n refs: [state.menuPopoverRef, !state.openOnContext && state.triggerRef].filter(\n Boolean,\n ) as React.MutableRefObject<HTMLElement>[],\n disabled: !open || !closeOnScroll,\n });\n\n useOnMenuMouseEnter({\n element: targetDocument,\n callback: e => {\n // When moving from a menu directly back to its trigger, this handler can close the menu\n // Explicitly check a flag to see if this situation happens\n if (!enteringTriggerRef.current) {\n setOpen(e, { open: false });\n }\n },\n disabled: !open,\n refs: [state.menuPopoverRef],\n });\n\n // Clear timeout on unmount\n // Setting state after a component unmounts can cause memory leaks\n React.useEffect(() => {\n return () => {\n clearTimeout(setOpenTimeout.current);\n };\n }, []);\n\n // Manage focus for open state\n const { findFirstFocusable, findNextFocusable, findPrevFocusable } = useFocusFinders();\n const focusFirst = React.useCallback(() => {\n const firstFocusable = findFirstFocusable(state.menuPopoverRef.current);\n firstFocusable?.focus();\n }, [findFirstFocusable, state.menuPopoverRef]);\n\n const focusAfterMenuTrigger = React.useCallback(() => {\n const nextFocusable = findNextFocusable(state.triggerRef.current);\n nextFocusable?.focus();\n }, [findNextFocusable, state.triggerRef]);\n\n const focusBeforeMenuTrigger = React.useCallback(() => {\n const prevFocusable = findPrevFocusable(state.triggerRef.current);\n prevFocusable?.focus();\n }, [findPrevFocusable, state.triggerRef]);\n\n React.useEffect(() => {\n if (open) {\n focusFirst();\n }\n }, [open, focusFirst]);\n\n React.useEffect(() => {\n if (open) {\n focusFirst();\n }\n\n if (shouldHandleKeyboardRef.current && !open) {\n if (shouldHandleTabRef.current && !state.isSubmenu) {\n pressedShiftRef.current ? focusBeforeMenuTrigger() : focusAfterMenuTrigger();\n } else {\n state.triggerRef.current?.focus();\n }\n }\n\n shouldHandleKeyboardRef.current = false;\n shouldHandleTabRef.current = false;\n pressedShiftRef.current = false;\n }, [state.triggerRef, state.isSubmenu, open, focusFirst, focusAfterMenuTrigger, focusBeforeMenuTrigger]);\n\n return [open ?? false, setOpen] as const;\n};\n"],"sourceRoot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K;;;IACnB,IAAI,IAAJ,EAAU;MACR,UAAU;IACX;;IAED,IAAI,CAAC,IAAL,EAAW;MACT,IAAI,kBAAkB,CAAC,OAAnB,IAA8B,CAAC,KAAK,CAAC,SAAzC,EAAoD;QAClD,eAAe,CAAC,OAAhB,GAA0B,sBAAsB,EAAhD,GAAqD,qBAAqB,EAA1E;MACD,CAFD,MAEO;QACL,CAAA,EAAA,GAAA,KAAK,CAAC,UAAN,CAAiB,OAAjB,MAAwB,IAAxB,IAAwB,EAAA,KAAA,KAAA,CAAxB,GAAwB,KAAA,CAAxB,GAAwB,EAAA,CAAE,KAAF,EAAxB;MACD;IACF;;IAED,kBAAkB,CAAC,OAAnB,GAA6B,KAA7B;IACA,eAAe,CAAC,OAAhB,GAA0B,KAA1B;EACD,CAfD,EAeG,CAAC,KAAK,CAAC,UAAP,EAAmB,KAAK,CAAC,SAAzB,EAAoC,IAApC,EAA0C,UAA1C,EAAsD,qBAAtD,EAA6E,sBAA7E,CAfH;EAiBA,OAAO,CAAC,IAAI,KAAA,IAAJ,IAAA,IAAI,KAAA,KAAA,CAAJ,GAAA,IAAA,GAAQ,KAAT,EAAgB,OAAhB,CAAP;AACD,CA7JD","sourcesContent":["import * as React from 'react';\nimport { usePositioningMouseTarget, usePositioning, resolvePositioningShorthand } from '@fluentui/react-positioning';\nimport {\n useControllableState,\n useId,\n useOnClickOutside,\n useEventCallback,\n useOnScrollOutside,\n} from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { elementContains } from '@fluentui/react-portal';\nimport { useFocusFinders } from '@fluentui/react-tabster';\nimport { useMenuContext_unstable } from '../../contexts/menuContext';\nimport { MENU_ENTER_EVENT, useOnMenuMouseEnter } from '../../utils/index';\nimport { useIsSubmenu } from '../../utils/useIsSubmenu';\nimport type { MenuOpenChangeData, MenuOpenEvents, MenuProps, MenuState } from './Menu.types';\nimport { Tab } from '@fluentui/keyboard-keys';\n\n/**\n * Create the state required to render Menu.\n *\n * The returned state can be modified with hooks such as useMenuStyles,\n * before being passed to renderMenu_unstable.\n *\n * @param props - props from this instance of Menu\n */\nexport const useMenu_unstable = (props: MenuProps): MenuState => {\n const {\n hoverDelay = 500,\n inline = false,\n hasCheckmarks = false,\n hasIcons = false,\n closeOnScroll = false,\n openOnContext = false,\n persistOnItemClick = false,\n defaultCheckedValues,\n } = props;\n const triggerId = useId('menu');\n const isSubmenu = useIsSubmenu();\n const [contextTarget, setContextTarget] = usePositioningMouseTarget();\n\n const positioningState = {\n position: isSubmenu ? ('after' as const) : ('below' as const),\n align: isSubmenu ? ('top' as const) : ('start' as const),\n target: props.openOnContext ? contextTarget : undefined,\n ...resolvePositioningShorthand(props.positioning),\n };\n\n const children = React.Children.toArray(props.children) as React.ReactElement[];\n\n if (process.env.NODE_ENV !== 'production') {\n if (children.length === 0) {\n // eslint-disable-next-line no-console\n console.warn('Menu must contain at least one child');\n }\n\n if (children.length > 2) {\n // eslint-disable-next-line no-console\n console.warn('Menu must contain at most two children');\n }\n }\n\n let menuTrigger: React.ReactElement | undefined = undefined;\n let menuPopover: React.ReactElement | undefined = undefined;\n if (children.length === 2) {\n menuTrigger = children[0];\n menuPopover = children[1];\n } else if (children.length === 1) {\n menuPopover = children[0];\n }\n const { targetRef: triggerRef, containerRef: menuPopoverRef } = usePositioning(positioningState);\n\n // TODO Better way to narrow types ?\n\n const [open, setOpen] = useMenuOpenState({\n hoverDelay,\n isSubmenu,\n setContextTarget,\n closeOnScroll,\n menuPopoverRef,\n triggerRef,\n open: props.open,\n defaultOpen: props.defaultOpen,\n onOpenChange: props.onOpenChange,\n openOnContext,\n });\n\n const [checkedValues, onCheckedValueChange] = useMenuSelectableState({\n checkedValues: props.checkedValues,\n defaultCheckedValues,\n onCheckedValueChange: props.onCheckedValueChange,\n });\n\n return {\n inline,\n hoverDelay,\n triggerId,\n isSubmenu,\n openOnHover: isSubmenu,\n contextTarget,\n setContextTarget,\n hasCheckmarks,\n hasIcons,\n closeOnScroll,\n menuTrigger,\n menuPopover,\n triggerRef,\n menuPopoverRef,\n components: {},\n openOnContext,\n open,\n setOpen,\n checkedValues,\n defaultCheckedValues,\n onCheckedValueChange,\n persistOnItemClick,\n };\n};\n\n/**\n * Adds appropriate state values and handlers for selectable items\n * i.e checkboxes and radios\n */\nconst useMenuSelectableState = (\n state: Pick<MenuProps, 'checkedValues' | 'defaultCheckedValues' | 'onCheckedValueChange'>,\n) => {\n const [checkedValues, setCheckedValues] = useControllableState({\n state: state.checkedValues,\n defaultState: state.defaultCheckedValues,\n initialState: {},\n });\n const { onCheckedValueChange: onCheckedValueChangeOriginal } = state;\n const onCheckedValueChange: MenuState['onCheckedValueChange'] = useEventCallback((e, { name, checkedItems }) => {\n if (onCheckedValueChangeOriginal) {\n onCheckedValueChangeOriginal(e, { name, checkedItems });\n }\n\n setCheckedValues(s => {\n return s ? { ...s, [name]: checkedItems } : { [name]: checkedItems };\n });\n });\n\n return [checkedValues, onCheckedValueChange] as const;\n};\n\nconst useMenuOpenState = (\n state: Pick<\n MenuState,\n | 'isSubmenu'\n | 'menuPopoverRef'\n | 'onOpenChange'\n | 'setContextTarget'\n | 'triggerRef'\n | 'openOnContext'\n | 'closeOnScroll'\n | 'hoverDelay'\n > &\n Pick<MenuProps, 'open' | 'defaultOpen'>,\n) => {\n const { targetDocument } = useFluent();\n const parentSetOpen = useMenuContext_unstable(context => context.setOpen);\n const onOpenChange: MenuState['onOpenChange'] = useEventCallback((e, data) => state.onOpenChange?.(e, data));\n\n const shouldHandleTabRef = React.useRef(false);\n const pressedShiftRef = React.useRef(false);\n const setOpenTimeout = React.useRef(0);\n const enteringTriggerRef = React.useRef(false);\n\n const [open, setOpenState] = useControllableState({\n state: state.open,\n defaultState: state.defaultOpen,\n initialState: false,\n });\n\n const trySetOpen = useEventCallback((e: MenuOpenEvents, data: MenuOpenChangeData) => {\n const event = e instanceof CustomEvent && e.type === MENU_ENTER_EVENT ? e.detail.nativeEvent : e;\n onOpenChange?.(event, { ...data });\n if (data.open && e.type === 'contextmenu') {\n state.setContextTarget(e as React.MouseEvent);\n }\n\n if (!data.open) {\n state.setContextTarget(undefined);\n }\n\n if (e.type === 'keydown' && (e as React.KeyboardEvent<HTMLElement>).key === Tab) {\n shouldHandleTabRef.current = true;\n pressedShiftRef.current = (e as React.KeyboardEvent<HTMLElement>).shiftKey;\n }\n\n if (data.bubble) {\n parentSetOpen(e, { ...data });\n }\n\n setOpenState(data.open);\n });\n\n const setOpen = useEventCallback((e: MenuOpenEvents, data: MenuOpenChangeData) => {\n clearTimeout(setOpenTimeout.current);\n if (!(e instanceof Event) && e.persist) {\n // < React 17 still uses pooled synthetic events\n e.persist();\n }\n\n if (e.type === 'mouseleave' || e.type === 'mouseenter' || e.type === 'mousemove' || e.type === MENU_ENTER_EVENT) {\n if (state.triggerRef.current?.contains(e.target as HTMLElement)) {\n enteringTriggerRef.current = e.type === 'mouseenter' || e.type === 'mousemove';\n }\n\n // FIXME leaking Node timeout type\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n setOpenTimeout.current = setTimeout(() => trySetOpen(e, data), state.hoverDelay);\n } else {\n trySetOpen(e, data);\n }\n });\n\n useOnClickOutside({\n contains: elementContains,\n disabled: !open,\n element: targetDocument,\n refs: [state.menuPopoverRef, !state.openOnContext && state.triggerRef].filter(\n Boolean,\n ) as React.MutableRefObject<HTMLElement>[],\n callback: e => setOpen(e, { open: false }),\n });\n\n // only close on scroll for context, or when closeOnScroll is specified\n const closeOnScroll = state.openOnContext || state.closeOnScroll;\n useOnScrollOutside({\n contains: elementContains,\n element: targetDocument,\n callback: ev => setOpen(ev, { open: false }),\n refs: [state.menuPopoverRef, !state.openOnContext && state.triggerRef].filter(\n Boolean,\n ) as React.MutableRefObject<HTMLElement>[],\n disabled: !open || !closeOnScroll,\n });\n\n useOnMenuMouseEnter({\n element: targetDocument,\n callback: e => {\n // When moving from a menu directly back to its trigger, this handler can close the menu\n // Explicitly check a flag to see if this situation happens\n if (!enteringTriggerRef.current) {\n setOpen(e, { open: false });\n }\n },\n disabled: !open,\n refs: [state.menuPopoverRef],\n });\n\n // Clear timeout on unmount\n // Setting state after a component unmounts can cause memory leaks\n React.useEffect(() => {\n return () => {\n clearTimeout(setOpenTimeout.current);\n };\n }, []);\n\n // Manage focus for open state\n const { findFirstFocusable, findNextFocusable, findPrevFocusable } = useFocusFinders();\n const focusFirst = React.useCallback(() => {\n const firstFocusable = findFirstFocusable(state.menuPopoverRef.current);\n firstFocusable?.focus();\n }, [findFirstFocusable, state.menuPopoverRef]);\n\n const focusAfterMenuTrigger = React.useCallback(() => {\n const nextFocusable = findNextFocusable(state.triggerRef.current);\n nextFocusable?.focus();\n }, [findNextFocusable, state.triggerRef]);\n\n const focusBeforeMenuTrigger = React.useCallback(() => {\n const prevFocusable = findPrevFocusable(state.triggerRef.current);\n prevFocusable?.focus();\n }, [findPrevFocusable, state.triggerRef]);\n\n React.useEffect(() => {\n if (open) {\n focusFirst();\n }\n }, [open, focusFirst]);\n\n React.useEffect(() => {\n if (open) {\n focusFirst();\n }\n\n if (!open) {\n if (shouldHandleTabRef.current && !state.isSubmenu) {\n pressedShiftRef.current ? focusBeforeMenuTrigger() : focusAfterMenuTrigger();\n } else {\n state.triggerRef.current?.focus();\n }\n }\n\n shouldHandleTabRef.current = false;\n pressedShiftRef.current = false;\n }, [state.triggerRef, state.isSubmenu, open, focusFirst, focusAfterMenuTrigger, focusBeforeMenuTrigger]);\n\n return [open ?? false, setOpen] as const;\n};\n"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"file":"MenuItem.types.js","sourceRoot":"../src/","sources":["components/MenuItem/MenuItem.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\n\nexport type MenuItemSlots = {\n root: Slot<'div'>;\n\n /**\n * Icon slot rendered before children content\n */\n icon?: Slot<'span'>;\n\n /**\n * A helper slot for alignment when a menu item is used with selectable menuitems\n * Avoid using this slot as a replacement for MenuItemCheckbox and MenuItemRadio components\n */\n checkmark?: Slot<'span'>;\n\n /**\n * Icon slot that shows the indicator for a submenu\n */\n submenuIndicator?: Slot<'span'>;\n\n /**\n * Component children are placed in this slot\n * Avoid using the `children` property in this slot in favour of Component children whenever possible\n */\n content?: Slot<'span'>;\n\n /**\n * Secondary content rendered opposite the primary content (e.g Shortcut text)\n */\n secondaryContent?: Slot<'span'>;\n};\n\nexport type MenuItemProps = ComponentProps<Partial<MenuItemSlots>> & {\n /**\n * Applies disabled styles to menu item but remains focusable\n *\n * @default false\n */\n disabled?: boolean;\n\n /**\n * If the menu item is a trigger for a submenu\n *\n * @default false\n */\n hasSubmenu?: boolean;\n\n /**\n * Clicking on the menu item will not dismiss an open menu\n *\n * @default false\n */\n persistOnClick?: boolean;\n};\n\nexport type MenuItemState = ComponentState<MenuItemSlots> &\n Pick<MenuItemProps, 'disabled' | 'hasSubmenu' | 'persistOnClick'>;\n"]}
1
+ {"version":3,"file":"MenuItem.types.js","sourceRoot":"../src/","sources":["components/MenuItem/MenuItem.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ARIAButtonSlotProps } from '@fluentui/react-aria';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\n\nexport type MenuItemSlots = {\n root: Slot<ARIAButtonSlotProps<'div'>>;\n\n /**\n * Icon slot rendered before children content\n */\n icon?: Slot<'span'>;\n\n /**\n * A helper slot for alignment when a menu item is used with selectable menuitems\n * Avoid using this slot as a replacement for MenuItemCheckbox and MenuItemRadio components\n */\n checkmark?: Slot<'span'>;\n\n /**\n * Icon slot that shows the indicator for a submenu\n */\n submenuIndicator?: Slot<'span'>;\n\n /**\n * Component children are placed in this slot\n * Avoid using the `children` property in this slot in favour of Component children whenever possible\n */\n content?: Slot<'span'>;\n\n /**\n * Secondary content rendered opposite the primary content (e.g Shortcut text)\n */\n secondaryContent?: Slot<'span'>;\n};\n\nexport type MenuItemProps = ComponentProps<Partial<MenuItemSlots>> & {\n /**\n * If the menu item is a trigger for a submenu\n *\n * @default false\n */\n hasSubmenu?: boolean;\n\n /**\n * Clicking on the menu item will not dismiss an open menu\n *\n * @default false\n */\n persistOnClick?: boolean;\n};\n\nexport type MenuItemState = ComponentState<MenuItemSlots> &\n Required<Pick<MenuItemProps, 'disabled' | 'hasSubmenu' | 'persistOnClick'>> & {\n isNativeButton: boolean;\n };\n"]}