@fluentui/react-menu 9.0.4 → 9.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. package/CHANGELOG.json +120 -5
  2. package/CHANGELOG.md +31 -6
  3. package/dist/index.d.ts +15 -9
  4. package/lib/components/Menu/Menu.types.js.map +1 -1
  5. package/lib/components/Menu/useMenu.js +42 -16
  6. package/lib/components/Menu/useMenu.js.map +1 -1
  7. package/lib/components/MenuItem/useMenuItemStyles.js +29 -29
  8. package/lib/components/MenuPopover/useMenuPopover.js +6 -2
  9. package/lib/components/MenuPopover/useMenuPopover.js.map +1 -1
  10. package/lib/components/MenuTrigger/MenuTrigger.types.js.map +1 -1
  11. package/lib/components/MenuTrigger/useMenuTrigger.js +18 -23
  12. package/lib/components/MenuTrigger/useMenuTrigger.js.map +1 -1
  13. package/lib/contexts/menuContext.js +8 -6
  14. package/lib/contexts/menuContext.js.map +1 -1
  15. package/lib/contexts/menuGroupContext.js +9 -5
  16. package/lib/contexts/menuGroupContext.js.map +1 -1
  17. package/lib/contexts/menuListContext.js +5 -5
  18. package/lib/contexts/menuListContext.js.map +1 -1
  19. package/lib/contexts/menuTriggerContext.js +7 -3
  20. package/lib/contexts/menuTriggerContext.js.map +1 -1
  21. package/lib-commonjs/components/Menu/useMenu.js +42 -16
  22. package/lib-commonjs/components/Menu/useMenu.js.map +1 -1
  23. package/lib-commonjs/components/MenuItem/useMenuItemStyles.js +29 -29
  24. package/lib-commonjs/components/MenuPopover/useMenuPopover.js +6 -2
  25. package/lib-commonjs/components/MenuPopover/useMenuPopover.js.map +1 -1
  26. package/lib-commonjs/components/MenuTrigger/useMenuTrigger.js +17 -22
  27. package/lib-commonjs/components/MenuTrigger/useMenuTrigger.js.map +1 -1
  28. package/lib-commonjs/contexts/menuContext.js +8 -6
  29. package/lib-commonjs/contexts/menuContext.js.map +1 -1
  30. package/lib-commonjs/contexts/menuGroupContext.js +9 -5
  31. package/lib-commonjs/contexts/menuGroupContext.js.map +1 -1
  32. package/lib-commonjs/contexts/menuListContext.js +5 -5
  33. package/lib-commonjs/contexts/menuListContext.js.map +1 -1
  34. package/lib-commonjs/contexts/menuTriggerContext.js +7 -3
  35. package/lib-commonjs/contexts/menuTriggerContext.js.map +1 -1
  36. package/package.json +15 -14
  37. package/dist/tsdoc-metadata.json +0 -11
package/CHANGELOG.json CHANGED
@@ -2,7 +2,122 @@
2
2
  "name": "@fluentui/react-menu",
3
3
  "entries": [
4
4
  {
5
- "date": "Wed, 03 Aug 2022 16:00:18 GMT",
5
+ "date": "Thu, 15 Sep 2022 09:44:29 GMT",
6
+ "tag": "@fluentui/react-menu_v9.1.0",
7
+ "version": "9.1.0",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "behowell@microsoft.com",
12
+ "package": "@fluentui/react-menu",
13
+ "commit": "e598325b985cad3e5057f00893e0176416edd292",
14
+ "comment": "refactor: Replace useMergedEventCallbacks utility with mergeCallbacks"
15
+ },
16
+ {
17
+ "author": "olfedias@microsoft.com",
18
+ "package": "@fluentui/react-menu",
19
+ "commit": "e610024474cfe5d45f61501a8b6a21daf4c794a2",
20
+ "comment": "chore: Update Griffel to latest version"
21
+ },
22
+ {
23
+ "author": "bernardo.sunderhus@gmail.com",
24
+ "package": "@fluentui/react-menu",
25
+ "commit": "6c6fe4c8246abec30d9cd3ba2079d379c4d7acb8",
26
+ "comment": "bugfix: stops propagation on Escape keydown"
27
+ },
28
+ {
29
+ "author": "lingfangao@hotmail.com",
30
+ "package": "@fluentui/react-menu",
31
+ "commit": "a0cfab0e5f74e3a3bfa9c269fff574295042d7f2",
32
+ "comment": "chore: fix no-context-default-value lint violations"
33
+ }
34
+ ],
35
+ "none": [
36
+ {
37
+ "author": "martinhochel@microsoft.com",
38
+ "package": "@fluentui/react-menu",
39
+ "commit": "e6cf183695d6d67a24e038c49a876224e5ed35e5",
40
+ "comment": "chore: update package scaffold"
41
+ },
42
+ {
43
+ "author": "martinhochel@microsoft.com",
44
+ "package": "@fluentui/react-menu",
45
+ "commit": "ba9444d594f3a960cc590eae5237c08bf7c5a07f",
46
+ "comment": "chore: consume cypress.config from it's package boundary"
47
+ },
48
+ {
49
+ "author": "bernardo.sunderhus@gmail.com",
50
+ "package": "@fluentui/react-menu",
51
+ "commit": "a105236ca0a6eac1035fee7bfca274972fb89da1",
52
+ "comment": "chore(react-menu): stop spreading props on state"
53
+ }
54
+ ],
55
+ "minor": [
56
+ {
57
+ "author": "bernardo.sunderhus@gmail.com",
58
+ "package": "@fluentui/react-menu",
59
+ "commit": "0547583ebcebe746110e5ef8d0599b0972b1f4c6",
60
+ "comment": "chore(react-menu): Updates trigger to use useARIAButton"
61
+ },
62
+ {
63
+ "author": "beachball",
64
+ "package": "@fluentui/react-menu",
65
+ "comment": "Bump @fluentui/react-aria to v9.2.0",
66
+ "commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
67
+ },
68
+ {
69
+ "author": "beachball",
70
+ "package": "@fluentui/react-menu",
71
+ "comment": "Bump @fluentui/react-context-selector to v9.0.3",
72
+ "commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
73
+ },
74
+ {
75
+ "author": "beachball",
76
+ "package": "@fluentui/react-menu",
77
+ "comment": "Bump @fluentui/react-portal to v9.0.5",
78
+ "commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
79
+ },
80
+ {
81
+ "author": "beachball",
82
+ "package": "@fluentui/react-menu",
83
+ "comment": "Bump @fluentui/react-positioning to v9.2.0",
84
+ "commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
85
+ },
86
+ {
87
+ "author": "beachball",
88
+ "package": "@fluentui/react-menu",
89
+ "comment": "Bump @fluentui/react-shared-contexts to v9.0.1",
90
+ "commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
91
+ },
92
+ {
93
+ "author": "beachball",
94
+ "package": "@fluentui/react-menu",
95
+ "comment": "Bump @fluentui/react-tabster to v9.1.1",
96
+ "commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
97
+ },
98
+ {
99
+ "author": "beachball",
100
+ "package": "@fluentui/react-menu",
101
+ "comment": "Bump @fluentui/react-theme to v9.1.0",
102
+ "commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
103
+ },
104
+ {
105
+ "author": "beachball",
106
+ "package": "@fluentui/react-menu",
107
+ "comment": "Bump @fluentui/react-utilities to v9.1.0",
108
+ "commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
109
+ },
110
+ {
111
+ "author": "beachball",
112
+ "package": "@fluentui/react-menu",
113
+ "comment": "Bump @fluentui/react-conformance-griffel to v9.0.0-beta.13",
114
+ "commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
115
+ }
116
+ ]
117
+ }
118
+ },
119
+ {
120
+ "date": "Wed, 03 Aug 2022 16:03:51 GMT",
6
121
  "tag": "@fluentui/react-menu_v9.0.4",
7
122
  "version": "9.0.4",
8
123
  "comments": {
@@ -37,25 +152,25 @@
37
152
  "author": "beachball",
38
153
  "package": "@fluentui/react-menu",
39
154
  "comment": "Bump @fluentui/react-portal to v9.0.4",
40
- "commit": "54bc6105c5c9c9023da35d4670239e44117ed4a5"
155
+ "commit": "ee4a8be0d0831a6615f878f98db6a97cc61a802d"
41
156
  },
42
157
  {
43
158
  "author": "beachball",
44
159
  "package": "@fluentui/react-menu",
45
160
  "comment": "Bump @fluentui/react-positioning to v9.1.2",
46
- "commit": "54bc6105c5c9c9023da35d4670239e44117ed4a5"
161
+ "commit": "ee4a8be0d0831a6615f878f98db6a97cc61a802d"
47
162
  },
48
163
  {
49
164
  "author": "beachball",
50
165
  "package": "@fluentui/react-menu",
51
166
  "comment": "Bump @fluentui/react-tabster to v9.1.0",
52
- "commit": "54bc6105c5c9c9023da35d4670239e44117ed4a5"
167
+ "commit": "ee4a8be0d0831a6615f878f98db6a97cc61a802d"
53
168
  },
54
169
  {
55
170
  "author": "beachball",
56
171
  "package": "@fluentui/react-menu",
57
172
  "comment": "Bump @fluentui/react-conformance-griffel to v9.0.0-beta.12",
58
- "commit": "54bc6105c5c9c9023da35d4670239e44117ed4a5"
173
+ "commit": "ee4a8be0d0831a6615f878f98db6a97cc61a802d"
59
174
  }
60
175
  ]
