@fluentui/react-menu 9.5.0 → 9.5.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.json +60 -1
- package/CHANGELOG.md +17 -2
- package/dist/index.d.ts +57 -10
- package/lib/components/Menu/Menu.types.js.map +1 -1
- package/lib/components/Menu/useMenu.js +10 -19
- package/lib/components/Menu/useMenu.js.map +1 -1
- package/lib/components/Menu/useMenuContextValues.js +0 -2
- package/lib/components/Menu/useMenuContextValues.js.map +1 -1
- package/lib/components/MenuDivider/useMenuDividerStyles.js +2 -2
- package/lib/components/MenuDivider/useMenuDividerStyles.js.map +1 -1
- package/lib/components/MenuGroup/useMenuGroup.js +1 -1
- package/lib/components/MenuGroup/useMenuGroup.js.map +1 -1
- package/lib/components/MenuList/MenuList.types.js.map +1 -1
- package/lib/components/MenuList/useMenuList.js +20 -29
- package/lib/components/MenuList/useMenuList.js.map +1 -1
- package/lib/components/MenuList/useMenuListContextValues.js +0 -2
- package/lib/components/MenuList/useMenuListContextValues.js.map +1 -1
- package/lib/contexts/menuContext.js +0 -1
- package/lib/contexts/menuContext.js.map +1 -1
- package/lib/contexts/menuListContext.js +0 -1
- package/lib/contexts/menuListContext.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib-amd/components/Menu/Menu.types.js.map +1 -1
- package/lib-amd/components/Menu/useMenu.js +8 -11
- package/lib-amd/components/Menu/useMenu.js.map +1 -1
- package/lib-amd/components/Menu/useMenuContextValues.js +1 -2
- package/lib-amd/components/Menu/useMenuContextValues.js.map +1 -1
- package/lib-amd/components/MenuDivider/useMenuDividerStyles.js +1 -1
- package/lib-amd/components/MenuDivider/useMenuDividerStyles.js.map +1 -1
- package/lib-amd/components/MenuGroup/useMenuGroup.js.map +1 -1
- package/lib-amd/components/MenuList/MenuList.types.js.map +1 -1
- package/lib-amd/components/MenuList/useMenuList.js +17 -12
- package/lib-amd/components/MenuList/useMenuList.js.map +1 -1
- package/lib-amd/components/MenuList/useMenuListContextValues.js +1 -2
- package/lib-amd/components/MenuList/useMenuListContextValues.js.map +1 -1
- package/lib-amd/contexts/menuContext.js +0 -1
- package/lib-amd/contexts/menuContext.js.map +1 -1
- package/lib-amd/contexts/menuListContext.js +0 -1
- package/lib-amd/contexts/menuListContext.js.map +1 -1
- package/lib-amd/index.js.map +1 -1
- package/lib-commonjs/components/Menu/useMenu.js +10 -19
- package/lib-commonjs/components/Menu/useMenu.js.map +1 -1
- package/lib-commonjs/components/Menu/useMenuContextValues.js +0 -2
- package/lib-commonjs/components/Menu/useMenuContextValues.js.map +1 -1
- package/lib-commonjs/components/MenuDivider/useMenuDividerStyles.js +2 -2
- package/lib-commonjs/components/MenuDivider/useMenuDividerStyles.js.map +1 -1
- package/lib-commonjs/components/MenuGroup/useMenuGroup.js +1 -1
- package/lib-commonjs/components/MenuGroup/useMenuGroup.js.map +1 -1
- package/lib-commonjs/components/MenuList/useMenuList.js +20 -29
- package/lib-commonjs/components/MenuList/useMenuList.js.map +1 -1
- package/lib-commonjs/components/MenuList/useMenuListContextValues.js +0 -2
- package/lib-commonjs/components/MenuList/useMenuListContextValues.js.map +1 -1
- package/lib-commonjs/contexts/menuContext.js +0 -1
- package/lib-commonjs/contexts/menuContext.js.map +1 -1
- package/lib-commonjs/contexts/menuListContext.js +0 -1
- package/lib-commonjs/contexts/menuListContext.js.map +1 -1
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.json
CHANGED
@@ -2,7 +2,66 @@
|
|
2
2
|
"name": "@fluentui/react-menu",
|
3
3
|
"entries": [
|
4
4
|
{
|
5
|
-
"date": "
|
5
|
+
"date": "Mon, 05 Dec 2022 18:25:22 GMT",
|
6
|
+
"tag": "@fluentui/react-menu_v9.5.1",
|
7
|
+
"version": "9.5.1",
|
8
|
+
"comments": {
|
9
|
+
"patch": [
|
10
|
+
{
|
11
|
+
"author": "bernardo.sunderhus@gmail.com",
|
12
|
+
"package": "@fluentui/react-menu",
|
13
|
+
"commit": "41b0dbe63181a473ea54811fffd5a9582d7b28b6",
|
14
|
+
"comment": "chore: removes prop spreading on MenuList state"
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"author": "lingfangao@hotmail.com",
|
18
|
+
"package": "@fluentui/react-menu",
|
19
|
+
"commit": "6f036a808e0d09e6395abe1f6d3046d1f7d2c28d",
|
20
|
+
"comment": "fix: MenuDivider thickness should be `strokeWidthThin`"
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"author": "beachball",
|
24
|
+
"package": "@fluentui/react-menu",
|
25
|
+
"comment": "Bump @fluentui/react-portal to v9.0.12",
|
26
|
+
"commit": "4c29542a51bf068e171690cc8e59c14489883912"
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"author": "beachball",
|
30
|
+
"package": "@fluentui/react-menu",
|
31
|
+
"comment": "Bump @fluentui/react-positioning to v9.3.3",
|
32
|
+
"commit": "4c29542a51bf068e171690cc8e59c14489883912"
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"author": "beachball",
|
36
|
+
"package": "@fluentui/react-menu",
|
37
|
+
"comment": "Bump @fluentui/react-shared-contexts to v9.1.2",
|
38
|
+
"commit": "4c29542a51bf068e171690cc8e59c14489883912"
|
39
|
+
},
|
40
|
+
{
|
41
|
+
"author": "beachball",
|
42
|
+
"package": "@fluentui/react-menu",
|
43
|
+
"comment": "Bump @fluentui/react-tabster to v9.3.2",
|
44
|
+
"commit": "4c29542a51bf068e171690cc8e59c14489883912"
|
45
|
+
},
|
46
|
+
{
|
47
|
+
"author": "beachball",
|
48
|
+
"package": "@fluentui/react-menu",
|
49
|
+
"comment": "Bump @fluentui/react-theme to v9.1.3",
|
50
|
+
"commit": "4c29542a51bf068e171690cc8e59c14489883912"
|
51
|
+
}
|
52
|
+
],
|
53
|
+
"none": [
|
54
|
+
{
|
55
|
+
"author": "mgodbolt@microsoft.com",
|
56
|
+
"package": "@fluentui/react-menu",
|
57
|
+
"commit": "b7bc3cad64eeb09c193b102b9497b1b01464dfeb",
|
58
|
+
"comment": "Added a link in the docs to the MenuButton"
|
59
|
+
}
|
60
|
+
]
|
61
|
+
}
|
62
|
+
},
|
63
|
+
{
|
64
|
+
"date": "Thu, 17 Nov 2022 23:05:41 GMT",
|
6
65
|
"tag": "@fluentui/react-menu_v9.5.0",
|
7
66
|
"version": "9.5.0",
|
8
67
|
"comments": {
|
package/CHANGELOG.md
CHANGED
@@ -1,12 +1,27 @@
|
|
1
1
|
# Change Log - @fluentui/react-menu
|
2
2
|
|
3
|
-
This log was last generated on
|
3
|
+
This log was last generated on Mon, 05 Dec 2022 18:25:22 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
+
## [9.5.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-menu_v9.5.1)
|
8
|
+
|
9
|
+
Mon, 05 Dec 2022 18:25:22 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-menu_v9.5.0..@fluentui/react-menu_v9.5.1)
|
11
|
+
|
12
|
+
### Patches
|
13
|
+
|
14
|
+
- chore: removes prop spreading on MenuList state ([PR #25672](https://github.com/microsoft/fluentui/pull/25672) by bernardo.sunderhus@gmail.com)
|
15
|
+
- fix: MenuDivider thickness should be `strokeWidthThin` ([PR #25711](https://github.com/microsoft/fluentui/pull/25711) by lingfangao@hotmail.com)
|
16
|
+
- Bump @fluentui/react-portal to v9.0.12 ([PR #25798](https://github.com/microsoft/fluentui/pull/25798) by beachball)
|
17
|
+
- Bump @fluentui/react-positioning to v9.3.3 ([PR #25798](https://github.com/microsoft/fluentui/pull/25798) by beachball)
|
18
|
+
- Bump @fluentui/react-shared-contexts to v9.1.2 ([PR #25798](https://github.com/microsoft/fluentui/pull/25798) by beachball)
|
19
|
+
- Bump @fluentui/react-tabster to v9.3.2 ([PR #25798](https://github.com/microsoft/fluentui/pull/25798) by beachball)
|
20
|
+
- Bump @fluentui/react-theme to v9.1.3 ([PR #25798](https://github.com/microsoft/fluentui/pull/25798) by beachball)
|
21
|
+
|
7
22
|
## [9.5.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-menu_v9.5.0)
|
8
23
|
|
9
|
-
Thu, 17 Nov 2022 23:
|
24
|
+
Thu, 17 Nov 2022 23:05:41 GMT
|
10
25
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-menu_v9.4.1..@fluentui/react-menu_v9.5.0)
|
11
26
|
|
12
27
|
### Minor changes
|
package/dist/index.d.ts
CHANGED
@@ -35,9 +35,15 @@ export declare type MenuCheckedValueChangeEvent = React_2.MouseEvent | React_2.K
|
|
35
35
|
*
|
36
36
|
* Extends and drills down MenuList props to simplify API
|
37
37
|
*/
|
38
|
-
export declare type MenuContextValue = Pick<MenuState, 'openOnHover' | 'openOnContext' | 'triggerRef' | 'menuPopoverRef' | 'setOpen' | 'isSubmenu' | 'triggerId' | 'hasIcons' | 'hasCheckmarks' | 'persistOnItemClick' | 'inline' | 'checkedValues' | 'onCheckedValueChange'
|
38
|
+
export declare type MenuContextValue = Pick<MenuState, 'openOnHover' | 'openOnContext' | 'triggerRef' | 'menuPopoverRef' | 'setOpen' | 'isSubmenu' | 'triggerId' | 'hasIcons' | 'hasCheckmarks' | 'persistOnItemClick' | 'inline' | 'checkedValues' | 'onCheckedValueChange'> & {
|
39
39
|
open: boolean;
|
40
40
|
triggerId: string;
|
41
|
+
/**
|
42
|
+
* Default values to be checked on mount
|
43
|
+
* @deprecated this property is not used internally anymore,
|
44
|
+
* the signature remains just to avoid breaking changes
|
45
|
+
*/
|
46
|
+
defaultCheckedValues?: Record<string, string[]>;
|
41
47
|
};
|
42
48
|
|
43
49
|
export declare type MenuContextValues = {
|
@@ -221,10 +227,20 @@ export declare const menuListClassNames: SlotClassNames<MenuListSlots>;
|
|
221
227
|
/**
|
222
228
|
* Context shared between MenuList and its children components
|
223
229
|
*/
|
224
|
-
export declare type MenuListContextValue = Pick<MenuListProps, 'checkedValues' | '
|
230
|
+
export declare type MenuListContextValue = Pick<MenuListProps, 'checkedValues' | 'hasIcons' | 'hasCheckmarks'> & {
|
225
231
|
setFocusByFirstCharacter?: (e: React_2.KeyboardEvent<HTMLElement>, itemEl: HTMLElement) => void;
|
226
232
|
toggleCheckbox?: SelectableHandler;
|
227
233
|
selectRadio?: SelectableHandler;
|
234
|
+
/**
|
235
|
+
* Callback when checked items change for value with a name
|
236
|
+
*
|
237
|
+
* @param event - React's original SyntheticEvent
|
238
|
+
* @param data - A data object with relevant information
|
239
|
+
*
|
240
|
+
* @deprecated this property is not used internally anymore,
|
241
|
+
* the signature remains just to avoid breaking changes
|
242
|
+
*/
|
243
|
+
onCheckedValueChange?: (e: MenuCheckedValueChangeEvent, data: MenuCheckedValueChangeData) => void;
|
228
244
|
};
|
229
245
|
|
230
246
|
export declare type MenuListContextValues = {
|
@@ -263,7 +279,7 @@ export declare type MenuListSlots = {
|
|
263
279
|
root: Slot<'div'>;
|
264
280
|
};
|
265
281
|
|
266
|
-
export declare type MenuListState = ComponentState<MenuListSlots> &
|
282
|
+
export declare type MenuListState = ComponentState<MenuListSlots> & Required<Pick<MenuListProps, 'checkedValues' | 'hasCheckmarks' | 'hasIcons'>> & {
|
267
283
|
/**
|
268
284
|
* Selects a radio item, will de-select the currently selected ratio item
|
269
285
|
*/
|
@@ -273,6 +289,21 @@ export declare type MenuListState = ComponentState<MenuListSlots> & Pick<MenuLis
|
|
273
289
|
*/
|
274
290
|
setFocusByFirstCharacter: NonNullable<MenuListContextValue['setFocusByFirstCharacter']>;
|
275
291
|
toggleCheckbox: SelectableHandler;
|
292
|
+
/**
|
293
|
+
* Default values to be checked on mount
|
294
|
+
* @deprecated this property is not used internally anymore,
|
295
|
+
* the signature remains just to avoid breaking changes
|
296
|
+
*/
|
297
|
+
defaultCheckedValues?: Record<string, string[]>;
|
298
|
+
/**
|
299
|
+
* Callback when checked items change for value with a name
|
300
|
+
*
|
301
|
+
* @param event - React's original SyntheticEvent
|
302
|
+
* @param data - A data object with relevant information
|
303
|
+
* @deprecated this property is not used internally anymore,
|
304
|
+
* the signature remains just to avoid breaking changes
|
305
|
+
*/
|
306
|
+
onCheckedValueChange?: (e: MenuCheckedValueChangeEvent, data: MenuCheckedValueChangeData) => void;
|
276
307
|
};
|
277
308
|
|
278
309
|
/**
|
@@ -374,12 +405,6 @@ export declare type MenuProps = ComponentProps<MenuSlots> & Pick<MenuListProps,
|
|
374
405
|
* Alternatively can only contain {@link MenuPopover} if using a custom `target`.
|
375
406
|
*/
|
376
407
|
children: [JSX.Element, JSX.Element] | JSX.Element;
|
377
|
-
/**
|
378
|
-
* Whether the popup is open by default
|
379
|
-
*
|
380
|
-
* @default false
|
381
|
-
*/
|
382
|
-
defaultOpen?: boolean;
|
383
408
|
/**
|
384
409
|
* Sets the delay for mouse open/close for the popover one mouse enter/leave
|
385
410
|
*/
|
@@ -402,6 +427,12 @@ export declare type MenuProps = ComponentProps<MenuSlots> & Pick<MenuListProps,
|
|
402
427
|
* @default false
|
403
428
|
*/
|
404
429
|
open?: boolean;
|
430
|
+
/**
|
431
|
+
* Whether the popup is open by default
|
432
|
+
*
|
433
|
+
* @default false
|
434
|
+
*/
|
435
|
+
defaultOpen?: boolean;
|
405
436
|
/**
|
406
437
|
* Opens the menu on right click (context menu), removes all other menu open interactions
|
407
438
|
*
|
@@ -457,7 +488,7 @@ export declare type MenuSplitGroupSlots = {
|
|
457
488
|
*/
|
458
489
|
export declare type MenuSplitGroupState = ComponentState<MenuSplitGroupSlots>;
|
459
490
|
|
460
|
-
export declare type MenuState = ComponentState<MenuSlots> &
|
491
|
+
export declare type MenuState = ComponentState<MenuSlots> & Required<Pick<MenuProps, 'hasCheckmarks' | 'hasIcons' | 'inline' | 'checkedValues' | 'onCheckedValueChange' | 'open' | 'openOnHover' | 'closeOnScroll' | 'hoverDelay' | 'openOnContext' | 'persistOnItemClick'>> & {
|
461
492
|
/**
|
462
493
|
* Anchors the popper to the mouse click for context events
|
463
494
|
*/
|
@@ -494,6 +525,19 @@ export declare type MenuState = ComponentState<MenuSlots> & Pick<MenuProps, 'onO
|
|
494
525
|
* The ref for the MenuTrigger, used for popup positioning
|
495
526
|
*/
|
496
527
|
triggerRef: React_2.MutableRefObject<HTMLElement>;
|
528
|
+
/**
|
529
|
+
* Call back when the component requests to change value
|
530
|
+
* The `open` value is used as a hint when directly controlling the component
|
531
|
+
* @deprecated this property is not used internally anymore,
|
532
|
+
* the signature remains just to avoid breaking changes
|
533
|
+
*/
|
534
|
+
onOpenChange?: (e: MenuOpenEvent, data: MenuOpenChangeData) => void;
|
535
|
+
/**
|
536
|
+
* Default values to be checked on mount
|
537
|
+
@deprecated this property is not used internally anymore,
|
538
|
+
* the signature remains just to avoid breaking changes
|
539
|
+
*/
|
540
|
+
defaultCheckedValues?: Record<string, string[]>;
|
497
541
|
};
|
498
542
|
|
499
543
|
/**
|
@@ -592,6 +636,9 @@ export declare const renderMenuTrigger_unstable: (state: MenuTriggerState) => JS
|
|
592
636
|
|
593
637
|
export declare type SelectableHandler = (e: React_2.MouseEvent | React_2.KeyboardEvent, name: string, value: string, checked: boolean) => void;
|
594
638
|
|
639
|
+
/**
|
640
|
+
* @deprecated this type is not being used internally anymore
|
641
|
+
*/
|
595
642
|
export declare type UninitializedMenuListState = Omit<MenuListState, 'checkedValues' | 'selectRadio' | 'setFocusByFirstCharacter' | 'toggleCheckbox'> & Partial<Pick<MenuListState, 'checkedValues'>>;
|
596
643
|
|
597
644
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Menu.types.js","sourceRoot":"../src/","sources":["packages/react-components/react-menu/src/components/Menu/Menu.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport { PositioningVirtualElement, SetVirtualMouseTarget } 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 *
|
1
|
+
{"version":3,"file":"Menu.types.js","sourceRoot":"../src/","sources":["packages/react-components/react-menu/src/components/Menu/Menu.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport { PositioningVirtualElement, SetVirtualMouseTarget } 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 * 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: MenuOpenEvent, data: MenuOpenChangeData) => void;\n\n /**\n * Whether the popup is open\n *\n * @default false\n */\n open?: boolean;\n\n /**\n * Whether the popup is open by default\n *\n * @default false\n */\n defaultOpen?: 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 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?: PositioningVirtualElement;\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: SetVirtualMouseTarget;\n\n /**\n * Callback to open/close the popup\n */\n setOpen: (e: MenuOpenEvent, 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 * Call back when the component requests to change value\n * The `open` value is used as a hint when directly controlling the component\n * @deprecated this property is not used internally anymore,\n * the signature remains just to avoid breaking changes\n */\n onOpenChange?: (e: MenuOpenEvent, data: MenuOpenChangeData) => void;\n /**\n * Default values to be checked on mount\n @deprecated this property is not used internally anymore,\n * the signature remains just to avoid breaking changes\n */\n defaultCheckedValues?: Record<string, string[]>;\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 MenuOpenEvent = MenuOpenChangeData['event'];\n/**\n * @deprecated use MenuOpenEvent instead\n */\nexport type MenuOpenEvents = MenuOpenEvent;\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 | {\n type: 'menuTriggerContextMenu';\n event: React.MouseEvent<HTMLElement>;\n }\n | {\n type: 'menuTriggerClick';\n event: React.MouseEvent<HTMLElement>;\n }\n | {\n type: 'menuTriggerMouseEnter';\n event: React.MouseEvent<HTMLElement>;\n }\n | {\n type: 'menuTriggerMouseLeave';\n event: React.MouseEvent<HTMLElement>;\n }\n | {\n type: 'menuTriggerMouseMove';\n event: React.MouseEvent<HTMLElement>;\n }\n | {\n type: 'menuTriggerKeyDown';\n event: React.KeyboardEvent<HTMLElement>;\n }\n | {\n type: 'menuItemClick';\n event: React.MouseEvent<HTMLElement>;\n }\n | {\n type: 'menuPopoverMouseEnter';\n event: React.MouseEvent<HTMLElement>;\n }\n | {\n type: 'menuPopoverKeyDown';\n event: React.KeyboardEvent<HTMLElement>;\n }\n | {\n type: 'clickOutside';\n event: MouseEvent | TouchEvent;\n }\n | {\n type: 'scrollOutside';\n event: MouseEvent | TouchEvent;\n }\n | {\n type: 'menuMouseEnter';\n event: MouseEvent | TouchEvent;\n }\n);\n"]}
|
@@ -104,7 +104,6 @@ export const useMenu_unstable = props => {
|
|
104
104
|
open,
|
105
105
|
setOpen,
|
106
106
|
checkedValues,
|
107
|
-
defaultCheckedValues,
|
108
107
|
onCheckedValueChange,
|
109
108
|
persistOnItemClick
|
110
109
|
};
|
@@ -114,33 +113,25 @@ export const useMenu_unstable = props => {
|
|
114
113
|
* i.e checkboxes and radios
|
115
114
|
*/
|
116
115
|
|
117
|
-
const useMenuSelectableState =
|
116
|
+
const useMenuSelectableState = props => {
|
118
117
|
const [checkedValues, setCheckedValues] = useControllableState({
|
119
|
-
state:
|
120
|
-
defaultState:
|
118
|
+
state: props.checkedValues,
|
119
|
+
defaultState: props.defaultCheckedValues,
|
121
120
|
initialState: {}
|
122
121
|
});
|
123
|
-
const {
|
124
|
-
onCheckedValueChange: onCheckedValueChangeOriginal
|
125
|
-
} = state;
|
126
122
|
const onCheckedValueChange = useEventCallback((e, {
|
127
123
|
name,
|
128
124
|
checkedItems
|
129
125
|
}) => {
|
130
|
-
|
131
|
-
onCheckedValueChangeOriginal(e, {
|
132
|
-
name,
|
133
|
-
checkedItems
|
134
|
-
});
|
135
|
-
}
|
126
|
+
var _a;
|
136
127
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
} : {
|
141
|
-
[name]: checkedItems
|
142
|
-
};
|
128
|
+
(_a = props.onCheckedValueChange) === null || _a === void 0 ? void 0 : _a.call(props, e, {
|
129
|
+
name,
|
130
|
+
checkedItems
|
143
131
|
});
|
132
|
+
setCheckedValues(currentValue => ({ ...currentValue,
|
133
|
+
[name]: checkedItems
|
134
|
+
}));
|
144
135
|
});
|
145
136
|
return [checkedValues, onCheckedValueChange];
|
146
137
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-menu/src/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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AAhD,GAAqD,qBAAqB,EAA1E;QACD,CAFD,MAEO;UACL,CAAA,EAAA,GAAA,KAAK,CAAC,UAAN,CAAiB,OAAjB,MAAwB,IAAxB,IAAwB,EAAA,KAAA,KAAA,CAAxB,GAAwB,KAAA,CAAxB,GAAwB,EAAA,CAAE,KAAF,EAAxB;QACD;MACF;IACF;;IAED,oBAAoB,CAAC,OAArB,GAA+B,KAA/B;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,IAAD,EAAO,OAAP,CAAP;AACD,CA5JD","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, MenuOpenEvent, 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 shouldHandleCloseRef = 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: MenuOpenEvent, 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 shouldHandleCloseRef.current = true;\n }\n\n if (e.type === 'keydown') {\n if ((e as React.KeyboardEvent<HTMLElement>).key === Tab) {\n shouldHandleTabRef.current = true;\n pressedShiftRef.current = (e as React.KeyboardEvent<HTMLElement>).shiftKey;\n }\n }\n\n if (data.bubble) {\n parentSetOpen(e, { ...data });\n }\n\n setOpenState(data.open);\n });\n\n const setOpen = useEventCallback((e: MenuOpenEvent, 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: event => setOpen(event, { open: false, type: 'clickOutside', event }),\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: event => setOpen(event, { open: false, type: 'scrollOutside', event }),\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: event => {\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(event, { open: false, type: 'menuMouseEnter', event });\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 } else {\n if (shouldHandleCloseRef.current) {\n if (shouldHandleTabRef.current && !state.isSubmenu) {\n pressedShiftRef.current ? focusBeforeMenuTrigger() : focusAfterMenuTrigger();\n } else {\n state.triggerRef.current?.focus();\n }\n }\n }\n\n shouldHandleCloseRef.current = false;\n shouldHandleTabRef.current = false;\n pressedShiftRef.current = false;\n }, [state.triggerRef, state.isSubmenu, open, focusFirst, focusAfterMenuTrigger, focusBeforeMenuTrigger]);\n\n return [open, setOpen] as const;\n};\n"],"sourceRoot":"../src/"}
|
1
|
+
{"version":3,"sources":["packages/react-components/react-menu/src/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,4BAAx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,OAAjB,MAAwB,IAAxB,IAAwB,EAAA,KAAA,KAAA,CAAxB,GAAwB,KAAA,CAAxB,GAAwB,EAAA,CAAE,KAAF,EAAxB;QACD;MACF;IACF;;IAED,oBAAoB,CAAC,OAArB,GAA+B,KAA/B;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,IAAD,EAAO,OAAP,CAAP;AACD,CA3JD","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, MenuOpenEvent, 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' : 'below',\n align: isSubmenu ? 'top' : 'start',\n target: props.openOnContext ? contextTarget : undefined,\n ...resolvePositioningShorthand(props.positioning),\n } as const;\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\n const { targetRef: triggerRef, containerRef: menuPopoverRef } = usePositioning(positioningState);\n\n // TODO Better way to narrow types ?\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 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 props: Pick<MenuProps, 'checkedValues' | 'defaultCheckedValues' | 'onCheckedValueChange'>,\n) => {\n const [checkedValues, setCheckedValues] = useControllableState({\n state: props.checkedValues,\n defaultState: props.defaultCheckedValues,\n initialState: {},\n });\n const onCheckedValueChange: MenuState['onCheckedValueChange'] = useEventCallback((e, { name, checkedItems }) => {\n props.onCheckedValueChange?.(e, { name, checkedItems });\n\n setCheckedValues(currentValue => ({\n ...currentValue,\n [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 | 'setContextTarget'\n | 'triggerRef'\n | 'openOnContext'\n | 'closeOnScroll'\n | 'hoverDelay'\n > &\n Pick<MenuProps, 'open' | 'defaultOpen' | 'onOpenChange'>,\n) => {\n const { targetDocument } = useFluent();\n const parentSetOpen = useMenuContext_unstable(context => context.setOpen);\n const onOpenChange: MenuProps['onOpenChange'] = useEventCallback((e, data) => state.onOpenChange?.(e, data));\n\n const shouldHandleCloseRef = 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: MenuOpenEvent, 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 shouldHandleCloseRef.current = true;\n }\n\n if (e.type === 'keydown') {\n if ((e as React.KeyboardEvent<HTMLElement>).key === Tab) {\n shouldHandleTabRef.current = true;\n pressedShiftRef.current = (e as React.KeyboardEvent<HTMLElement>).shiftKey;\n }\n }\n\n if (data.bubble) {\n parentSetOpen(e, { ...data });\n }\n\n setOpenState(data.open);\n });\n\n const setOpen = useEventCallback((e: MenuOpenEvent, 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: event => setOpen(event, { open: false, type: 'clickOutside', event }),\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: event => setOpen(event, { open: false, type: 'scrollOutside', event }),\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: event => {\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(event, { open: false, type: 'menuMouseEnter', event });\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 } else {\n if (shouldHandleCloseRef.current) {\n if (shouldHandleTabRef.current && !state.isSubmenu) {\n pressedShiftRef.current ? focusBeforeMenuTrigger() : focusAfterMenuTrigger();\n } else {\n state.triggerRef.current?.focus();\n }\n }\n }\n\n shouldHandleCloseRef.current = false;\n shouldHandleTabRef.current = false;\n pressedShiftRef.current = false;\n }, [state.triggerRef, state.isSubmenu, open, focusFirst, focusAfterMenuTrigger, focusBeforeMenuTrigger]);\n\n return [open, setOpen] as const;\n};\n"],"sourceRoot":"../src/"}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
export function useMenuContextValues_unstable(state) {
|
2
2
|
const {
|
3
3
|
checkedValues,
|
4
|
-
defaultCheckedValues,
|
5
4
|
hasCheckmarks,
|
6
5
|
hasIcons,
|
7
6
|
inline,
|
@@ -19,7 +18,6 @@ export function useMenuContextValues_unstable(state) {
|
|
19
18
|
|
20
19
|
const menu = {
|
21
20
|
checkedValues,
|
22
|
-
defaultCheckedValues,
|
23
21
|
hasCheckmarks,
|
24
22
|
hasIcons,
|
25
23
|
inline,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-menu/src/components/Menu/useMenuContextValues.ts"],"names":[],"mappings":"AAEA,OAAM,SAAU,6BAAV,CAAwC,KAAxC,EAAwD;EAC5D,MAAM;IACJ,aADI;IAEJ,
|
1
|
+
{"version":3,"sources":["packages/react-components/react-menu/src/components/Menu/useMenuContextValues.ts"],"names":[],"mappings":"AAEA,OAAM,SAAU,6BAAV,CAAwC,KAAxC,EAAwD;EAC5D,MAAM;IACJ,aADI;IAEJ,aAFI;IAGJ,QAHI;IAIJ,MAJI;IAKJ,SALI;IAMJ,cANI;IAOJ,oBAPI;IAQJ,IARI;IASJ,aATI;IAUJ,WAVI;IAWJ,kBAXI;IAYJ,OAZI;IAaJ,SAbI;IAcJ;EAdI,IAeF,KAfJ,CAD4D,CAkB5D;;EACA,MAAM,IAAI,GAAG;IACX,aADW;IAEX,aAFW;IAGX,QAHW;IAIX,MAJW;IAKX,SALW;IAMX,cANW;IAOX,oBAPW;IAQX,IARW;IASX,aATW;IAUX,WAVW;IAWX,kBAXW;IAYX,OAZW;IAaX,SAbW;IAcX;EAdW,CAAb;EAiBA,OAAO;IAAE;EAAF,CAAP;AACD","sourcesContent":["import type { MenuContextValues, MenuState } from './Menu.types';\n\nexport function useMenuContextValues_unstable(state: MenuState): MenuContextValues {\n const {\n checkedValues,\n hasCheckmarks,\n hasIcons,\n inline,\n isSubmenu,\n menuPopoverRef,\n onCheckedValueChange,\n open,\n openOnContext,\n openOnHover,\n persistOnItemClick,\n setOpen,\n triggerId,\n triggerRef,\n } = state;\n\n // This context is created with \"@fluentui/react-context-selector\", these is no sense to memoize it\n const menu = {\n checkedValues,\n hasCheckmarks,\n hasIcons,\n inline,\n isSubmenu,\n menuPopoverRef,\n onCheckedValueChange,\n open,\n openOnContext,\n openOnHover,\n persistOnItemClick,\n setOpen,\n triggerId,\n triggerRef,\n };\n\n return { menu };\n}\n"],"sourceRoot":"../src/"}
|
@@ -11,12 +11,12 @@ const useStyles = /*#__PURE__*/__styles({
|
|
11
11
|
"jrapky": "fd1gkq",
|
12
12
|
"Frg6f3": ["f1q7jvqi", "f1rnx978"],
|
13
13
|
"a9b677": "f14z66ap",
|
14
|
-
"Bn0qgzm": "
|
14
|
+
"Bn0qgzm": "f1vxd6vx",
|
15
15
|
"oivjwe": "fg706s2",
|
16
16
|
"B9xav0g": "frpde29"
|
17
17
|
}
|
18
18
|
}, {
|
19
|
-
"d": [".fvjh0tl{margin-top:4px;}", ".f1rnx978{margin-right:-5px;}", ".f1q7jvqi{margin-left:-5px;}", ".fd1gkq{margin-bottom:4px;}", ".f14z66ap{width:auto;}", ".
|
19
|
+
"d": [".fvjh0tl{margin-top:4px;}", ".f1rnx978{margin-right:-5px;}", ".f1q7jvqi{margin-left:-5px;}", ".fd1gkq{margin-bottom:4px;}", ".f14z66ap{width:auto;}", ".f1vxd6vx{border-bottom-width:var(--strokeWidthThin);}", ".fg706s2{border-bottom-style:solid;}", ".frpde29{border-bottom-color:var(--colorNeutralStroke2);}"]
|
20
20
|
});
|
21
21
|
|
22
22
|
export const useMenuDividerStyles_unstable = state => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-menu/src/components/MenuDivider/useMenuDividerStyles.ts"],"names":[],"mappings":"AAAA,SAAS,UAAT,EAAqB,YAArB,kBAAqD,gBAArD;AACA,SAAS,MAAT,QAAuB,uBAAvB;AAIA,OAAO,MAAM,qBAAqB,GAAqC;EACrE,IAAI,EAAE;AAD+D,CAAhE;;AAIP,MAAM,SAAS,gBAAG;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;AAAA;EAAA;AAAA,EAAlB;;AAQA,OAAO,MAAM,6BAA6B,GAAI,KAAD,IAA4B;EACvE,MAAM,MAAM,GAAG,SAAS,EAAxB;EACA,KAAK,CAAC,IAAN,CAAW,SAAX,GAAuB,YAAY,CAAC,qBAAqB,CAAC,IAAvB,EAA6B,MAAM,CAAC,IAApC,EAA0C,KAAK,CAAC,IAAN,CAAW,SAArD,CAAnC;EAEA,OAAO,KAAP;AACD,CALM","sourcesContent":["import { shorthands, mergeClasses, makeStyles } from '@griffel/react';\nimport { tokens } from '@fluentui/react-theme';\nimport type { MenuDividerSlots, MenuDividerState } from './MenuDivider.types';\nimport type { SlotClassNames } from '@fluentui/react-utilities';\n\nexport const menuDividerClassNames: SlotClassNames<MenuDividerSlots> = {\n root: 'fui-MenuDivider',\n};\n\nconst useStyles = makeStyles({\n root: {\n ...shorthands.margin('4px', '-5px', '4px', '-5px'),\n width: 'auto',\n ...shorthands.borderBottom(
|
1
|
+
{"version":3,"sources":["packages/react-components/react-menu/src/components/MenuDivider/useMenuDividerStyles.ts"],"names":[],"mappings":"AAAA,SAAS,UAAT,EAAqB,YAArB,kBAAqD,gBAArD;AACA,SAAS,MAAT,QAAuB,uBAAvB;AAIA,OAAO,MAAM,qBAAqB,GAAqC;EACrE,IAAI,EAAE;AAD+D,CAAhE;;AAIP,MAAM,SAAS,gBAAG;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;AAAA;EAAA;AAAA,EAAlB;;AAQA,OAAO,MAAM,6BAA6B,GAAI,KAAD,IAA4B;EACvE,MAAM,MAAM,GAAG,SAAS,EAAxB;EACA,KAAK,CAAC,IAAN,CAAW,SAAX,GAAuB,YAAY,CAAC,qBAAqB,CAAC,IAAvB,EAA6B,MAAM,CAAC,IAApC,EAA0C,KAAK,CAAC,IAAN,CAAW,SAArD,CAAnC;EAEA,OAAO,KAAP;AACD,CALM","sourcesContent":["import { shorthands, mergeClasses, makeStyles } from '@griffel/react';\nimport { tokens } from '@fluentui/react-theme';\nimport type { MenuDividerSlots, MenuDividerState } from './MenuDivider.types';\nimport type { SlotClassNames } from '@fluentui/react-utilities';\n\nexport const menuDividerClassNames: SlotClassNames<MenuDividerSlots> = {\n root: 'fui-MenuDivider',\n};\n\nconst useStyles = makeStyles({\n root: {\n ...shorthands.margin('4px', '-5px', '4px', '-5px'),\n width: 'auto',\n ...shorthands.borderBottom(tokens.strokeWidthThin, 'solid', tokens.colorNeutralStroke2),\n },\n});\n\nexport const useMenuDividerStyles_unstable = (state: MenuDividerState) => {\n const styles = useStyles();\n state.root.className = mergeClasses(menuDividerClassNames.root, styles.root, state.root.className);\n\n return state;\n};\n"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-menu/src/components/MenuGroup/useMenuGroup.ts"],"names":[],"mappings":"AACA,SAAS,qBAAT,EAAgC,KAAhC,QAA6C,2BAA7C;AAGA;;AAEG;;AACH,OAAM,SAAU,qBAAV,CAAgC,KAAhC,EAAuD,GAAvD,EAAkF;EACtF,MAAM,QAAQ,GAAG,KAAK,CAAC,YAAD,CAAtB;EAEA,OAAO;IACL,UAAU,EAAE;MACV,IAAI,EAAE;IADI,CADP;IAIL,IAAI,EAAE,qBAAqB,CAAC,KAAD,EAAQ;MACjC,GADiC;MAEjC,mBAAmB,QAFc;MAGjC,IAAI,EAAE,OAH2B;MAIjC,GAAG;IAJ8B,CAAR,CAJtB;IAUL
|
1
|
+
{"version":3,"sources":["packages/react-components/react-menu/src/components/MenuGroup/useMenuGroup.ts"],"names":[],"mappings":"AACA,SAAS,qBAAT,EAAgC,KAAhC,QAA6C,2BAA7C;AAGA;;AAEG;;AACH,OAAM,SAAU,qBAAV,CAAgC,KAAhC,EAAuD,GAAvD,EAAkF;EACtF,MAAM,QAAQ,GAAG,KAAK,CAAC,YAAD,CAAtB;EAEA,OAAO;IACL,UAAU,EAAE;MACV,IAAI,EAAE;IADI,CADP;IAIL,IAAI,EAAE,qBAAqB,CAAC,KAAD,EAAQ;MACjC,GADiC;MAEjC,mBAAmB,QAFc;MAGjC,IAAI,EAAE,OAH2B;MAIjC,GAAG;IAJ8B,CAAR,CAJtB;IAUL;EAVK,CAAP;AAYD","sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, useId } from '@fluentui/react-utilities';\nimport { MenuGroupProps, MenuGroupState } from './MenuGroup.types';\n\n/**\n * Given user props, returns state and render function for a MenuGroup.\n */\nexport function useMenuGroup_unstable(props: MenuGroupProps, ref: React.Ref<HTMLElement>): MenuGroupState {\n const headerId = useId('menu-group');\n\n return {\n components: {\n root: 'div',\n },\n root: getNativeElementProps('div', {\n ref,\n 'aria-labelledby': headerId,\n role: 'group',\n ...props,\n }),\n headerId,\n };\n}\n"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"MenuList.types.js","sourceRoot":"../src/","sources":["packages/react-components/react-menu/src/components/MenuList/MenuList.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport type { MenuListContextValue } from '../../contexts/menuListContext';\nimport type { SelectableHandler } from '../../selectable/index';\n\nexport type MenuCheckedValueChangeEvent = React.MouseEvent | React.KeyboardEvent;\n\nexport type MenuCheckedValueChangeData = {\n /** The items for this value that are checked */\n checkedItems: string[];\n /** The name of the value */\n name: string;\n};\n\nexport type MenuListSlots = {\n root: Slot<'div'>;\n};\n\nexport type MenuListProps = ComponentProps<MenuListSlots> & {\n /**\n * Map of all checked values\n */\n checkedValues?: Record<string, string[]>;\n\n /**\n * Default values to be checked on mount\n */\n defaultCheckedValues?: Record<string, string[]>;\n\n /**\n * States that menu items can contain selectable items and reserve slots for item alignment\n */\n hasCheckmarks?: boolean;\n\n /**\n * States that menu items can contain icons and reserve slots for item alignment\n */\n hasIcons?: boolean;\n\n /**\n * Callback when checked items change for value with a name\n *\n * @param event - React's original SyntheticEvent\n * @param data - A data object with relevant information\n */\n onCheckedValueChange?: (e: MenuCheckedValueChangeEvent, data: MenuCheckedValueChangeData) => void;\n};\n\nexport type MenuListState = ComponentState<MenuListSlots> &\n
|
1
|
+
{"version":3,"file":"MenuList.types.js","sourceRoot":"../src/","sources":["packages/react-components/react-menu/src/components/MenuList/MenuList.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport type { MenuListContextValue } from '../../contexts/menuListContext';\nimport type { SelectableHandler } from '../../selectable/index';\n\nexport type MenuCheckedValueChangeEvent = React.MouseEvent | React.KeyboardEvent;\n\nexport type MenuCheckedValueChangeData = {\n /** The items for this value that are checked */\n checkedItems: string[];\n /** The name of the value */\n name: string;\n};\n\nexport type MenuListSlots = {\n root: Slot<'div'>;\n};\n\nexport type MenuListProps = ComponentProps<MenuListSlots> & {\n /**\n * Map of all checked values\n */\n checkedValues?: Record<string, string[]>;\n\n /**\n * Default values to be checked on mount\n */\n defaultCheckedValues?: Record<string, string[]>;\n\n /**\n * States that menu items can contain selectable items and reserve slots for item alignment\n */\n hasCheckmarks?: boolean;\n\n /**\n * States that menu items can contain icons and reserve slots for item alignment\n */\n hasIcons?: boolean;\n\n /**\n * Callback when checked items change for value with a name\n *\n * @param event - React's original SyntheticEvent\n * @param data - A data object with relevant information\n */\n onCheckedValueChange?: (e: MenuCheckedValueChangeEvent, data: MenuCheckedValueChangeData) => void;\n};\n\nexport type MenuListState = ComponentState<MenuListSlots> &\n Required<Pick<MenuListProps, 'checkedValues' | 'hasCheckmarks' | 'hasIcons'>> & {\n /**\n * Selects a radio item, will de-select the currently selected ratio item\n */\n selectRadio: SelectableHandler;\n\n /**\n * Callback to set focus on the next menu item by first character\n */\n setFocusByFirstCharacter: NonNullable<MenuListContextValue['setFocusByFirstCharacter']>;\n\n /*\n * Toggles the state of a checkbox item\n */\n toggleCheckbox: SelectableHandler;\n\n /**\n * Default values to be checked on mount\n * @deprecated this property is not used internally anymore,\n * the signature remains just to avoid breaking changes\n */\n defaultCheckedValues?: Record<string, string[]>;\n /**\n * Callback when checked items change for value with a name\n *\n * @param event - React's original SyntheticEvent\n * @param data - A data object with relevant information\n * @deprecated this property is not used internally anymore,\n * the signature remains just to avoid breaking changes\n */\n onCheckedValueChange?: (e: MenuCheckedValueChangeEvent, data: MenuCheckedValueChangeData) => void;\n };\n\nexport type MenuListContextValues = {\n menuList: MenuListContextValue;\n};\n\n/**\n * @deprecated this type is not being used internally anymore\n */\nexport type UninitializedMenuListState = Omit<\n MenuListState,\n 'checkedValues' | 'selectRadio' | 'setFocusByFirstCharacter' | 'toggleCheckbox'\n> &\n Partial<Pick<MenuListState, 'checkedValues'>>;\n"]}
|
@@ -28,22 +28,6 @@ export const useMenuList_unstable = (props, ref) => {
|
|
28
28
|
}
|
29
29
|
|
30
30
|
const innerRef = React.useRef(null);
|
31
|
-
const initialState = {
|
32
|
-
components: {
|
33
|
-
root: 'div'
|
34
|
-
},
|
35
|
-
root: getNativeElementProps('div', {
|
36
|
-
ref: useMergedRefs(ref, innerRef),
|
37
|
-
role: 'menu',
|
38
|
-
'aria-labelledby': menuContext.triggerId,
|
39
|
-
...focusAttributes,
|
40
|
-
...props
|
41
|
-
}),
|
42
|
-
hasIcons: menuContext.hasIcons || false,
|
43
|
-
hasCheckmarks: menuContext.hasCheckmarks || false,
|
44
|
-
...(hasMenuContext && menuContext),
|
45
|
-
...props
|
46
|
-
};
|
47
31
|
const setFocusByFirstCharacter = React.useCallback((e, itemEl) => {
|
48
32
|
// TODO use some kind of children registration to reduce dependency on DOM roles
|
49
33
|
const acceptedRoles = ['menuitem', 'menuitemcheckbox', 'menuitemradio'];
|
@@ -89,13 +73,11 @@ export const useMenuList_unstable = (props, ref) => {
|
|
89
73
|
}
|
90
74
|
}, [findAllFocusable]);
|
91
75
|
const [checkedValues, setCheckedValues] = useControllableState({
|
92
|
-
state:
|
93
|
-
defaultState:
|
76
|
+
state: hasMenuContext ? menuContext.checkedValues : props.checkedValues,
|
77
|
+
defaultState: props.defaultCheckedValues,
|
94
78
|
initialState: {}
|
95
79
|
});
|
96
|
-
const
|
97
|
-
onCheckedValueChange
|
98
|
-
} = initialState;
|
80
|
+
const handleCheckedValueChange = hasMenuContext ? menuContext.onCheckedValueChange : props.onCheckedValueChange;
|
99
81
|
const toggleCheckbox = useEventCallback((e, name, value, checked) => {
|
100
82
|
const checkedItems = (checkedValues === null || checkedValues === void 0 ? void 0 : checkedValues[name]) || [];
|
101
83
|
const newCheckedItems = [...checkedItems];
|
@@ -106,7 +88,7 @@ export const useMenuList_unstable = (props, ref) => {
|
|
106
88
|
newCheckedItems.push(value);
|
107
89
|
}
|
108
90
|
|
109
|
-
|
91
|
+
handleCheckedValueChange === null || handleCheckedValueChange === void 0 ? void 0 : handleCheckedValueChange(e, {
|
110
92
|
name,
|
111
93
|
checkedItems: newCheckedItems
|
112
94
|
});
|
@@ -119,18 +101,29 @@ export const useMenuList_unstable = (props, ref) => {
|
|
119
101
|
setCheckedValues(s => ({ ...s,
|
120
102
|
[name]: newCheckedItems
|
121
103
|
}));
|
122
|
-
|
104
|
+
handleCheckedValueChange === null || handleCheckedValueChange === void 0 ? void 0 : handleCheckedValueChange(e, {
|
123
105
|
name,
|
124
106
|
checkedItems: newCheckedItems
|
125
107
|
});
|
126
108
|
});
|
127
|
-
|
109
|
+
return {
|
110
|
+
components: {
|
111
|
+
root: 'div'
|
112
|
+
},
|
113
|
+
root: getNativeElementProps('div', {
|
114
|
+
ref: useMergedRefs(ref, innerRef),
|
115
|
+
role: 'menu',
|
116
|
+
'aria-labelledby': menuContext.triggerId,
|
117
|
+
...focusAttributes,
|
118
|
+
...props
|
119
|
+
}),
|
120
|
+
hasIcons: menuContext.hasIcons || false,
|
121
|
+
hasCheckmarks: menuContext.hasCheckmarks || false,
|
122
|
+
checkedValues,
|
128
123
|
setFocusByFirstCharacter,
|
129
124
|
selectRadio,
|
130
|
-
toggleCheckbox
|
131
|
-
checkedValues: checkedValues !== null && checkedValues !== void 0 ? checkedValues : {}
|
125
|
+
toggleCheckbox
|
132
126
|
};
|
133
|
-
return state;
|
134
127
|
};
|
135
128
|
/**
|
136
129
|
* Adds some sugar to fetching multiple context selector values
|
@@ -139,14 +132,12 @@ export const useMenuList_unstable = (props, ref) => {
|
|
139
132
|
const useMenuContextSelectors = () => {
|
140
133
|
const checkedValues = useMenuContext_unstable(context => context.checkedValues);
|
141
134
|
const onCheckedValueChange = useMenuContext_unstable(context => context.onCheckedValueChange);
|
142
|
-
const defaultCheckedValues = useMenuContext_unstable(context => context.defaultCheckedValues);
|
143
135
|
const triggerId = useMenuContext_unstable(context => context.triggerId);
|
144
136
|
const hasIcons = useMenuContext_unstable(context => context.hasIcons);
|
145
137
|
const hasCheckmarks = useMenuContext_unstable(context => context.hasCheckmarks);
|
146
138
|
return {
|
147
139
|
checkedValues,
|
148
140
|
onCheckedValueChange,
|
149
|
-
defaultCheckedValues,
|
150
141
|
triggerId,
|
151
142
|
hasIcons,
|
152
143
|
hasCheckmarks
|