@fluentui/react-menu 9.1.0 → 9.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. package/CHANGELOG.json +37 -1
  2. package/CHANGELOG.md +21 -2
  3. package/dist/index.d.ts +11 -19
  4. package/lib/components/Menu/Menu.types.js.map +1 -1
  5. package/lib/components/Menu/useMenu.js +7 -8
  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 +22 -2
  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/selectable/types.js.map +1 -1
  21. package/lib-commonjs/components/Menu/useMenu.js +8 -8
  22. package/lib-commonjs/components/Menu/useMenu.js.map +1 -1
  23. package/lib-commonjs/components/MenuItem/useCharacterSearch.js +2 -4
  24. package/lib-commonjs/components/MenuItem/useCharacterSearch.js.map +1 -1
  25. package/lib-commonjs/components/MenuItem/useMenuItem.js +59 -71
  26. package/lib-commonjs/components/MenuItem/useMenuItem.js.map +1 -1
  27. package/lib-commonjs/components/MenuItem/useMenuItemStyles.js +22 -2
  28. package/lib-commonjs/components/MenuItem/useMenuItemStyles.js.map +1 -1
  29. package/lib-commonjs/components/MenuItemCheckbox/useMenuItemCheckbox.js +26 -28
  30. package/lib-commonjs/components/MenuItemCheckbox/useMenuItemCheckbox.js.map +1 -1
  31. package/lib-commonjs/components/MenuItemCheckbox/useMenuItemCheckboxStyles.js.map +1 -1
  32. package/lib-commonjs/components/MenuItemRadio/useMenuItemRadio.js +25 -31
  33. package/lib-commonjs/components/MenuItemRadio/useMenuItemRadio.js.map +1 -1
  34. package/lib-commonjs/components/MenuItemRadio/useMenuItemRadioStyles.js.map +1 -1
  35. package/package.json +2 -2
package/CHANGELOG.json CHANGED
@@ -2,7 +2,43 @@
2
2
  "name": "@fluentui/react-menu",