61
176
  }
package/CHANGELOG.md CHANGED
@@ -1,22 +1,47 @@
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 Thu, 15 Sep 2022 09:44:29 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.1.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-menu_v9.1.0)
8
+
9
+ Thu, 15 Sep 2022 09:44:29 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-menu_v9.0.4..@fluentui/react-menu_v9.1.0)
11
+
12
+ ### Minor changes
13
+
14
+ - chore(react-menu): Updates trigger to use useARIAButton ([PR #24177](https://github.com/microsoft/fluentui/pull/24177) by bernardo.sunderhus@gmail.com)
15
+ - Bump @fluentui/react-aria to v9.2.0 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
16
+ - Bump @fluentui/react-context-selector to v9.0.3 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
17
+ - Bump @fluentui/react-portal to v9.0.5 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
18
+ - Bump @fluentui/react-positioning to v9.2.0 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
19
+ - Bump @fluentui/react-shared-contexts to v9.0.1 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
20
+ - Bump @fluentui/react-tabster to v9.1.1 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
21
+ - Bump @fluentui/react-theme to v9.1.0 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
22
+ - Bump @fluentui/react-utilities to v9.1.0 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
23
+ - Bump @fluentui/react-conformance-griffel to v9.0.0-beta.13 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
24
+
25
+ ### Patches
26
+
27
+ - refactor: Replace useMergedEventCallbacks utility with mergeCallbacks ([PR #24152](https://github.com/microsoft/fluentui/pull/24152) by behowell@microsoft.com)
28
+ - chore: Update Griffel to latest version ([PR #24221](https://github.com/microsoft/fluentui/pull/24221) by olfedias@microsoft.com)
29
+ - bugfix: stops propagation on Escape keydown ([PR #24750](https://github.com/microsoft/fluentui/pull/24750) by bernardo.sunderhus@gmail.com)
30
+ - chore: fix no-context-default-value lint violations ([PR #24276](https://github.com/microsoft/fluentui/pull/24276) by lingfangao@hotmail.com)
31
+
7
32
  ## [9.0.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-menu_v9.0.4)
8
33
 
9
- Wed, 03 Aug 2022 16:00:18 GMT
34
+ Wed, 03 Aug 2022 16:03:51 GMT
10
35
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-menu_v9.0.3..@fluentui/react-menu_v9.0.4)
11
36
 
12
37
  ### Patches
13
38
 
14
39
  - chore: Bump Griffel dependencies ([PR #24114](https://github.com/microsoft/fluentui/pull/24114) by miroslav.stastny@microsoft.com)
15
40
  - 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)
41
+ - Bump @fluentui/react-portal to v9.0.4 ([PR #24131](https://github.com/microsoft/fluentui/pull/24131) by beachball)
42
+ - Bump @fluentui/react-positioning to v9.1.2 ([PR #24131](https://github.com/microsoft/fluentui/pull/24131) by beachball)
43
+ - Bump @fluentui/react-tabster to v9.1.0 ([PR #24131](https://github.com/microsoft/fluentui/pull/24131) by beachball)
44
+ - Bump @fluentui/react-conformance-griffel to v9.0.0-beta.12 ([PR #24131](https://github.com/microsoft/fluentui/pull/24131) by beachball)
20
45
 
21
46
  ## [9.0.3](https://github.com/microsoft/fluentui/tree/@fluentui/react-menu_v9.0.3)
22
47
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  /// <reference types="react" />
2
2
 
3
+ import { ARIAButtonResultProps } from '@fluentui/react-aria';
4
+ import { ARIAButtonType } from '@fluentui/react-aria';
3
5
  import type { ComponentProps } from '@fluentui/react-utilities';
4
6
  import type { ComponentState } from '@fluentui/react-utilities';
5
7
  import type { ContextSelector } from '@fluentui/react-context-selector';
@@ -30,7 +32,7 @@ export declare type MenuCheckedValueChangeEvent = React_2.MouseEvent | React_2.K
30
32
  *
31
33
  * Extends and drills down MenuList props to simplify API
32
34
  */
33
- export declare type MenuContextValue = MenuListProps & Pick<MenuState, 'openOnHover' | 'openOnContext' | 'triggerRef' | 'menuPopoverRef' | 'setOpen' | 'isSubmenu' | 'triggerId' | 'hasIcons' | 'hasCheckmarks' | 'persistOnItemClick' | 'inline'> & {
35
+ export declare type MenuContextValue = Pick<MenuState, 'openOnHover' | 'openOnContext' | 'triggerRef' | 'menuPopoverRef' | 'setOpen' | 'isSubmenu' | 'triggerId' | 'hasIcons' | 'hasCheckmarks' | 'persistOnItemClick' | 'inline' | 'checkedValues' | 'onCheckedValueChange' | 'defaultCheckedValues'> & {
34
36
  open: boolean;
35
37
  triggerId: string;
36
38
  };
@@ -421,7 +423,7 @@ export declare type MenuSplitGroupSlots = {
421
423
  */
422
424
  export declare type MenuSplitGroupState = ComponentState<MenuSplitGroupSlots>;
423
425
 
424
- export declare type MenuState = ComponentState<MenuSlots> & Pick<MenuProps, 'defaultCheckedValues' | 'hasCheckmarks' | 'hasIcons' | 'inline' | 'onOpenChange' | 'openOnContext' | 'persistOnItemClick'> & Required<Pick<MenuProps, 'checkedValues' | 'onCheckedValueChange' | 'open' | 'openOnHover' | 'closeOnScroll'>> & {
426
+ 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
427
  /**
426
428
  * Anchors the popper to the mouse click for context events
427
429
  */
@@ -469,10 +471,16 @@ export declare const MenuTrigger: React_2.FC<MenuTriggerProps> & FluentTriggerCo
469
471
  /**
470
472
  * Props that are passed to the child of the MenuTrigger when cloned to ensure correct behaviour for the Menu
471
473
  */
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
- };
474
+ export declare type MenuTriggerChildProps<Type extends ARIAButtonType = ARIAButtonType, Props = {}> = ARIAButtonResultProps<Type, Props & {
475
+ 'aria-haspopup': 'menu';
476
+ 'aria-expanded'?: boolean;
477
+ id: string;
478
+ ref: React_2.Ref<never>;
479
+ onMouseEnter: React_2.MouseEventHandler<HTMLButtonElement & HTMLAnchorElement & HTMLDivElement>;
480
+ onMouseLeave: React_2.MouseEventHandler<HTMLButtonElement & HTMLAnchorElement & HTMLDivElement>;
481
+ onMouseMove: React_2.MouseEventHandler<HTMLButtonElement & HTMLAnchorElement & HTMLDivElement>;
482
+ onContextMenu: React_2.MouseEventHandler<HTMLButtonElement & HTMLAnchorElement & HTMLDivElement>;
483
+ }>;
476
484
 
477
485
  export declare const MenuTriggerContextProvider: React_2.Provider<boolean>;
478
486
 
@@ -480,9 +488,7 @@ export declare type MenuTriggerProps = {
480
488
  /**
481
489
  * Explicitly require single child or render function
482
490
  */
483
- children: (React_2.ReactElement & {
484
- ref?: React_2.Ref<unknown>;
485
- }) | ((props: MenuTriggerChildProps) => React_2.ReactElement | null);
491
+ children: React_2.ReactElement | ((props: MenuTriggerChildProps) => React_2.ReactElement | null);
486
492
  };
487
493
 
488
494
  export declare type MenuTriggerState = {
@@ -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 */\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"]}
@@ -17,8 +17,16 @@ import { useIsSubmenu } from '../../utils/useIsSubmenu';
17
17
  */
18
18
 
19
19
  export const useMenu_unstable = props => {
20
- var _a;
21
-
20
+ const {
21
+ hoverDelay = 500,
22
+ inline = false,
23
+ hasCheckmarks = false,
24
+ hasIcons = false,
25
+ closeOnScroll = false,
26
+ openOnContext = false,
27
+ persistOnItemClick = false,
28
+ defaultCheckedValues
29
+ } = props;
22
30
  const triggerId = useId('menu');
23
31
  const isSubmenu = useIsSubmenu();
24
32
  const [contextTarget, setContextTarget] = usePositioningMouseTarget();
@@ -55,30 +63,48 @@ export const useMenu_unstable = props => {
55
63
  const {
56
64
  targetRef: triggerRef,
57
65
  containerRef: menuPopoverRef
58
- } = usePositioning(positioningState);
59
- const initialState = {
60
- hoverDelay: 500,
66
+ } = usePositioning(positioningState); // TODO Better way to narrow types ?
67
+
68
+ const [open, setOpen] = useMenuOpenState({
69
+ hoverDelay,
70
+ isSubmenu,
71
+ setContextTarget,
72
+ closeOnScroll,
73
+ menuPopoverRef,
74
+ triggerRef,
75
+ open: props.open,
76
+ defaultOpen: props.defaultOpen,
77
+ onOpenChange: props.onOpenChange,
78
+ openOnContext
79
+ });
80
+ const [checkedValues, onCheckedValueChange] = useMenuSelectableState({
81
+ checkedValues: props.checkedValues,
82
+ defaultCheckedValues,
83
+ onCheckedValueChange: props.onCheckedValueChange
84
+ });
85
+ return {
86
+ inline,
87
+ hoverDelay,
61
88
  triggerId,
62
- isSubmenu: !!isSubmenu,
63
- openOnHover: !!isSubmenu,
89
+ isSubmenu,
90
+ openOnHover: isSubmenu,
64
91
  contextTarget,
65
92
  setContextTarget,
66
- ...props,
67
- closeOnScroll: (_a = props.closeOnScroll) !== null && _a !== void 0 ? _a : false,
93
+ hasCheckmarks,
94
+ hasIcons,
95
+ closeOnScroll,
68
96
  menuTrigger,
69
97
  menuPopover,
70
98
  triggerRef,
71
99
  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,
100
+ components: {},
101
+ openOnContext,
78
102
  open,
79
103
  setOpen,
80
104
  checkedValues,
81
- onCheckedValueChange
105
+ defaultCheckedValues,
106
+ onCheckedValueChange,
107
+ persistOnItemClick
82
108
  };
83
109
  };
84
110
  /**
@@ -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,mBAAtD;AACA,SAAS,YAAT,QAA6B,0BAA7B;AAGA;;;;;;;AAOG;;AACH,OAAO,MAAM,gBAAgB,GAAI,KAAD,IAAgC;;;EAC9D,MAAM,SAAS,GAAG,KAAK,CAAC,MAAD,CAAvB;EACA,MAAM,SAAS,GAAG,YAAY,EAA9B;EACA,MAAM,CAAC,aAAD,EAAgB,gBAAhB,IAAoC,yBAAyB,EAAnE;EAEA,MAAM,gBAAgB,GAAG;IACvB,QAAQ,EAAE,SAAS,GAAI,OAAJ,GAAyB,OADrB;IAEvB,KAAK,EAAE,SAAS,GAAI,KAAJ,GAAuB,OAFhB;IAGvB,MAAM,EAAE,KAAK,CAAC,aAAN,GAAsB,aAAtB,GAAsC,SAHvB;IAIvB,GAAG,2BAA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C,SAAN,CAAgB,MAAK;;;IACnB,IAAI,IAAJ,EAAU;MACR,UAAU;IACX;;IAED,IAAI,uBAAuB,CAAC,OAAxB,IAAmC,CAAC,IAAxC,EAA8C;MAC5C,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,uBAAuB,CAAC,OAAxB,GAAkC,KAAlC;IACA,kBAAkB,CAAC,OAAnB,GAA6B,KAA7B;IACA,eAAe,CAAC,OAAhB,GAA0B,KAA1B;EACD,CAhBD,EAgBG,CAAC,KAAK,CAAC,UAAP,EAAmB,KAAK,CAAC,SAAzB,EAAoC,IAApC,EAA0C,UAA1C,EAAsD,qBAAtD,EAA6E,sBAA7E,CAhBH;EAkBA,OAAO,CAAC,IAAI,KAAA,IAAJ,IAAA,IAAI,KAAA,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":"../src/"}
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,mBAAtD;AACA,SAAS,YAAT,QAA6B,0BAA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;MACD;IACF;;IAED,uBAAuB,CAAC,OAAxB,GAAkC,KAAlC;IACA,kBAAkB,CAAC,OAAnB,GAA6B,KAA7B;IACA,eAAe,CAAC,OAAhB,GAA0B,KAA1B;EACD,CAhBD,EAgBG,CAAC,KAAK,CAAC,UAAP,EAAmB,KAAK,CAAC,SAAzB,EAAoC,IAApC,EAA0C,UAA1C,EAAsD,qBAAtD,EAA6E,sBAA7E,CAhBH;EAkBA,OAAO,CAAC,IAAI,KAAA,IAAJ,IAAA,IAAI,KAAA,KAAA,CAAJ,GAAA,IAAA,GAAQ,KAAT,EAAgB,OAAhB,CAAP;AACD,CAhKD","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 {\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 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":"../src/"}
@@ -16,34 +16,34 @@ const useStyles = /*#__PURE__*/__styles({
16
16
  "focusIndicator": {
17
17
  "Brovlpu": "ftqa4ok",
18
18
  "B486eqv": "f2hkw1w",
19
- "Bvjrn4i": "fvvvjju",
20
- "Bfjx6ro": ["f1j42xvt", "ftiyk5j"],
21
- "vkx7if": "f3za06g",
22
- "Bhdpb9s": ["ftiyk5j", "f1j42xvt"],
23
- "Bpou26a": "f1l3yytu",
24
- "Bxui8rh": "fnfm6nw",
25
- "v96tid": "f19m7vnf",
26
- "cyjxpb": "f8p7r4r",
27
- "Bn0no95": "f1iilt6f",
28
- "B573luj": ["f2keu4t", "f14fcfgr"],
29
- "B639bv6": "faptqjd",
30
- "shdfye": ["f14fcfgr", "f2keu4t"],
31
- "gekwd": "fhcdesm",
32
- "Du8lva": ["f17qorvy", "f1s68zmt"],
33
- "Bxo5kf0": "f1kaw87x",
34
- "G4c1lw": ["f1s68zmt", "f17qorvy"],
35
- "B7295ny": ["fcxw5no", "f1klxzyg"],
36
- "Bfl2641": ["f1klxzyg", "fcxw5no"],
37
- "Bc850wg": ["f8h35c5", "f41fp59"],
38
- "Bwbif6r": ["f41fp59", "f8h35c5"],
39
- "Bc7x9ep": "f89yr8c",
40
- "Btolfwl": ["f3vokhu", "fgoym2l"],
41
- "nuwgkz": "f1b662q1",
42
- "iduwum": ["fgoym2l", "f3vokhu"],
43
- "zp4aim": "fn1y60j",
44
- "Br8g1vq": "f197ac7e",
45
- "s8cxrh": ["f1yd45vn", "f1w8wcpf"],
46
- "dw1usy": ["f1w8wcpf", "f1yd45vn"]
19
+ "r6j8yp": "f9sgzds",
20
+ "w235jp": ["fut1j4r", "fkf1fqv"],
21
+ "Bjm0d8m": "f1t0sa4d",
22
+ "jwfw70": ["fkf1fqv", "fut1j4r"],
23
+ "Boz55fv": "f1m3tk81",
24
+ "pmqz9c": "f1pr2mxm",
25
+ "Bl9sb7i": "f29vp72",
26
+ "h4jxiv": "f1b5h9zn",
27
+ "E4x6tl": "f1ltau7e",
28
+ "B9c4r0f": ["f18ihh6m", "fzaptb5"],
29
+ "Bstwoin": "f1or3dzb",
30
+ "Bflkndj": ["fzaptb5", "f18ihh6m"],
31
+ "h1egvf": "fciubpk",
32
+ "vw8w2h": ["fzvtil0", "f1e7tdtt"],
33
+ "Bbpctgi": "f14oz5ke",
34
+ "Dyu7ee": ["f1e7tdtt", "fzvtil0"],
35
+ "gnkc5c": ["f1clxaxy", "f1pefego"],
36
+ "Bw9c0us": ["f1pefego", "f1clxaxy"],
37
+ "B9ptage": ["f1e14n0d", "f19um3kx"],
38
+ "c7u8z9": ["f19um3kx", "f1e14n0d"],
39
+ "Bgf7pbm": "f1a5bpr6",
40
+ "Btw8xqj": ["fjsutlp", "f1fz4ffz"],
41
+ "B6j1cfa": "f11bfvwp",
42
+ "B3wlxu": ["f1fz4ffz", "fjsutlp"],
43
+ "Beastro": "f1hebwof",
44
+ "Bhizb9d": "f19pyrw2",
45
+ "B2fkz8r": ["fjebp7m", "f1m6puf8"],
46
+ "B0gbj9w": ["f1m6puf8", "fjebp7m"]
47
47
  },
48
48
  "root": {
49
49
  "Bbmb7ep": ["f1aa9q02", "f16jpd5f"],
@@ -108,7 +108,7 @@ const useStyles = /*#__PURE__*/__styles({
108
108
  }, {
109
109
  "f": [".ftqa4ok:focus{outline-style:none;}", ".fc1cou1:focus{color:var(--colorNeutralForeground3Hover);}", ".ft33916:focus{color:var(--colorNeutralForegroundDisabled);}"],
110
110
  "i": [".f2hkw1w:focus-visible{outline-style:none;}"],
111
- "d": [".fui-FluentProvider .fvvvjju.fui-focus-visible{border-top-color:transparent;}", ".fui-FluentProvider .f1j42xvt.fui-focus-visible{border-right-color:transparent;}", ".fui-FluentProvider .ftiyk5j.fui-focus-visible{border-left-color:transparent;}", ".fui-FluentProvider .f3za06g.fui-focus-visible{border-bottom-color:transparent;}", ".fui-FluentProvider .f1l3yytu.fui-focus-visible::after{content:\"\";}", ".fui-FluentProvider .fnfm6nw.fui-focus-visible::after{position:absolute;}", ".fui-FluentProvider .f19m7vnf.fui-focus-visible::after{pointer-events:none;}", ".fui-FluentProvider .f8p7r4r.fui-focus-visible::after{z-index:1;}", ".fui-FluentProvider .f1iilt6f.fui-focus-visible::after{border-top-style:solid;}", ".fui-FluentProvider .f2keu4t.fui-focus-visible::after{border-right-style:solid;}", ".fui-FluentProvider .f14fcfgr.fui-focus-visible::after{border-left-style:solid;}", ".fui-FluentProvider .faptqjd.fui-focus-visible::after{border-bottom-style:solid;}", ".fui-FluentProvider .fhcdesm.fui-focus-visible::after{border-top-width:2px;}", ".fui-FluentProvider .f17qorvy.fui-focus-visible::after{border-right-width:2px;}", ".fui-FluentProvider .f1s68zmt.fui-focus-visible::after{border-left-width:2px;}", ".fui-FluentProvider .f1kaw87x.fui-focus-visible::after{border-bottom-width:2px;}", ".fui-FluentProvider .fcxw5no.fui-focus-visible::after{border-bottom-right-radius:var(--borderRadiusMedium);}", ".fui-FluentProvider .f1klxzyg.fui-focus-visible::after{border-bottom-left-radius:var(--borderRadiusMedium);}", ".fui-FluentProvider .f8h35c5.fui-focus-visible::after{border-top-right-radius:var(--borderRadiusMedium);}", ".fui-FluentProvider .f41fp59.fui-focus-visible::after{border-top-left-radius:var(--borderRadiusMedium);}", ".fui-FluentProvider .f89yr8c.fui-focus-visible::after{border-top-color:var(--colorStrokeFocus2);}", ".fui-FluentProvider .f3vokhu.fui-focus-visible::after{border-right-color:var(--colorStrokeFocus2);}", ".fui-FluentProvider .fgoym2l.fui-focus-visible::after{border-left-color:var(--colorStrokeFocus2);}", ".fui-FluentProvider .f1b662q1.fui-focus-visible::after{border-bottom-color:var(--colorStrokeFocus2);}", ".fui-FluentProvider .fn1y60j.fui-focus-visible::after{top:-2px;}", ".fui-FluentProvider .f197ac7e.fui-focus-visible::after{bottom:-2px;}", ".fui-FluentProvider .f1yd45vn.fui-focus-visible::after{left:-2px;}", ".fui-FluentProvider .f1w8wcpf.fui-focus-visible::after{right:-2px;}", ".f1aa9q02{border-bottom-right-radius:var(--borderRadiusMedium);}", ".f16jpd5f{border-bottom-left-radius:var(--borderRadiusMedium);}", ".f1jar5jt{border-top-right-radius:var(--borderRadiusMedium);}", ".fyu767a{border-top-left-radius:var(--borderRadiusMedium);}", ".f10pi13n{position:relative;}", ".fkfq4zb{color:var(--colorNeutralForeground2);}", ".fxugw4r{background-color:var(--colorNeutralBackground1);}", ".f81rol6{padding-right:10px;}", ".frdkuqy{padding-left:10px;}", ".f1d2rq10{height:32px;}", ".f22iagw{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}", ".f122n59{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;}", ".fkhj508{font-size:var(--fontSizeBase300);}", ".f1k6fduh{cursor:pointer;}", ".f1q8lukm{-webkit-column-gap:4px;column-gap:4px;}", ".f1ma2n7n{row-gap:4px;}", ".f1xqy1su{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;}", ".f161knb0{padding-left:2px;}", ".f12huiiw{padding-right:2px;}", ".f3rmtva{background-color:transparent;}", ".fqerorx{-webkit-box-flex:1;-webkit-flex-grow:1;-ms-flex-positive:1;flex-grow:1;}", ".f11d4kpn{color:var(--colorNeutralForeground3);}", ".f64fuq3{width:20px;}", ".fjamq6b{height:20px;}", ".fe5j1ua{font-size:20px;}", ".fez10in{line-height:0;}", ".ftuwxu6{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;}", ".f4d9j23{-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;}", ".f1s2aq7o{color:var(--colorNeutralForegroundDisabled);}"],
111
+ "d": [".f9sgzds.fui-focus-visible{border-top-color:transparent;}", ".fut1j4r.fui-focus-visible{border-right-color:transparent;}", ".fkf1fqv.fui-focus-visible{border-left-color:transparent;}", ".f1t0sa4d.fui-focus-visible{border-bottom-color:transparent;}", ".f1m3tk81.fui-focus-visible::after{content:\"\";}", ".f1pr2mxm.fui-focus-visible::after{position:absolute;}", ".f29vp72.fui-focus-visible::after{pointer-events:none;}", ".f1b5h9zn.fui-focus-visible::after{z-index:1;}", ".f1ltau7e.fui-focus-visible::after{border-top-style:solid;}", ".f18ihh6m.fui-focus-visible::after{border-right-style:solid;}", ".fzaptb5.fui-focus-visible::after{border-left-style:solid;}", ".f1or3dzb.fui-focus-visible::after{border-bottom-style:solid;}", ".fciubpk.fui-focus-visible::after{border-top-width:2px;}", ".fzvtil0.fui-focus-visible::after{border-right-width:2px;}", ".f1e7tdtt.fui-focus-visible::after{border-left-width:2px;}", ".f14oz5ke.fui-focus-visible::after{border-bottom-width:2px;}", ".f1clxaxy.fui-focus-visible::after{border-bottom-right-radius:var(--borderRadiusMedium);}", ".f1pefego.fui-focus-visible::after{border-bottom-left-radius:var(--borderRadiusMedium);}", ".f1e14n0d.fui-focus-visible::after{border-top-right-radius:var(--borderRadiusMedium);}", ".f19um3kx.fui-focus-visible::after{border-top-left-radius:var(--borderRadiusMedium);}", ".f1a5bpr6.fui-focus-visible::after{border-top-color:var(--colorStrokeFocus2);}", ".fjsutlp.fui-focus-visible::after{border-right-color:var(--colorStrokeFocus2);}", ".f1fz4ffz.fui-focus-visible::after{border-left-color:var(--colorStrokeFocus2);}", ".f11bfvwp.fui-focus-visible::after{border-bottom-color:var(--colorStrokeFocus2);}", ".f1hebwof.fui-focus-visible::after{top:-2px;}", ".f19pyrw2.fui-focus-visible::after{bottom:-2px;}", ".fjebp7m.fui-focus-visible::after{left:-2px;}", ".f1m6puf8.fui-focus-visible::after{right:-2px;}", ".f1aa9q02{border-bottom-right-radius:var(--borderRadiusMedium);}", ".f16jpd5f{border-bottom-left-radius:var(--borderRadiusMedium);}", ".f1jar5jt{border-top-right-radius:var(--borderRadiusMedium);}", ".fyu767a{border-top-left-radius:var(--borderRadiusMedium);}", ".f10pi13n{position:relative;}", ".fkfq4zb{color:var(--colorNeutralForeground2);}", ".fxugw4r{background-color:var(--colorNeutralBackground1);}", ".f81rol6{padding-right:10px;}", ".frdkuqy{padding-left:10px;}", ".f1d2rq10{height:32px;}", ".f22iagw{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}", ".f122n59{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;}", ".fkhj508{font-size:var(--fontSizeBase300);}", ".f1k6fduh{cursor:pointer;}", ".f1q8lukm{-webkit-column-gap:4px;column-gap:4px;}", ".f1ma2n7n{row-gap:4px;}", ".f1xqy1su{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;}", ".f161knb0{padding-left:2px;}", ".f12huiiw{padding-right:2px;}", ".f3rmtva{background-color:transparent;}", ".fqerorx{-webkit-box-flex:1;-webkit-flex-grow:1;-ms-flex-positive:1;flex-grow:1;}", ".f11d4kpn{color:var(--colorNeutralForeground3);}", ".f64fuq3{width:20px;}", ".fjamq6b{height:20px;}", ".fe5j1ua{font-size:20px;}", ".fez10in{line-height:0;}", ".ftuwxu6{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;}", ".f4d9j23{-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;}", ".f1s2aq7o{color:var(--colorNeutralForegroundDisabled);}"],
112
112
  "h": [".f1knas48:hover{background-color:var(--colorNeutralBackground1Hover);}", ".fnwyq0v:hover{color:var(--colorNeutralForeground2Hover);}", ".ft1hn21:hover .fui-Icon-filled{display:inline;}", ".fuxngvv:hover .fui-Icon-regular{display:none;}", ".fp258yr:hover .fui-MenuItem__icon{color:var(--colorNeutralForeground2BrandSelected);}", ".f1jp5ecu:hover{color:var(--colorNeutralForeground3Hover);}", ".fvgxktp:hover{color:var(--colorNeutralForegroundDisabled);}"]
113
113
  });
114
114
  /** Applies style classnames to slots */
@@ -20,6 +20,7 @@ export const useMenuPopover_unstable = (props, ref) => {
20
20
 
21
21
  const popoverRef = useMenuContext_unstable(context => context.menuPopoverRef);
22
22
  const setOpen = useMenuContext_unstable(context => context.setOpen);
23
+ const open = useMenuContext_unstable(context => context.open);
23
24
  const openOnHover = useMenuContext_unstable(context => context.openOnHover);
24
25
  const isSubmenu = useIsSubmenu();
25
26
  const canDispatchCustomEventRef = React.useRef(true);
@@ -75,11 +76,14 @@ export const useMenuPopover_unstable = (props, ref) => {
75
76
  const key = e.key;
76
77
 
77
78
  if (key === Escape || isSubmenu && key === CloseArrowKey) {
78
- if ((_a = popoverRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target)) {
79
+ if (open && ((_a = popoverRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
79
80
  setOpen(e, {
80
81
  open: false,
81
82
  keyboard: true
82
- });
83
+ }); // stop propagation to avoid conflicting with other elements that listen for `Escape`
84
+ // e,g: Dialog, Popover and Tooltip
85
+
86
+ e.stopPropagation();
83
87
  }
84
88
  }
85
89
 
@@ -1 +1 @@
1
- {"version":3,"sources":["components/MenuPopover/useMenuPop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,SAAS,IAAI,GAAG,KAAK,aAA5C,EAA4D;MAC1D,IAAI,CAAA,EAAA,GAAA,UAAU,CAAC,OAAX,MAAkB,IAAlB,IAAkB,EAAA,KAAA,KAAA,CAAlB,GAAkB,KAAA,CAAlB,GAAkB,EAAA,CAAE,QAAF,CAAW,CAAC,CAAC,MAAb,CAAtB,EAA2D;QACzD,OAAO,CAAC,CAAD,EAAI;UAAE,IAAI,EAAE,KAAR;UAAe,QAAQ,EAAE;QAAzB,CAAJ,CAAP;MACD;IACF;;IAED,IAAI,GAAG,KAAK,GAAZ,EAAiB;MACf,OAAO,CAAC,CAAD,EAAI;QAAE,IAAI,EAAE,KAAR;QAAe,QAAQ,EAAE;MAAzB,CAAJ,CAAP;MACA,CAAC,CAAC,cAAF;IACD;;IAED,iBAAiB,KAAA,IAAjB,IAAA,iBAAiB,KAAA,KAAA,CAAjB,GAAiB,KAAA,CAAjB,GAAA,iBAAiB,CAAG,CAAH,CAAjB;EACD,CAfqC,CAAtC;EAiBA,OAAO;IACL,MADK;IAEL,UAAU,EAAE;MACV,IAAI,EAAE;IADI,CAFP;IAKL,IAAI,EAAE;EALD,CAAP;AAOD,CA9EM","sourcesContent":["import * as React from 'react';\nimport { ArrowLeft, Tab, ArrowRight, Escape } from '@fluentui/keyboard-keys';\nimport { getNativeElementProps, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport { MenuPopoverProps, MenuPopoverState } from './MenuPopover.types';\nimport { useMenuContext_unstable } from '../../contexts/menuContext';\nimport { dispatchMenuEnterEvent } from '../../utils/index';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { useIsSubmenu } from '../../utils/useIsSubmenu';\n\n/**\n * Create the state required to render MenuPopover.\n *\n * The returned state can be modified with hooks such as useMenuPopoverStyles_unstable,\n * before being passed to renderMenuPopover_unstable.\n *\n * @param props - props from this instance of MenuPopover\n * @param ref - reference to root HTMLElement of MenuPopover\n */\nexport const useMenuPopover_unstable = (props: MenuPopoverProps, ref: React.Ref<HTMLElement>): MenuPopoverState => {\n const popoverRef = useMenuContext_unstable(context => context.menuPopoverRef);\n const setOpen = useMenuContext_unstable(context => context.setOpen);\n const openOnHover = useMenuContext_unstable(context => context.openOnHover);\n const isSubmenu = useIsSubmenu();\n const canDispatchCustomEventRef = React.useRef(true);\n const throttleDispatchTimerRef = React.useRef(0);\n\n const { dir } = useFluent();\n const CloseArrowKey = dir === 'ltr' ? ArrowLeft : ArrowRight;\n\n // use DOM listener since react events propagate up the react tree\n // no need to do `contains` logic as menus are all positioned in different portals\n const mouseOverListenerCallbackRef = React.useCallback(\n (node: HTMLElement) => {\n if (node) {\n // Dispatches the custom menu mouse enter event with throttling\n // Needs to trigger on mouseover to support keyboard + mouse together\n // i.e. keyboard opens submenus while cursor is still on the parent\n node.addEventListener('mouseover', e => {\n if (canDispatchCustomEventRef.current) {\n canDispatchCustomEventRef.current = false;\n dispatchMenuEnterEvent(popoverRef.current as HTMLElement, e);\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore #16889 Node setTimeout type leaking\n throttleDispatchTimerRef.current = setTimeout(() => (canDispatchCustomEventRef.current = true), 250);\n }\n });\n }\n },\n [popoverRef, throttleDispatchTimerRef],\n );\n\n React.useEffect(() => {\n () => clearTimeout(throttleDispatchTimerRef.current);\n }, []);\n\n const inline = useMenuContext_unstable(context => context.inline) ?? false;\n const rootProps = getNativeElementProps('div', {\n role: 'presentation',\n ...props,\n ref: useMergedRefs(ref, popoverRef, mouseOverListenerCallbackRef),\n });\n\n const { onMouseEnter: onMouseEnterOriginal, onKeyDown: onKeyDownOriginal } = rootProps;\n\n rootProps.onMouseEnter = useEventCallback((e: React.MouseEvent<HTMLElement>) => {\n if (openOnHover) {\n setOpen(e, { open: true, keyboard: false });\n }\n\n onMouseEnterOriginal?.(e);\n });\n\n rootProps.onKeyDown = useEventCallback((e: React.KeyboardEvent<HTMLElement>) => {\n const key = e.key;\n\n if (key === Escape || (isSubmenu && key === CloseArrowKey)) {\n if (popoverRef.current?.contains(e.target as HTMLElement)) {\n setOpen(e, { open: false, keyboard: true });\n }\n }\n\n if (key === Tab) {\n setOpen(e, { open: false, keyboard: true });\n e.preventDefault();\n }\n\n onKeyDownOriginal?.(e);\n });\n\n return {\n inline,\n components: {\n root: 'div',\n },\n root: rootProps,\n };\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["components/MenuPopover/useMenuPopover.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,SAAT,EAAoB,GAApB,EAAyB,UAAzB,EAAqC,MAArC,QAAmD,yBAAnD;AACA,SAAS,qBAAT,EAAgC,gBAAhC,EAAkD,aAAlD,QAAuE,2BAAvE;AAEA,SAAS,uBAAT,QAAwC,4BAAxC;AACA,SAAS,sBAAT,QAAuC,mBAAvC;AACA,SAAS,kBAAkB,IAAI,SAA/B,QAAgD,iCAAhD;AACA,SAAS,YAAT,QAA6B,0BAA7B;AAEA;;;;;;;;AAQG;;AACH,OAAO,MAAM,uBAAuB,GAAG,CAAC,KAAD,EAA0B,GAA1B,KAA2E;;;EAChH,MAAM,UAAU,GAAG,uBAAuB,CAAC,OAAO,IAAI,OAAO,CAAC,cAApB,CAA1C;EACA,MAAM,OAAO,GAAG,uBAAuB,CAAC,OAAO,IAAI,OAAO,CAAC,OAApB,CAAvC;EACA,MAAM,IAAI,GAAG,uBAAuB,CAAC,OAAO,IAAI,OAAO,CAAC,IAApB,CAApC;EACA,MAAM,WAAW,GAAG,uBAAuB,CAAC,OAAO,IAAI,OAAO,CAAC,WAApB,CAA3C;EACA,MAAM,SAAS,GAAG,YAAY,EAA9B;EACA,MAAM,yBAAyB,GAAG,KAAK,CAAC,MAAN,CAAa,IAAb,CAAlC;EACA,MAAM,wBAAwB,GAAG,KAAK,CAAC,MAAN,CAAa,CAAb,CAAjC;EAEA,MAAM;IAAE;EAAF,IAAU,SAAS,EAAzB;EACA,MAAM,aAAa,GAAG,GA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AI;QAAE,IAAI,EAAE,IAAR;QAAc,QAAQ,EAAE;MAAxB,CAAJ,CAAP;IACD;;IAED,oBAAoB,KAAA,IAApB,IAAA,oBAAoB,KAAA,KAAA,CAApB,GAAoB,KAAA,CAApB,GAAA,oBAAoB,CAAG,CAAH,CAApB;EACD,CANwC,CAAzC;EAQA,SAAS,CAAC,SAAV,GAAsB,gBAAgB,CAAE,CAAD,IAAwC;;;IAC7E,MAAM,GAAG,GAAG,CAAC,CAAC,GAAd;;IAEA,IAAI,GAAG,KAAK,MAAR,IAAmB,SAAS,IAAI,GAAG,KAAK,aAA5C,EAA4D;MAC1D,IAAI,IAAI,KAAI,CAAA,EAAA,GAAA,UAAU,CAAC,OAAX,MAAkB,IAAlB,IAAkB,EAAA,KAAA,KAAA,CAAlB,GAAkB,KAAA,CAAlB,GAAkB,EAAA,CAAE,QAAF,CAAW,CAAC,CAAC,MAAb,CAAtB,CAAR,EAAmE;QACjE,OAAO,CAAC,CAAD,EAAI;UAAE,IAAI,EAAE,KAAR;UAAe,QAAQ,EAAE;QAAzB,CAAJ,CAAP,CADiE,CAEjE;QACA;;QACA,CAAC,CAAC,eAAF;MACD;IACF;;IAED,IAAI,GAAG,KAAK,GAAZ,EAAiB;MACf,OAAO,CAAC,CAAD,EAAI;QAAE,IAAI,EAAE,KAAR;QAAe,QAAQ,EAAE;MAAzB,CAAJ,CAAP;MACA,CAAC,CAAC,cAAF;IACD;;IAED,iBAAiB,KAAA,IAAjB,IAAA,iBAAiB,KAAA,KAAA,CAAjB,GAAiB,KAAA,CAAjB,GAAA,iBAAiB,CAAG,CAAH,CAAjB;EACD,CAlBqC,CAAtC;EAoBA,OAAO;IACL,MADK;IAEL,UAAU,EAAE;MACV,IAAI,EAAE;IADI,CAFP;IAKL,IAAI,EAAE;EALD,CAAP;AAOD,CAlFM","sourcesContent":["import * as React from 'react';\nimport { ArrowLeft, Tab, ArrowRight, Escape } from '@fluentui/keyboard-keys';\nimport { getNativeElementProps, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport { MenuPopoverProps, MenuPopoverState } from './MenuPopover.types';\nimport { useMenuContext_unstable } from '../../contexts/menuContext';\nimport { dispatchMenuEnterEvent } from '../../utils/index';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { useIsSubmenu } from '../../utils/useIsSubmenu';\n\n/**\n * Create the state required to render MenuPopover.\n *\n * The returned state can be modified with hooks such as useMenuPopoverStyles_unstable,\n * before being passed to renderMenuPopover_unstable.\n *\n * @param props - props from this instance of MenuPopover\n * @param ref - reference to root HTMLElement of MenuPopover\n */\nexport const useMenuPopover_unstable = (props: MenuPopoverProps, ref: React.Ref<HTMLElement>): MenuPopoverState => {\n const popoverRef = useMenuContext_unstable(context => context.menuPopoverRef);\n const setOpen = useMenuContext_unstable(context => context.setOpen);\n const open = useMenuContext_unstable(context => context.open);\n const openOnHover = useMenuContext_unstable(context => context.openOnHover);\n const isSubmenu = useIsSubmenu();\n const canDispatchCustomEventRef = React.useRef(true);\n const throttleDispatchTimerRef = React.useRef(0);\n\n const { dir } = useFluent();\n const CloseArrowKey = dir === 'ltr' ? ArrowLeft : ArrowRight;\n\n // use DOM listener since react events propagate up the react tree\n // no need to do `contains` logic as menus are all positioned in different portals\n const mouseOverListenerCallbackRef = React.useCallback(\n (node: HTMLElement) => {\n if (node) {\n // Dispatches the custom menu mouse enter event with throttling\n // Needs to trigger on mouseover to support keyboard + mouse together\n // i.e. keyboard opens submenus while cursor is still on the parent\n node.addEventListener('mouseover', e => {\n if (canDispatchCustomEventRef.current) {\n canDispatchCustomEventRef.current = false;\n dispatchMenuEnterEvent(popoverRef.current as HTMLElement, e);\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore #16889 Node setTimeout type leaking\n throttleDispatchTimerRef.current = setTimeout(() => (canDispatchCustomEventRef.current = true), 250);\n }\n });\n }\n },\n [popoverRef, throttleDispatchTimerRef],\n );\n\n React.useEffect(() => {\n () => clearTimeout(throttleDispatchTimerRef.current);\n }, []);\n\n const inline = useMenuContext_unstable(context => context.inline) ?? false;\n const rootProps = getNativeElementProps('div', {\n role: 'presentation',\n ...props,\n ref: useMergedRefs(ref, popoverRef, mouseOverListenerCallbackRef),\n });\n\n const { onMouseEnter: onMouseEnterOriginal, onKeyDown: onKeyDownOriginal } = rootProps;\n\n rootProps.onMouseEnter = useEventCallback((e: React.MouseEvent<HTMLElement>) => {\n if (openOnHover) {\n setOpen(e, { open: true, keyboard: false });\n }\n\n onMouseEnterOriginal?.(e);\n });\n\n rootProps.onKeyDown = useEventCallback((e: React.KeyboardEvent<HTMLElement>) => {\n const key = e.key;\n\n if (key === Escape || (isSubmenu && key === CloseArrowKey)) {\n if (open && popoverRef.current?.contains(e.target as HTMLElement)) {\n setOpen(e, { open: false, keyboard: true });\n // stop propagation to avoid conflicting with other elements that listen for `Escape`\n // e,g: Dialog, Popover and Tooltip\n e.stopPropagation();\n }\n }\n\n if (key === Tab) {\n setOpen(e, { open: false, keyboard: true });\n e.preventDefault();\n }\n\n onKeyDownOriginal?.(e);\n });\n\n return {\n inline,\n components: {\n root: 'div',\n },\n root: rootProps,\n };\n};\n"],"sourceRoot":"../src/"}