3
3
  "entries": [
4
4
  {
5
- "date": "Thu, 15 Sep 2022 09:44:29 GMT",
5
+ "date": "Fri, 23 Sep 2022 10:32:08 GMT",
6
+ "tag": "@fluentui/react-menu_v9.2.1",
7
+ "version": "9.2.1",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "behowell@microsoft.com",
12
+ "package": "@fluentui/react-menu",
13
+ "commit": "f6202c4bb7ca9f352e7b4bc376242849648dcfd6",
14
+ "comment": "fix: Make Menu openOnHover prop work again"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Tue, 20 Sep 2022 20:55:45 GMT",
21
+ "tag": "@fluentui/react-menu_v9.2.0",
22
+ "version": "9.2.0",
23
+ "comments": {
24
+ "minor": [
25
+ {
26
+ "author": "bernardo.sunderhus@gmail.com",
27
+ "package": "@fluentui/react-menu",
28
+ "commit": "e8f84e8262c165e5809b4ffc18381e6398b12c4f",
29
+ "comment": "feat: replace keydown handlers by useARIAButtonShorthand on MenuItem"
30
+ },
31
+ {
32
+ "author": "beachball",
33
+ "package": "@fluentui/react-menu",
34
+ "comment": "Bump @fluentui/react-conformance-griffel to v9.0.0-beta.14",
35
+ "commit": "4ceba844c804a2f49b0465389100e7a3dabf116e"
36
+ }
37
+ ]
38
+ }
39
+ },
40
+ {
41
+ "date": "Thu, 15 Sep 2022 09:49:08 GMT",
6
42
  "tag": "@fluentui/react-menu_v9.1.0",
7
43
  "version": "9.1.0",
8
44
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,31 @@
1
1
  # Change Log - @fluentui/react-menu
2
2
 
3
- This log was last generated on Thu, 15 Sep 2022 09:44:29 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 23 Sep 2022 10:32:08 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.2.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-menu_v9.2.1)
8
+
9
+ Fri, 23 Sep 2022 10:32:08 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-menu_v9.2.0..@fluentui/react-menu_v9.2.1)
11
+
12
+ ### Patches
13
+
14
+ - fix: Make Menu openOnHover prop work again ([PR #24899](https://github.com/microsoft/fluentui/pull/24899) by behowell@microsoft.com)
15
+
16
+ ## [9.2.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-menu_v9.2.0)
17
+
18
+ Tue, 20 Sep 2022 20:55:45 GMT
19
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-menu_v9.1.0..@fluentui/react-menu_v9.2.0)
20
+
21
+ ### Minor changes
22
+
23
+ - feat: replace keydown handlers by useARIAButtonShorthand on MenuItem ([PR #24738](https://github.com/microsoft/fluentui/pull/24738) by bernardo.sunderhus@gmail.com)
24
+ - Bump @fluentui/react-conformance-griffel to v9.0.0-beta.14 ([PR #24869](https://github.com/microsoft/fluentui/pull/24869) by beachball)
25
+
7
26
  ## [9.1.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-menu_v9.1.0)
8
27
 
9
- Thu, 15 Sep 2022 09:44:29 GMT
28
+ Thu, 15 Sep 2022 09:49:08 GMT
10
29
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-menu_v9.0.4..@fluentui/react-menu_v9.1.0)
11
30
 
12
31
  ### Minor changes
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  /// <reference types="react" />
2
2
 
3
+ import type { ARIAButtonElement } from '@fluentui/react-aria';
3
4
  import { ARIAButtonResultProps } from '@fluentui/react-aria';
5
+ import type { ARIAButtonSlotProps } from '@fluentui/react-aria';
4
6
  import { ARIAButtonType } from '@fluentui/react-aria';
5
7
  import type { ComponentProps } from '@fluentui/react-utilities';
6
8
  import type { ComponentState } from '@fluentui/react-utilities';
@@ -127,12 +129,6 @@ export declare type MenuItemCheckboxState = MenuItemState & MenuItemSelectableSt
127
129
  export declare const menuItemClassNames: SlotClassNames<MenuItemSlots>;
128
130
 
129
131
  export declare type MenuItemProps = ComponentProps<Partial<MenuItemSlots>> & {
130
- /**
131
- * Applies disabled styles to menu item but remains focusable
132
- *
133
- * @default false
134
- */
135
- disabled?: boolean;
136
132
  /**
137
133
  * If the menu item is a trigger for a submenu
138
134
  *
@@ -178,14 +174,6 @@ export declare type MenuItemSelectableProps = {
178
174
  * State for selectable menu items
179
175
  */
180
176
  export declare type MenuItemSelectableState = MenuItemSelectableProps & {
181
- /**
182
- * Checked items for a value with `name`
183
- */
184
- checkedItems: string[];
185
- /**
186
- * Callback when checked items changes for a given value with `name`
187
- */
188
- onCheckedValueChange: (e: React_2.MouseEvent | React_2.KeyboardEvent, name: string, checkedItems: string[]) => void;
189
177
  /**
190
178
  * Selectable is checked
191
179
  */
@@ -193,7 +181,7 @@ export declare type MenuItemSelectableState = MenuItemSelectableProps & {
193
181
  };
194
182
 
195
183
  export declare type MenuItemSlots = {
196
- root: Slot<'div'>;
184
+ root: Slot<ARIAButtonSlotProps<'div'>>;
197
185
  /**
198
186
  * Icon slot rendered before children content
199
187
  */
@@ -218,7 +206,9 @@ export declare type MenuItemSlots = {
218
206
  secondaryContent?: Slot<'span'>;
219
207
  };
220
208
 
221
- 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
+ };
222
212
 
223
213
  /**
224
214
  * Define a styled MenuList, using the `useMenuList_unstable` hook.
@@ -294,6 +284,8 @@ export declare type MenuOpenChangeData = {
294
284
  bubble?: boolean;
295
285
  /**
296
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
297
289
  */
298
290
  keyboard?: boolean;
299
291
  open: boolean;
@@ -608,17 +600,17 @@ export declare const useMenuGroupStyles_unstable: (state: MenuGroupState) => Men
608
600
  /**
609
601
  * Returns the props and state required to render the component
610
602
  */
611
- 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;
612
604
 
613
605
  /** Returns the props and state required to render the component */
614
- 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;
615
607
 
616
608
  export declare const useMenuItemCheckboxStyles_unstable: (state: MenuItemCheckboxState) => void;
617
609
 
618
610
  /**
619
611
  * Given user props, returns state and render function for a MenuItemRadio.
620
612
  */
621
- 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;
622
614
 
623
615
  export declare const useMenuItemRadioStyles_unstable: (state: MenuItemRadioState) => void;
624
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<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"]}
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,6 +18,7 @@ import { useIsSubmenu } from '../../utils/useIsSubmenu';
17
18
  */
18
19
 
19
20
  export const useMenu_unstable = props => {
21
+ const isSubmenu = useIsSubmenu();
20
22
  const {
21
23
  hoverDelay = 500,
22
24
  inline = false,
@@ -25,10 +27,10 @@ export const useMenu_unstable = props => {
25
27
  closeOnScroll = false,
26
28
  openOnContext = false,
27
29
  persistOnItemClick = false,
30
+ openOnHover = isSubmenu,
28
31
  defaultCheckedValues
29
32
  } = props;
30
33
  const triggerId = useId('menu');
31
- const isSubmenu = useIsSubmenu();
32
34
  const [contextTarget, setContextTarget] = usePositioningMouseTarget();
33
35
  const positioningState = {
34
36
  position: isSubmenu ? 'after' : 'below',
@@ -87,7 +89,7 @@ export const useMenu_unstable = props => {
87
89
  hoverDelay,
88
90
  triggerId,
89
91
  isSubmenu,
90
- openOnHover: isSubmenu,
92
+ openOnHover,
91
93
  contextTarget,
92
94
  setContextTarget,
93
95
  hasCheckmarks,
@@ -153,7 +155,6 @@ const useMenuOpenState = state => {
153
155
 
154
156
  return (_a = state.onOpenChange) === null || _a === void 0 ? void 0 : _a.call(state, e, data);
155
157
  });
156
- const shouldHandleKeyboardRef = React.useRef(false);
157
158
  const shouldHandleTabRef = React.useRef(false);
158
159
  const pressedShiftRef = React.useRef(false);
159
160
  const setOpenTimeout = React.useRef(0);
@@ -176,9 +177,8 @@ const useMenuOpenState = state => {
176
177
  state.setContextTarget(undefined);
177
178
  }
178
179
 
179
- if (data.keyboard) {
180
- shouldHandleKeyboardRef.current = true;
181
- shouldHandleTabRef.current = e.key === 'Tab';
180
+ if (e.type === 'keydown' && e.key === Tab) {
181
+ shouldHandleTabRef.current = true;
182
182
  pressedShiftRef.current = e.shiftKey;
183
183
  }
184
184
 
@@ -283,7 +283,7 @@ const useMenuOpenState = state => {
283
283
  focusFirst();
284
284
  }
285
285
 
286
- if (shouldHandleKeyboardRef.current && !open) {
286
+ if (!open) {
287
287
  if (shouldHandleTabRef.current && !state.isSubmenu) {
288
288
  pressedShiftRef.current ? focusBeforeMenuTrigger() : focusAfterMenuTrigger();
289
289
  } else {
@@ -291,7 +291,6 @@ const useMenuOpenState = state => {
291
291
  }
292
292
  }
293
293
 
294
- shouldHandleKeyboardRef.current = false;
295
294
  shouldHandleTabRef.current = false;
296
295
  pressedShiftRef.current = false;
297
296
  }, [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,mBAAtD;AACA,SAAS,YAAT,QAA6B,0BAA7B;AAGA;;;;;;;AAOG;;AACH,OAAO,MAAM,gBAAgB,GAAI,KAAD,IAAgC;EAC9D,MAAM;IACJ,UAAU,GAAG,GADT;IAEJ,MAAM,GAAG,KAFL;IAGJ,aAAa,GAAG,KAHZ;IAIJ,QAAQ,GAAG,KAJP;IAKJ,aAAa,GAAG,KALZ;IAMJ,aAAa,GAAG,KANZ;IAOJ,kBAAkB,GAAG,KAPjB;IAQJ;EARI,IASF,KATJ;EAUA,MAAM,SAAS,GAAG,KAAK,CAAC,MAAD,CAAvB;EACA,MAAM,SAAS,GAAG,YAAY,EAA9B;EACA,MAAM,CAAC,aAAD,EAAgB,gBAAhB,IAAoC,yBAAyB,EAAnE;EAE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, 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/"}
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;AAEA,SAAS,GAAT,QAAoB,yBAApB;AAEA;;;;;;;AAOG;;AACH,OAAO,MAAM,gBAAgB,GAAI,KAAD,IAAgC;EAC9D,MAAM,SAAS,GAAG,YAAY,EAA9B;EACA,MAAM;IACJ,UAAU,GAAG,GADT;IAEJ,MAAM,GAAG,KAFL;IAGJ,aAAa,GAAG,KAHZ;IAIJ,QAAQ,GAAG,KAJP;IAKJ,aAAa,GAAG,KALZ;IAMJ,aAAa,GAAG,KANZ;IAOJ,kBAAkB,GAAG,KAPjB;IAQJ,WAAW,GAAG,SARV;IASJ;EATI,IAUF,KAVJ;EAWA,MAAM,SAAS,GAAG,KAAK,CAAC,MAAD,CAAvB;EACA,MAAM,CAAC,aAAD,EAAgB,gBAAhB,IAAoC,yBAAyB,EAAnE;EAEA,MAAM,gBAAgB,GAAG;IACvB,QAAQ,EAAE,SAAS,GAAI,OAAJ,G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B,EAG5B,CAAC,iBAAD,EAAoB,KAAK,CAAC,UAA1B,CAH4B,CAA/B;EAKA,KAAK,CAAC,SAAN,CAAgB,MAAK;IACnB,IAAI,IAAJ,EAAU;MACR,UAAU;IACX;EACF,CAJD,EAIG,CAAC,IAAD,EAAO,UAAP,CAJH;EAMA,KAAK,CAAC,SAAN,CAAgB,MAAK;;;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 isSubmenu = useIsSubmenu();\n const {\n hoverDelay = 500,\n inline = false,\n hasCheckmarks = false,\n hasIcons = false,\n closeOnScroll = false,\n openOnContext = false,\n persistOnItemClick = false,\n openOnHover = isSubmenu,\n defaultCheckedValues,\n } = props;\n const triggerId = useId('menu');\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,\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"]}
@@ -2,15 +2,13 @@ import { useMenuListContext_unstable } from '../../contexts/menuListContext';
2
2
  export const useCharacterSearch = (state, ref) => {
3
3
  const setFocusByFirstCharacter = useMenuListContext_unstable(context => context.setFocusByFirstCharacter);
4
4
  const {
5
- onKeyDown: onKeyDownBase
5
+ onKeyDown: originalOnKeyDown
6
6
  } = state.root;
7
7
 
8
8
  state.root.onKeyDown = e => {
9
9
  var _a;
10
10
 
11
- if (onKeyDownBase) {
12
- onKeyDownBase(e);
13
- }
11
+ originalOnKeyDown === null || originalOnKeyDown === void 0 ? void 0 : originalOnKeyDown(e);
14
12
 
15
13
  if (((_a = e.key) === null || _a === void 0 ? void 0 : _a.length) > 1) {
16
14
  return;
@@ -1 +1 @@
1
- {"version":3,"sources":["components/MenuItem/useCharacterSearch.ts"],"names":[],"mappings":"AACA,SAAS,2BAAT,QAA4C,gCAA5C;AAGA,OAAO,MAAM,kBAAkB,GAAG,CAAC,KAAD,EAAuB,GAAvB,KAA4D;EAC5F,MAAM,wBAAwB,GAAG,2BAA2B,CAAC,OAAO,IAAI,OAAO,CAAC,wBAApB,CAA5D;EAEA,MAAM;IAAE,SAAS,EAAE;EAAb,IAA+B,KAAK,CAAC,IAA3C;;EACA,KAAK,CAAC,IAAN,CAAW,SAAX,GAAuB,CAAC,IAAG;;;IACzB,IAAI,aAAJ,EAAmB;MACjB,aAAa,CAAC,CAAD,CAAb;IACD;;IAED,IAAI,CAAA,CAAA,EAAA,GAAA,CAAC,CAAC,GAAF,MAAK,IAAL,IAAK,EAAA,KAAA,KAAA,CAAL,GAAK,KAAA,CAAL,GAAK,EAAA,CAAE,MAAP,IAAgB,CAApB,EAAuB;MACrB;IACD;;IAED,IAAI,GAAG,CAAC,OAAR,EAAiB;MACf,wBAAwB,KAAA,IAAxB,IAAA,wBAAwB,KAAA,KAAA,CAAxB,GAAwB,KAAA,CAAxB,GAAA,wBAAwB,CAAG,CAAH,EAAM,GAAG,CAAC,OAAV,CAAxB;IACD;EACF,CAZD;;EAcA,OAAO,KAAP;AACD,CAnBM","sourcesContent":["import * as React from 'react';\nimport { useMenuListContext_unstable } from '../../contexts/menuListContext';\nimport type { MenuItemState } from '../../components/index';\n\nexport const useCharacterSearch = (state: MenuItemState, ref: React.RefObject<HTMLElement>) => {\n const setFocusByFirstCharacter = useMenuListContext_unstable(context => context.setFocusByFirstCharacter);\n\n const { onKeyDown: onKeyDownBase } = state.root;\n state.root.onKeyDown = e => {\n if (onKeyDownBase) {\n onKeyDownBase(e);\n }\n\n if (e.key?.length > 1) {\n return;\n }\n\n if (ref.current) {\n setFocusByFirstCharacter?.(e, ref.current);\n }\n };\n\n return state;\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["components/MenuItem/useCharacterSearch.ts"],"names":[],"mappings":"AACA,SAAS,2BAAT,QAA4C,gCAA5C;AAIA,OAAO,MAAM,kBAAkB,GAAG,CAAC,KAAD,EAAuB,GAAvB,KAA4D;EAC5F,MAAM,wBAAwB,GAAG,2BAA2B,CAAC,OAAO,IAAI,OAAO,CAAC,wBAApB,CAA5D;EAEA,MAAM;IAAE,SAAS,EAAE;EAAb,IAAmC,KAAK,CAAC,IAA/C;;EAEA,KAAK,CAAC,IAAN,CAAW,SAAX,GAAwB,CAAD,IAA0D;;;IAC/E,iBAAiB,KAAA,IAAjB,IAAA,iBAAiB,KAAA,KAAA,CAAjB,GAAiB,KAAA,CAAjB,GAAA,iBAAiB,CAAG,CAAH,CAAjB;;IAEA,IAAI,CAAA,CAAA,EAAA,GAAA,CAAC,CAAC,GAAF,MAAK,IAAL,IAAK,EAAA,KAAA,KAAA,CAAL,GAAK,KAAA,CAAL,GAAK,EAAA,CAAE,MAAP,IAAgB,CAApB,EAAuB;MACrB;IACD;;IAED,IAAI,GAAG,CAAC,OAAR,EAAiB;MACf,wBAAwB,KAAA,IAAxB,IAAA,wBAAwB,KAAA,KAAA,CAAxB,GAAwB,KAAA,CAAxB,GAAA,wBAAwB,CAAG,CAAH,EAAM,GAAG,CAAC,OAAV,CAAxB;IACD;EACF,CAVD;;EAYA,OAAO,KAAP;AACD,CAlBM","sourcesContent":["import * as React from 'react';\nimport { useMenuListContext_unstable } from '../../contexts/menuListContext';\nimport type { MenuItemState } from '../../components/index';\nimport type { ARIAButtonElementIntersection } from '@fluentui/react-aria';\n\nexport const useCharacterSearch = (state: MenuItemState, ref: React.RefObject<HTMLElement>) => {\n const setFocusByFirstCharacter = useMenuListContext_unstable(context => context.setFocusByFirstCharacter);\n\n const { onKeyDown: originalOnKeyDown } = state.root;\n\n state.root.onKeyDown = (e: React.KeyboardEvent<ARIAButtonElementIntersection>) => {\n originalOnKeyDown?.(e);\n\n if (e.key?.length > 1) {\n return;\n }\n\n if (ref.current) {\n setFocusByFirstCharacter?.(e, ref.current);\n }\n };\n\n return state;\n};\n"],"sourceRoot":"../src/"}
@@ -1,11 +1,13 @@
1
1
  import * as React from 'react';
2
- import { useEventCallback, shouldPreventDefaultOnKeyDown, resolveShorthand, useMergedRefs, getNativeElementProps } from '@fluentui/react-utilities';
2
+ import { useEventCallback, resolveShorthand, useMergedRefs, getNativeElementProps } from '@fluentui/react-utilities';
3
3
  import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
4
4
  import { useCharacterSearch } from './useCharacterSearch';
5
5
  import { useMenuTriggerContext_unstable } from '../../contexts/menuTriggerContext';
6
6
  import { ChevronRightFilled, ChevronRightRegular, ChevronLeftFilled, ChevronLeftRegular, bundleIcon } from '@fluentui/react-icons';
7
7
  import { useMenuListContext_unstable } from '../../contexts/menuListContext';
8
8
  import { useMenuContext_unstable } from '../../contexts/menuContext';
9
+ import { useARIAButtonShorthand } from '@fluentui/react-aria';
10
+ import { Enter, Space } from '@fluentui/keyboard-keys';
9
11
  const ChevronRightIcon = /*#__PURE__*/bundleIcon(ChevronRightFilled, ChevronRightRegular);
10
12
  const ChevronLeftIcon = /*#__PURE__*/bundleIcon(ChevronLeftFilled, ChevronLeftRegular);
11
13
  /**
@@ -13,22 +15,28 @@ const ChevronLeftIcon = /*#__PURE__*/bundleIcon(ChevronLeftFilled, ChevronLeftRe
13
15
  */
14
16
 
15
17
  export const useMenuItem_unstable = (props, ref) => {
16
- var _a;
17
-
18
+ const isSubmenuTrigger = useMenuTriggerContext_unstable();
19
+ const persistOnClickContext = useMenuContext_unstable(context => context.persistOnItemClick);
20
+ const {
21
+ as = 'div',
22
+ disabled,
23
+ disabledFocusable,
24
+ hasSubmenu = isSubmenuTrigger,
25
+ persistOnClick = persistOnClickContext
26
+ } = props;
18
27
  const hasIcons = useMenuListContext_unstable(context => context.hasIcons);
19
28
  const hasCheckmarks = useMenuListContext_unstable(context => context.hasCheckmarks);
20
29
  const setOpen = useMenuContext_unstable(context => context.setOpen);
21
- const persistOnClickContext = useMenuContext_unstable(context => context.persistOnItemClick);
22
- const dismissedWithKeyboardRef = React.useRef(false);
23
- const isSubmenuTrigger = useMenuTriggerContext_unstable();
24
- const hasSubmenu = (_a = props.hasSubmenu) !== null && _a !== void 0 ? _a : isSubmenuTrigger;
25
30
  const {
26
31
  dir
27
32
  } = useFluent();
28
33
  const innerRef = React.useRef(null);
34
+ const dismissedWithKeyboardRef = React.useRef(false);
35
+ const isDisabled = Boolean(disabled || disabledFocusable);
29
36
  const state = {
30
37
  hasSubmenu,
31
- ...props,
38
+ disabled: isDisabled,
39
+ persistOnClick,
32
40
  components: {
33
41
  root: 'div',
34
42
  icon: 'span',
@@ -37,13 +45,48 @@ export const useMenuItem_unstable = (props, ref) => {
37
45
  content: 'span',
38
46
  secondaryContent: 'span'
39
47
  },
40
- root: getNativeElementProps('div', {
41
- ref: useMergedRefs(ref, innerRef),
42
- role: 'menuitem',
43
- tabIndex: 0,
44
- 'aria-disabled': props.disabled,
45
- ...props
46
- }),
48
+ isNativeButton: as === 'button',
49
+ root: getNativeElementProps(as, useARIAButtonShorthand({
50
+ disabled: false,
51
+ disabledFocusable: isDisabled,
52
+ as
53
+ }, {
54
+ required: true,
55
+ defaultProps: {
56
+ role: 'menuitem',
57
+ ...props,
58
+ ref: useMergedRefs(ref, innerRef),
59
+ onKeyDown: useEventCallback(event => {
60
+ var _a;
61
+
62
+ (_a = props.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(props, event);
63
+
64
+ if (!event.isDefaultPrevented() && (event.key === Space || event.key === Enter)) {
65
+ dismissedWithKeyboardRef.current = true;
66
+ }
67
+ }),
68
+ onMouseEnter: useEventCallback(event => {
69
+ var _a, _b;
70
+
71
+ (_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
72
+ (_b = props.onMouseEnter) === null || _b === void 0 ? void 0 : _b.call(props, event);
73
+ }),
74
+ onClick: useEventCallback(event => {
75
+ var _a;
76
+
77
+ if (!hasSubmenu && !persistOnClick) {
78
+ setOpen(event, {
79
+ open: false,
80
+ keyboard: dismissedWithKeyboardRef.current,
81
+ bubble: true
82
+ });
83
+ dismissedWithKeyboardRef.current = false;
84
+ }
85
+
86
+ (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, event);
87
+ })
88
+ }
89
+ })),
47
90
  icon: resolveShorthand(props.icon, {
48
91
  required: hasIcons
49
92
  }),
@@ -64,63 +107,6 @@ export const useMenuItem_unstable = (props, ref) => {
64
107
  }),
65
108
  secondaryContent: resolveShorthand(props.secondaryContent)
66
109
  };
67
- const {
68
- onClick: onClickOriginal,
69
- onKeyDown: onKeyDownOriginal
70
- } = state.root;
71
-
72
- state.root.onKeyDown = e => {
73
- var _a;
74
-
75
- if (shouldPreventDefaultOnKeyDown(e)) {
76
- if (state.disabled) {
77
- e.preventDefault();
78
- e.stopPropagation();
79
- return;
80
- }
81
-
82
- dismissedWithKeyboardRef.current = true;
83
- e.preventDefault();
84
- (_a = e.target) === null || _a === void 0 ? void 0 : _a.click();
85
- }
86
-
87
- onKeyDownOriginal === null || onKeyDownOriginal === void 0 ? void 0 : onKeyDownOriginal(e);
88
- };
89
-
90
- state.root.onClick = e => {
91
- if (state.disabled) {
92
- e.preventDefault();
93
- e.stopPropagation();
94
- return;
95
- }
96
-
97
- let shouldPersist = persistOnClickContext; // prop wins over context;
98
-
99
- if (state.persistOnClick !== undefined && persistOnClickContext !== state.persistOnClick) {
100
- shouldPersist = state.persistOnClick;
101
- }
102
-
103
- if (!hasSubmenu && !shouldPersist) {
104
- setOpen(e, {
105
- open: false,
106
- keyboard: dismissedWithKeyboardRef.current,
107
- bubble: true
108
- });
109
- dismissedWithKeyboardRef.current = false;
110
- }
111
-
112
- onClickOriginal === null || onClickOriginal === void 0 ? void 0 : onClickOriginal(e);
113
- };
114
-
115
- const {
116
- onMouseEnter: onMouseEnterOriginal
117
- } = state.root;
118
- state.root.onMouseEnter = useEventCallback(e => {
119
- var _a;
120
-
121
- (_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
122
- onMouseEnterOriginal === null || onMouseEnterOriginal === void 0 ? void 0 : onMouseEnterOriginal(e);
123
- });
124
110
  useCharacterSearch(state, innerRef);
125
111
  return state;
126
112
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["components/MenuItem/useMenuItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SACE,gBADF,EAEE,6BAFF,EAGE,gBAH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AE;EAAhB,IAAyC,KAAK,CAAC,IAArD;EACA,KAAK,CAAC,IAAN,CAAW,YAAX,GAA0B,gBAAgB,CAAC,CAAC,IAAG;;;IAC7C,CAAA,EAAA,GAAA,QAAQ,CAAC,OAAT,MAAgB,IAAhB,IAAgB,EAAA,KAAA,KAAA,CAAhB,GAAgB,KAAA,CAAhB,GAAgB,EAAA,CAAE,KAAF,EAAhB;IAEA,oBAAoB,KAAA,IAApB,IAAA,oBAAoB,KAAA,KAAA,CAApB,GAAoB,KAAA,CAApB,GAAA,oBAAoB,CAAG,CAAH,CAApB;EACD,CAJyC,CAA1C;EAMA,kBAAkB,CAAC,KAAD,EAAQ,QAAR,CAAlB;EACA,OAAO,KAAP;AACD,CA7FM","sourcesContent":["import * as React from 'react';\nimport {\n useEventCallback,\n shouldPreventDefaultOnKeyDown,\n resolveShorthand,\n useMergedRefs,\n getNativeElementProps,\n} from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { useCharacterSearch } from './useCharacterSearch';\nimport { useMenuTriggerContext_unstable } from '../../contexts/menuTriggerContext';\nimport {\n ChevronRightFilled,\n ChevronRightRegular,\n ChevronLeftFilled,\n ChevronLeftRegular,\n bundleIcon,\n} from '@fluentui/react-icons';\nimport { useMenuListContext_unstable } from '../../contexts/menuListContext';\nimport { useMenuContext_unstable } from '../../contexts/menuContext';\nimport type { MenuItemProps, MenuItemState } from './MenuItem.types';\n\nconst ChevronRightIcon = bundleIcon(ChevronRightFilled, ChevronRightRegular);\nconst ChevronLeftIcon = bundleIcon(ChevronLeftFilled, ChevronLeftRegular);\n\n/**\n * Returns the props and state required to render the component\n */\nexport const useMenuItem_unstable = (props: MenuItemProps, ref: React.Ref<HTMLElement>): MenuItemState => {\n const hasIcons = useMenuListContext_unstable(context => context.hasIcons);\n const hasCheckmarks = useMenuListContext_unstable(context => context.hasCheckmarks);\n const setOpen = useMenuContext_unstable(context => context.setOpen);\n const persistOnClickContext = useMenuContext_unstable(context => context.persistOnItemClick);\n const dismissedWithKeyboardRef = React.useRef(false);\n\n const isSubmenuTrigger = useMenuTriggerContext_unstable();\n const hasSubmenu = props.hasSubmenu ?? isSubmenuTrigger;\n\n const { dir } = useFluent();\n const innerRef = React.useRef<HTMLElement>(null);\n\n const state: MenuItemState = {\n hasSubmenu,\n ...props,\n components: {\n root: 'div',\n icon: 'span',\n checkmark: 'span',\n submenuIndicator: 'span',\n content: 'span',\n secondaryContent: 'span',\n },\n root: getNativeElementProps('div', {\n ref: useMergedRefs(ref, innerRef),\n role: 'menuitem',\n tabIndex: 0,\n 'aria-disabled': props.disabled,\n ...props,\n }),\n icon: resolveShorthand(props.icon, { required: hasIcons }),\n checkmark: resolveShorthand(props.checkmark, { required: hasCheckmarks }),\n submenuIndicator: resolveShorthand(props.submenuIndicator, {\n required: hasSubmenu,\n defaultProps: {\n children: dir === 'ltr' ? <ChevronRightIcon /> : <ChevronLeftIcon />,\n },\n }),\n content: resolveShorthand(props.content, {\n required: !!props.children,\n defaultProps: { children: props.children },\n }),\n secondaryContent: resolveShorthand(props.secondaryContent),\n };\n\n const { onClick: onClickOriginal, onKeyDown: onKeyDownOriginal } = state.root;\n state.root.onKeyDown = e => {\n if (shouldPreventDefaultOnKeyDown(e)) {\n if (state.disabled) {\n e.preventDefault();\n e.stopPropagation();\n return;\n }\n\n dismissedWithKeyboardRef.current = true;\n e.preventDefault();\n (e.target as HTMLElement)?.click();\n }\n\n onKeyDownOriginal?.(e);\n };\n\n state.root.onClick = e => {\n if (state.disabled) {\n e.preventDefault();\n e.stopPropagation();\n return;\n }\n\n let shouldPersist = persistOnClickContext;\n // prop wins over context;\n if (state.persistOnClick !== undefined && persistOnClickContext !== state.persistOnClick) {\n shouldPersist = state.persistOnClick;\n }\n\n if (!hasSubmenu && !shouldPersist) {\n setOpen(e, { open: false, keyboard: dismissedWithKeyboardRef.current, bubble: true });\n dismissedWithKeyboardRef.current = false;\n }\n\n onClickOriginal?.(e);\n };\n\n const { onMouseEnter: onMouseEnterOriginal } = state.root;\n state.root.onMouseEnter = useEventCallback(e => {\n innerRef.current?.focus();\n\n onMouseEnterOriginal?.(e);\n });\n\n useCharacterSearch(state, innerRef);\n return state;\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["components/MenuItem/useMenuItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,gBAAT,EAA2B,gBAA3B,EAA6C,aAA7C,EAA4D,qBAA5D,QAAyF,2BAAzF;AACA,SAAS,kBAAkB,IAAI,SAA/B,QAAgD,iCAAhD;AACA,SAAS,kBAAT,QAAmC,sBAAnC;AACA,SAAS,8BAAT,QAA+C,mCAA/C;AACA,SACE,kBADF,EAEE,mBAFF,EAGE,iBAHF,EAIE,kBAJF,EAKE,UALF,QAMO,uBANP;AAOA,SAAS,2BAAT,QAA4C,gCAA5C;AACA,SAAS,uBAAT,QAAwC,4BAAxC;AAGA,SAAS,sBAAT,QAAuC,sBAAvC;AACA,SAAS,KAAT,EAAgB,KAAhB,QAA6B,yBAA7B;AAEA,MAAM,gBAAgB,gBAAG,UAAU,CAAC,kBAAD,EAAqB,mBAArB,CAAnC;AACA,MAAM,eAAe,gBAAG,UAAU,CAAC,iBAAD,EAAoB,kBAApB,CAAlC;AAEA;;AAEG;;AACH,OAAO,MAAM,oBAAoB,GAAG,CAAC,KAAD,EAAuB,GAAvB,KAAkF;EACpH,MAAM,gBAAgB,GAAG,8BAA8B,EAAvD;EACA,MAAM,qBAAqB,GAAG,uBAAuB,CAAC,OAAO,IAAI,OAAO,CAAC,kBAApB,CAArD;EACA,MAAM;IACJ,EAAE,GAAG,KADD;IAEJ,QAFI;IAGJ,iBAHI;IAIJ,UAAU,GAAG,gBAJT;IAKJ,cAAc,GAAG;EALb,IAMF,KANJ;EAOA,MAAM,QAAQ,GAAG,2BAA2B,CAAC,OAAO,IAAI,OAAO,CAAC,QAApB,CAA5C;EACA,MAAM,aAAa,GA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zD,QAAQ,EAAE,UAD+C;MAEzD,YAAY,EAAE;QACZ,QAAQ,EAAE,GAAG,KAAK,KAAR,gBAAgB,KAAA,CAAA,aAAA,CAAC,gBAAD,EAAiB,IAAjB,CAAhB,gBAAuC,KAAA,CAAA,aAAA,CAAC,eAAD,EAAgB,IAAhB;MADrC;IAF2C,CAAzB,CAhDP;IAsD3B,OAAO,EAAE,gBAAgB,CAAC,KAAK,CAAC,OAAP,EAAgB;MACvC,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,QADqB;MAEvC,YAAY,EAAE;QAAE,QAAQ,EAAE,KAAK,CAAC;MAAlB;IAFyB,CAAhB,CAtDE;IA0D3B,gBAAgB,EAAE,gBAAgB,CAAC,KAAK,CAAC,gBAAP;EA1DP,CAA7B;EA4DA,kBAAkB,CAAC,KAAD,EAAQ,QAAR,CAAlB;EACA,OAAO,KAAP;AACD,CAlFM","sourcesContent":["import * as React from 'react';\nimport { useEventCallback, resolveShorthand, useMergedRefs, getNativeElementProps } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { useCharacterSearch } from './useCharacterSearch';\nimport { useMenuTriggerContext_unstable } from '../../contexts/menuTriggerContext';\nimport {\n ChevronRightFilled,\n ChevronRightRegular,\n ChevronLeftFilled,\n ChevronLeftRegular,\n bundleIcon,\n} from '@fluentui/react-icons';\nimport { useMenuListContext_unstable } from '../../contexts/menuListContext';\nimport { useMenuContext_unstable } from '../../contexts/menuContext';\nimport type { MenuItemProps, MenuItemState } from './MenuItem.types';\nimport type { ARIAButtonElement, ARIAButtonElementIntersection, ARIAButtonSlotProps } from '@fluentui/react-aria';\nimport { useARIAButtonShorthand } from '@fluentui/react-aria';\nimport { Enter, Space } from '@fluentui/keyboard-keys';\n\nconst ChevronRightIcon = bundleIcon(ChevronRightFilled, ChevronRightRegular);\nconst ChevronLeftIcon = bundleIcon(ChevronLeftFilled, ChevronLeftRegular);\n\n/**\n * Returns the props and state required to render the component\n */\nexport const useMenuItem_unstable = (props: MenuItemProps, ref: React.Ref<ARIAButtonElement<'div'>>): MenuItemState => {\n const isSubmenuTrigger = useMenuTriggerContext_unstable();\n const persistOnClickContext = useMenuContext_unstable(context => context.persistOnItemClick);\n const {\n as = 'div',\n disabled,\n disabledFocusable,\n hasSubmenu = isSubmenuTrigger,\n persistOnClick = persistOnClickContext,\n } = props;\n const hasIcons = useMenuListContext_unstable(context => context.hasIcons);\n const hasCheckmarks = useMenuListContext_unstable(context => context.hasCheckmarks);\n const setOpen = useMenuContext_unstable(context => context.setOpen);\n\n const { dir } = useFluent();\n const innerRef = React.useRef<ARIAButtonElementIntersection<'div'>>(null);\n const dismissedWithKeyboardRef = React.useRef(false);\n\n const isDisabled = Boolean(disabled || disabledFocusable);\n\n const state: MenuItemState = {\n hasSubmenu,\n disabled: isDisabled,\n persistOnClick,\n components: {\n root: 'div',\n icon: 'span',\n checkmark: 'span',\n submenuIndicator: 'span',\n content: 'span',\n secondaryContent: 'span',\n },\n isNativeButton: as === 'button',\n root: getNativeElementProps(\n as,\n useARIAButtonShorthand<ARIAButtonSlotProps<'div'>>(\n { disabled: false, disabledFocusable: isDisabled, as },\n {\n required: true,\n defaultProps: {\n role: 'menuitem',\n ...props,\n ref: useMergedRefs(ref, innerRef) as React.Ref<ARIAButtonElementIntersection<'div'>>,\n onKeyDown: useEventCallback(event => {\n props.onKeyDown?.(event);\n if (!event.isDefaultPrevented() && (event.key === Space || event.key === Enter)) {\n dismissedWithKeyboardRef.current = true;\n }\n }),\n onMouseEnter: useEventCallback(event => {\n innerRef.current?.focus();\n\n props.onMouseEnter?.(event);\n }),\n onClick: useEventCallback(event => {\n if (!hasSubmenu && !persistOnClick) {\n setOpen(event, { open: false, keyboard: dismissedWithKeyboardRef.current, bubble: true });\n dismissedWithKeyboardRef.current = false;\n }\n\n props.onClick?.(event);\n }),\n },\n },\n ),\n ),\n icon: resolveShorthand(props.icon, { required: hasIcons }),\n checkmark: resolveShorthand(props.checkmark, { required: hasCheckmarks }),\n submenuIndicator: resolveShorthand(props.submenuIndicator, {\n required: hasSubmenu,\n defaultProps: {\n children: dir === 'ltr' ? <ChevronRightIcon /> : <ChevronLeftIcon />,\n },\n }),\n content: resolveShorthand(props.content, {\n required: !!props.children,\n defaultProps: { children: props.children },\n }),\n secondaryContent: resolveShorthand(props.secondaryContent),\n };\n useCharacterSearch(state, innerRef);\n return state;\n};\n"],"sourceRoot":"../src/"}