@elliemae/ds-menu-button 3.80.0-next.8 → 3.80.0-next.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/config/useLatestValueReferenciallyStable.js +43 -0
- package/dist/cjs/config/useLatestValueReferenciallyStable.js.map +7 -0
- package/dist/cjs/config/useSideEffectSyntheticEvent.js +44 -0
- package/dist/cjs/config/useSideEffectSyntheticEvent.js.map +7 -0
- package/dist/cjs/config/useSplitInherithedProps.js +19 -2
- package/dist/cjs/config/useSplitInherithedProps.js.map +2 -2
- package/dist/cjs/parts/DSFlyoutMenu/DSFlyoutMenu.js +22 -1
- package/dist/cjs/parts/DSFlyoutMenu/DSFlyoutMenu.js.map +2 -2
- package/dist/cjs/parts/DSMenuBehaviouralContextProvider/DSMenuBehaviouralContextProvider.js +4 -3
- package/dist/cjs/parts/DSMenuBehaviouralContextProvider/DSMenuBehaviouralContextProvider.js.map +2 -2
- package/dist/cjs/parts/DSMenuBehaviouralContextProvider/config/useFocusTracker.js +10 -1
- package/dist/cjs/parts/DSMenuBehaviouralContextProvider/config/useFocusTracker.js.map +2 -2
- package/dist/cjs/parts/DSMenuBehaviouralContextProvider/config/useGlobalEvents.js +4 -3
- package/dist/cjs/parts/DSMenuBehaviouralContextProvider/config/useGlobalEvents.js.map +2 -2
- package/dist/cjs/parts/DSMenuBehaviouralContextProvider/config/useMenuItemEventsHandlers.js +59 -24
- package/dist/cjs/parts/DSMenuBehaviouralContextProvider/config/useMenuItemEventsHandlers.js.map +2 -2
- package/dist/cjs/parts/DSMenuBehaviouralContextProvider/config/useMenuOpenStatus.js +14 -8
- package/dist/cjs/parts/DSMenuBehaviouralContextProvider/config/useMenuOpenStatus.js.map +2 -2
- package/dist/cjs/parts/DSMenuItemRendererFactory/ActivableMenuItem.js +6 -3
- package/dist/cjs/parts/DSMenuItemRendererFactory/ActivableMenuItem.js.map +2 -2
- package/dist/cjs/parts/DSMenuItemRendererFactory/ActivableWithSubmenuMenuItem.js +6 -3
- package/dist/cjs/parts/DSMenuItemRendererFactory/ActivableWithSubmenuMenuItem.js.map +2 -2
- package/dist/cjs/parts/DSMenuItemRendererFactory/MultipleSelectMenuItem.js +8 -5
- package/dist/cjs/parts/DSMenuItemRendererFactory/MultipleSelectMenuItem.js.map +2 -2
- package/dist/cjs/parts/DSMenuItemRendererFactory/MultipleSelectWithSubmenuMenuItem.js +8 -5
- package/dist/cjs/parts/DSMenuItemRendererFactory/MultipleSelectWithSubmenuMenuItem.js.map +2 -2
- package/dist/cjs/parts/DSMenuItemRendererFactory/SingleSelectMenuItem.js +6 -3
- package/dist/cjs/parts/DSMenuItemRendererFactory/SingleSelectMenuItem.js.map +2 -2
- package/dist/cjs/parts/DSMenuItemRendererFactory/SingleSelectWithSubmenuMenuItem.js +6 -3
- package/dist/cjs/parts/DSMenuItemRendererFactory/SingleSelectWithSubmenuMenuItem.js.map +2 -2
- package/dist/cjs/parts/DSMenuItemRendererFactory/SkeletonMenuItem.js +9 -1
- package/dist/cjs/parts/DSMenuItemRendererFactory/SkeletonMenuItem.js.map +2 -2
- package/dist/cjs/parts/DSMenuItemRendererFactory/WithSubmenuMenuItem.js +6 -3
- package/dist/cjs/parts/DSMenuItemRendererFactory/WithSubmenuMenuItem.js.map +2 -2
- package/dist/cjs/parts/DSOpinionatedButton/DSOpinionatedButton.js +9 -2
- package/dist/cjs/parts/DSOpinionatedButton/DSOpinionatedButton.js.map +2 -2
- package/dist/cjs/parts/DSOpinionatedButton/config/useTriggerEventsHandlers.js +58 -21
- package/dist/cjs/parts/DSOpinionatedButton/config/useTriggerEventsHandlers.js.map +2 -2
- package/dist/cjs/react-desc-prop-types.js +18 -2
- package/dist/cjs/react-desc-prop-types.js.map +2 -2
- package/dist/cjs/utils/nodesTypeguardsAndGetters.js +9 -0
- package/dist/cjs/utils/nodesTypeguardsAndGetters.js.map +2 -2
- package/dist/esm/config/useLatestValueReferenciallyStable.js +13 -0
- package/dist/esm/config/useLatestValueReferenciallyStable.js.map +7 -0
- package/dist/esm/config/useSideEffectSyntheticEvent.js +14 -0
- package/dist/esm/config/useSideEffectSyntheticEvent.js.map +7 -0
- package/dist/esm/config/useSplitInherithedProps.js +19 -2
- package/dist/esm/config/useSplitInherithedProps.js.map +2 -2
- package/dist/esm/parts/DSFlyoutMenu/DSFlyoutMenu.js +22 -1
- package/dist/esm/parts/DSFlyoutMenu/DSFlyoutMenu.js.map +2 -2
- package/dist/esm/parts/DSMenuBehaviouralContextProvider/DSMenuBehaviouralContextProvider.js +4 -3
- package/dist/esm/parts/DSMenuBehaviouralContextProvider/DSMenuBehaviouralContextProvider.js.map +2 -2
- package/dist/esm/parts/DSMenuBehaviouralContextProvider/config/useFocusTracker.js +10 -1
- package/dist/esm/parts/DSMenuBehaviouralContextProvider/config/useFocusTracker.js.map +2 -2
- package/dist/esm/parts/DSMenuBehaviouralContextProvider/config/useGlobalEvents.js +4 -3
- package/dist/esm/parts/DSMenuBehaviouralContextProvider/config/useGlobalEvents.js.map +2 -2
- package/dist/esm/parts/DSMenuBehaviouralContextProvider/config/useMenuItemEventsHandlers.js +61 -24
- package/dist/esm/parts/DSMenuBehaviouralContextProvider/config/useMenuItemEventsHandlers.js.map +2 -2
- package/dist/esm/parts/DSMenuBehaviouralContextProvider/config/useMenuOpenStatus.js +14 -8
- package/dist/esm/parts/DSMenuBehaviouralContextProvider/config/useMenuOpenStatus.js.map +2 -2
- package/dist/esm/parts/DSMenuItemRendererFactory/ActivableMenuItem.js +6 -3
- package/dist/esm/parts/DSMenuItemRendererFactory/ActivableMenuItem.js.map +2 -2
- package/dist/esm/parts/DSMenuItemRendererFactory/ActivableWithSubmenuMenuItem.js +6 -3
- package/dist/esm/parts/DSMenuItemRendererFactory/ActivableWithSubmenuMenuItem.js.map +2 -2
- package/dist/esm/parts/DSMenuItemRendererFactory/MultipleSelectMenuItem.js +8 -5
- package/dist/esm/parts/DSMenuItemRendererFactory/MultipleSelectMenuItem.js.map +2 -2
- package/dist/esm/parts/DSMenuItemRendererFactory/MultipleSelectWithSubmenuMenuItem.js +8 -5
- package/dist/esm/parts/DSMenuItemRendererFactory/MultipleSelectWithSubmenuMenuItem.js.map +2 -2
- package/dist/esm/parts/DSMenuItemRendererFactory/SingleSelectMenuItem.js +6 -3
- package/dist/esm/parts/DSMenuItemRendererFactory/SingleSelectMenuItem.js.map +2 -2
- package/dist/esm/parts/DSMenuItemRendererFactory/SingleSelectWithSubmenuMenuItem.js +6 -3
- package/dist/esm/parts/DSMenuItemRendererFactory/SingleSelectWithSubmenuMenuItem.js.map +2 -2
- package/dist/esm/parts/DSMenuItemRendererFactory/SkeletonMenuItem.js +9 -1
- package/dist/esm/parts/DSMenuItemRendererFactory/SkeletonMenuItem.js.map +2 -2
- package/dist/esm/parts/DSMenuItemRendererFactory/WithSubmenuMenuItem.js +6 -3
- package/dist/esm/parts/DSMenuItemRendererFactory/WithSubmenuMenuItem.js.map +2 -2
- package/dist/esm/parts/DSOpinionatedButton/DSOpinionatedButton.js +9 -2
- package/dist/esm/parts/DSOpinionatedButton/DSOpinionatedButton.js.map +2 -2
- package/dist/esm/parts/DSOpinionatedButton/config/useTriggerEventsHandlers.js +58 -21
- package/dist/esm/parts/DSOpinionatedButton/config/useTriggerEventsHandlers.js.map +2 -2
- package/dist/esm/react-desc-prop-types.js +18 -2
- package/dist/esm/react-desc-prop-types.js.map +2 -2
- package/dist/esm/utils/nodesTypeguardsAndGetters.js +9 -0
- package/dist/esm/utils/nodesTypeguardsAndGetters.js.map +2 -2
- package/dist/types/config/useLatestValueReferenciallyStable.d.ts +4 -0
- package/dist/types/config/useSideEffectSyntheticEvent.d.ts +9 -0
- package/dist/types/config/useSplitInherithedProps.d.ts +7 -3
- package/dist/types/parts/DSMenuBehaviouralContextProvider/config/useFocusTracker.d.ts +4 -1
- package/dist/types/parts/DSMenuBehaviouralContextProvider/config/useMenuItemEventsHandlers.d.ts +1 -0
- package/dist/types/parts/DSMenuBehaviouralContextProvider/config/useMenuOpenStatus.d.ts +12 -4
- package/dist/types/parts/DSMenuItemRendererFactory/focusNodeRacingConditionSolved.d.ts +1 -1
- package/dist/types/parts/DSOpinionatedButton/config/useOpinionatedButton.d.ts +2 -1
- package/dist/types/parts/DSOpinionatedButton/config/useTriggerEventsHandlers.d.ts +1 -0
- package/dist/types/react-desc-prop-types.d.ts +64 -2
- package/dist/types/utils/nodesTypeguardsAndGetters.d.ts +21 -0
- package/package.json +14 -13
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/parts/DSMenuItemRendererFactory/SkeletonMenuItem.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-lines */\nimport { StyledContentWrapper, StyledGlobalMenuItemWrapper } from '@elliemae/ds-menu-items-commons';\nimport { DSSkeleton } from '@elliemae/ds-skeleton';\nimport React from 'react';\nimport type { DSMenuButtonT } from '../../react-desc-prop-types.js';\nimport { MenuBehaviouralContextProviderContext } from '../DSMenuBehaviouralContextProvider/MenuBehaviouralContextProviderCTX.js';\nimport { MENU_FOCUS_REGIONS } from '../DSMenuBehaviouralContextProvider/constants/index.js';\nimport { focusNodeRacingConditionSolved } from './focusNodeRacingConditionSolved.js';\nimport { MenuButtonContextProvider } from '../../MenuButtonContextProviderCTX.js';\nconst firstBoxWidth = '16px';\nconst gridLayout = [firstBoxWidth, '1fr'];\nexport const SkeletonMenuItem: React.ComponentType<{\n itemNode: DSMenuButtonT.MenuNodeSkeletonItem;\n ariaPosInSet?: number;\n ariaSetSize?: number;\n}> = ({ itemNode, ariaPosInSet, ariaSetSize }) => {\n const { dsId, plainItem } = itemNode;\n const { minWidth } = plainItem;\n\n const {\n focusRegion,\n menuItemEventsHandlers: {\n handleFocusableMenuItemKeyDown,\n handleFocusableMenuItemOnMouseEnter,\n handleFocusableMenuItemNativeFocusEvent,\n },\n } = React.useContext(MenuBehaviouralContextProviderContext);\n\n const focusedRegionPerformanceHelper = React.useRef(focusRegion);\n focusedRegionPerformanceHelper.current = focusRegion;\n\n const isFocused = focusRegion === MENU_FOCUS_REGIONS.ITEM_BY_DSID(dsId);\n\n const {\n ownerProps: { getOwnerProps },\n } = React.useContext(MenuButtonContextProvider);\n\n const getOwnerPropsArguments = React.useCallback(() => plainItem, [plainItem]);\n\n const handleFocusOnRender = React.useCallback(\n (node: HTMLDivElement) => {\n if (node && focusRegion === MENU_FOCUS_REGIONS.ITEM_BY_DSID(dsId)) {\n focusNodeRacingConditionSolved(node);\n }\n },\n // we need to change the callback reference every time the focusRegion changes or else the focus will not be set\n [dsId, focusRegion],\n // we are using the \"as='div'\", typescript is not able to infer the correct type\n // the logic here actually receives a ref to a HTMLDivElement,\n // but the component must think this is a HTMLLIElement ref callback\n ) as unknown as React.RefCallback<HTMLLIElement>;\n const handleOnMouseEnter = React.useCallback<React.MouseEventHandler<HTMLDivElement>>(() => {\n handleFocusableMenuItemOnMouseEnter(itemNode);\n }, [handleFocusableMenuItemOnMouseEnter, itemNode]);\n const handleOnFocus = React.useCallback<React.FocusEventHandler<HTMLDivElement>>(\n (e) => {\n handleFocusableMenuItemNativeFocusEvent(itemNode, e);\n },\n [handleFocusableMenuItemNativeFocusEvent, itemNode],\n );\n\n const spacelessDsIdForDom = `ds-menu-item-${`${dsId}`.replace(/\\s/g, '')}`;\n\n const firstBoxAndGutterWidth = 16 + 8;\n const secondBoxWidth = minWidth\n ? `calc(${minWidth} - ${firstBoxAndGutterWidth})`\n : `${150 - firstBoxAndGutterWidth}px`;\n return (\n <StyledGlobalMenuItemWrapper\n innerRef={handleFocusOnRender}\n onKeyDown={
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-lines */\nimport { isActivationKey } from '@elliemae/ds-props-helpers';\nimport { StyledContentWrapper, StyledGlobalMenuItemWrapper } from '@elliemae/ds-menu-items-commons';\nimport { DSSkeleton } from '@elliemae/ds-skeleton';\nimport React from 'react';\nimport type { DSMenuButtonT } from '../../react-desc-prop-types.js';\nimport { MenuBehaviouralContextProviderContext } from '../DSMenuBehaviouralContextProvider/MenuBehaviouralContextProviderCTX.js';\nimport { MENU_FOCUS_REGIONS } from '../DSMenuBehaviouralContextProvider/constants/index.js';\nimport { focusNodeRacingConditionSolved } from './focusNodeRacingConditionSolved.js';\nimport { MenuButtonContextProvider } from '../../MenuButtonContextProviderCTX.js';\nconst firstBoxWidth = '16px';\nconst gridLayout = [firstBoxWidth, '1fr'];\nexport const SkeletonMenuItem: React.ComponentType<{\n itemNode: DSMenuButtonT.MenuNodeSkeletonItem;\n ariaPosInSet?: number;\n ariaSetSize?: number;\n}> = ({ itemNode, ariaPosInSet, ariaSetSize }) => {\n const { dsId, plainItem } = itemNode;\n const { minWidth } = plainItem;\n\n const {\n focusRegion,\n menuItemEventsHandlers: {\n handleFocusableMenuItemKeyDown,\n handleFocusableMenuItemOnMouseEnter,\n handleFocusableMenuItemNativeFocusEvent,\n },\n } = React.useContext(MenuBehaviouralContextProviderContext);\n\n const focusedRegionPerformanceHelper = React.useRef(focusRegion);\n focusedRegionPerformanceHelper.current = focusRegion;\n\n const isFocused = focusRegion === MENU_FOCUS_REGIONS.ITEM_BY_DSID(dsId);\n\n const {\n ownerProps: { getOwnerProps },\n } = React.useContext(MenuButtonContextProvider);\n\n const getOwnerPropsArguments = React.useCallback(() => plainItem, [plainItem]);\n\n const handleFocusOnRender = React.useCallback(\n (node: HTMLDivElement) => {\n if (node && focusRegion === MENU_FOCUS_REGIONS.ITEM_BY_DSID(dsId)) {\n focusNodeRacingConditionSolved(node);\n }\n },\n // we need to change the callback reference every time the focusRegion changes or else the focus will not be set\n [dsId, focusRegion],\n // we are using the \"as='div'\", typescript is not able to infer the correct type\n // the logic here actually receives a ref to a HTMLDivElement,\n // but the component must think this is a HTMLLIElement ref callback\n ) as unknown as React.RefCallback<HTMLLIElement>;\n // a skeleton is a loading placeholder with nothing to activate: Enter and Space are not handled on it\n // (otherwise they would activate the placeholder through onActivateItem)\n const handleSkeletonKeyDown = React.useCallback<React.KeyboardEventHandler<HTMLDivElement>>(\n (event) => {\n if (isActivationKey(event)) return;\n handleFocusableMenuItemKeyDown(event);\n },\n [handleFocusableMenuItemKeyDown],\n );\n const handleOnMouseEnter = React.useCallback<React.MouseEventHandler<HTMLDivElement>>(() => {\n handleFocusableMenuItemOnMouseEnter(itemNode);\n }, [handleFocusableMenuItemOnMouseEnter, itemNode]);\n const handleOnFocus = React.useCallback<React.FocusEventHandler<HTMLDivElement>>(\n (e) => {\n handleFocusableMenuItemNativeFocusEvent(itemNode, e);\n },\n [handleFocusableMenuItemNativeFocusEvent, itemNode],\n );\n\n const spacelessDsIdForDom = `ds-menu-item-${`${dsId}`.replace(/\\s/g, '')}`;\n\n const firstBoxAndGutterWidth = 16 + 8;\n const secondBoxWidth = minWidth\n ? `calc(${minWidth} - ${firstBoxAndGutterWidth})`\n : `${150 - firstBoxAndGutterWidth}px`;\n return (\n <StyledGlobalMenuItemWrapper\n innerRef={handleFocusOnRender}\n onKeyDown={handleSkeletonKeyDown}\n onMouseEnter={handleOnMouseEnter}\n onFocus={handleOnFocus}\n as=\"div\"\n id={`${spacelessDsIdForDom}`}\n role=\"menuitem\"\n aria-label=\"Loading\"\n aria-posinset={ariaPosInSet}\n aria-setsize={ariaSetSize}\n tabIndex={isFocused ? 0 : -1}\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n >\n <StyledContentWrapper\n cols={gridLayout}\n minHeight=\"16px\"\n gutter=\"xxs\"\n alignItems=\"center\"\n minWidth={minWidth ?? '150px'}\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n >\n <DSSkeleton variant=\"rectangular\" width={firstBoxWidth} height=\"16px\" bg=\"neutral-080\" borderRadius=\"1px\" />\n <DSSkeleton variant=\"rectangular\" width={secondBoxWidth} height=\"16px\" bg=\"neutral-080\" borderRadius=\"1px\" />\n </StyledContentWrapper>\n </StyledGlobalMenuItemWrapper>\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;AC6FjB,SASE,KATF;AA5FN,SAAS,uBAAuB;AAChC,SAAS,sBAAsB,mCAAmC;AAClE,SAAS,kBAAkB;AAC3B,OAAOA,YAAW;AAElB,SAAS,6CAA6C;AACtD,SAAS,0BAA0B;AACnC,SAAS,sCAAsC;AAC/C,SAAS,iCAAiC;AAC1C,MAAM,gBAAgB;AACtB,MAAM,aAAa,CAAC,eAAe,KAAK;AACjC,MAAM,mBAIR,CAAC,EAAE,UAAU,cAAc,YAAY,MAAM;AAChD,QAAM,EAAE,MAAM,UAAU,IAAI;AAC5B,QAAM,EAAE,SAAS,IAAI;AAErB,QAAM;AAAA,IACJ;AAAA,IACA,wBAAwB;AAAA,MACtB;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,IAAIA,OAAM,WAAW,qCAAqC;AAE1D,QAAM,iCAAiCA,OAAM,OAAO,WAAW;AAC/D,iCAA+B,UAAU;AAEzC,QAAM,YAAY,gBAAgB,mBAAmB,aAAa,IAAI;AAEtE,QAAM;AAAA,IACJ,YAAY,EAAE,cAAc;AAAA,EAC9B,IAAIA,OAAM,WAAW,yBAAyB;AAE9C,QAAM,yBAAyBA,OAAM,YAAY,MAAM,WAAW,CAAC,SAAS,CAAC;AAE7E,QAAM,sBAAsBA,OAAM;AAAA,IAChC,CAAC,SAAyB;AACxB,UAAI,QAAQ,gBAAgB,mBAAmB,aAAa,IAAI,GAAG;AACjE,uCAA+B,IAAI;AAAA,MACrC;AAAA,IACF;AAAA;AAAA,IAEA,CAAC,MAAM,WAAW;AAAA;AAAA;AAAA;AAAA,EAIpB;AAGA,QAAM,wBAAwBA,OAAM;AAAA,IAClC,CAAC,UAAU;AACT,UAAI,gBAAgB,KAAK,EAAG;AAC5B,qCAA+B,KAAK;A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
13
13
|
import { MENU_FOCUS_REGIONS } from "../DSMenuBehaviouralContextProvider/constants/index.js";
|
|
14
14
|
import { focusNodeRacingConditionSolved } from "./focusNodeRacingConditionSolved.js";
|
|
15
15
|
import { MenuButtonContextProvider } from "../../MenuButtonContextProviderCTX.js";
|
|
16
|
+
import { isItemLocked } from "../../utils/nodesTypeguardsAndGetters.js";
|
|
16
17
|
const placementOrderPreference = [
|
|
17
18
|
"right-start",
|
|
18
19
|
"right-start",
|
|
@@ -24,6 +25,7 @@ const placementOrderPreference = [
|
|
|
24
25
|
const WithSubmenuMenuItem = ({ itemNode, FlyoutMenuCircularDepInject, ariaPosInSet, ariaSetSize }) => {
|
|
25
26
|
const { dsId, plainItem } = itemNode;
|
|
26
27
|
const { label, secondaryLabel, leftDecoration: LeftDecComponent, minWidth, disabled } = plainItem;
|
|
28
|
+
const locked = isItemLocked(plainItem);
|
|
27
29
|
const {
|
|
28
30
|
ownerProps: { getOwnerProps }
|
|
29
31
|
} = React2.useContext(MenuButtonContextProvider);
|
|
@@ -106,10 +108,11 @@ const WithSubmenuMenuItem = ({ itemNode, FlyoutMenuCircularDepInject, ariaPosInS
|
|
|
106
108
|
* ******************************************************************************************************************** */
|
|
107
109
|
isExpanded ? itemNode.plainChildren.map((child) => `ds-menu-item-${`${child.dsId}`.replace(/\s/g, "")}`).join(" ") : void 0
|
|
108
110
|
),
|
|
109
|
-
"aria-disabled":
|
|
111
|
+
"aria-disabled": locked ? true : void 0,
|
|
110
112
|
"aria-posinset": ariaPosInSet,
|
|
111
113
|
"aria-setsize": ariaSetSize,
|
|
112
|
-
applyAriaDisabled:
|
|
114
|
+
applyAriaDisabled: locked,
|
|
115
|
+
$disabled: disabled,
|
|
113
116
|
getOwnerProps,
|
|
114
117
|
getOwnerPropsArguments,
|
|
115
118
|
children: /* @__PURE__ */ jsxs(
|
|
@@ -139,7 +142,7 @@ const WithSubmenuMenuItem = ({ itemNode, FlyoutMenuCircularDepInject, ariaPosInS
|
|
|
139
142
|
{
|
|
140
143
|
getOwnerProps,
|
|
141
144
|
getOwnerPropsArguments,
|
|
142
|
-
disabled,
|
|
145
|
+
$disabled: locked,
|
|
143
146
|
children: secondaryLabel
|
|
144
147
|
}
|
|
145
148
|
),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/parts/DSMenuItemRendererFactory/WithSubmenuMenuItem.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { ChevronSmallRight } from '@elliemae/ds-icons';\nimport {\n StyleMenuItemLabel,\n StyleMenuItemSecondaryLabel,\n StyledContentWrapper,\n StyledGlobalMenuItemWrapper,\n} from '@elliemae/ds-menu-items-commons';\nimport { useFloatingContext, type DSHookFloatingContextT } from '@elliemae/ds-floating-context';\nimport React from 'react';\nimport type { DSMenuButtonT } from '../../react-desc-prop-types.js';\nimport { MenuBehaviouralContextProviderContext } from '../DSMenuBehaviouralContextProvider/MenuBehaviouralContextProviderCTX.js';\nimport { MENU_FOCUS_REGIONS } from '../DSMenuBehaviouralContextProvider/constants/index.js';\nimport { type DSMenuItemRendererFactoryT } from './react-desc-prop-types.js';\nimport { focusNodeRacingConditionSolved } from './focusNodeRacingConditionSolved.js';\nimport { MenuButtonContextProvider } from '../../MenuButtonContextProviderCTX.js';\nconst placementOrderPreference: Required<DSHookFloatingContextT.Props>['placementOrderPreference'] = [\n 'right-start',\n 'right-start',\n 'right',\n 'left-start',\n 'left-end',\n 'left',\n];\nexport const WithSubmenuMenuItem: React.ComponentType<{\n itemNode: DSMenuButtonT.MenuNodeWithSubmenuItem;\n FlyoutMenuCircularDepInject: DSMenuItemRendererFactoryT.RequiredProps['FlyoutMenuCircularDepInject'];\n ariaPosInSet?: number;\n ariaSetSize?: number;\n}> = ({ itemNode, FlyoutMenuCircularDepInject, ariaPosInSet, ariaSetSize }) => {\n const { dsId, plainItem } = itemNode;\n const { label, secondaryLabel, leftDecoration: LeftDecComponent, minWidth, disabled } = plainItem;\n\n const {\n ownerProps: { getOwnerProps },\n } = React.useContext(MenuButtonContextProvider);\n const getOwnerPropsArguments = React.useCallback(() => plainItem, [plainItem]);\n\n const {\n focusRegion,\n openedSubItems,\n menuItemEventsHandlers: {\n handleFocusableMenuItemKeyDown,\n handleFocusableMenuItemClick,\n handleFocusableMenuItemOnMouseEnter,\n handleFocusableMenuItemNativeFocusEvent,\n },\n } = React.useContext(MenuBehaviouralContextProviderContext);\n\n const gridLayout = React.useMemo(() => {\n const cols = LeftDecComponent ? ['min-content', 'auto'] : ['auto'];\n if (secondaryLabel) cols.push('auto');\n cols.push('min-content');\n return cols;\n }, [LeftDecComponent, secondaryLabel]);\n\n const focusedRegionPerformanceHelper = React.useRef(focusRegion);\n focusedRegionPerformanceHelper.current = focusRegion;\n\n const isFocused = focusRegion === MENU_FOCUS_REGIONS.ITEM_BY_DSID(dsId);\n const isExpanded = openedSubItems.some((itemWithOpenSubmenu) => itemWithOpenSubmenu.dsId === dsId);\n\n const floatingContext = useFloatingContext({\n placement: placementOrderPreference[0],\n placementOrderPreference,\n animationDuration: 100,\n customOffset: [0, 0],\n externallyControlledIsOpen: isExpanded,\n });\n const {\n refs: { setReference },\n } = floatingContext;\n\n const handleFocusOnRender = React.useCallback(\n (node: HTMLDivElement) => {\n setReference(node);\n if (node && focusRegion === MENU_FOCUS_REGIONS.ITEM_BY_DSID(dsId)) {\n focusNodeRacingConditionSolved(node);\n }\n },\n // we need to change the callback reference every time the focusRegion changes or else the focus will not be set\n [dsId, focusRegion, setReference],\n // we are using the \"as='div'\", typescript is not able to infer the correct type\n // the logic here actually receives a ref to a HTMLDivElement,\n // but the component must think this is a HTMLLIElement ref callback\n ) as unknown as React.RefCallback<HTMLLIElement>;\n\n const handleOnMouseEnter = React.useCallback<React.MouseEventHandler<HTMLDivElement>>(() => {\n handleFocusableMenuItemOnMouseEnter(itemNode);\n }, [handleFocusableMenuItemOnMouseEnter, itemNode]);\n const handleOnFocus = React.useCallback<React.FocusEventHandler<HTMLDivElement>>(\n (e) => {\n handleFocusableMenuItemNativeFocusEvent(itemNode, e);\n },\n [handleFocusableMenuItemNativeFocusEvent, itemNode],\n );\n\n const spacelessDsIdForDom = `ds-menu-item-${`${dsId}`.replace(/\\s/g, '')}`;\n return (\n <>\n <StyledGlobalMenuItemWrapper\n innerRef={handleFocusOnRender}\n onKeyDown={handleFocusableMenuItemKeyDown}\n onClick={handleFocusableMenuItemClick}\n onMouseEnter={handleOnMouseEnter}\n onFocus={handleOnFocus}\n as=\"div\"\n id={`${spacelessDsIdForDom}`}\n tabIndex={isFocused ? 0 : -1}\n role=\"menuitem\"\n aria-haspopup=\"menu\"\n aria-expanded={isExpanded}\n aria-controls={\n /* ********************************************************************************************************************\n * https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-controls\n * The aria-controls only needs to be set when the popup is visible, but it is valid and easier to program to reference an element that is not visible.\n * ********************************************************************************************************************\n * ^^^ some automated tools will mark an error if the aria-controls references an element that does (yet) exist in the DOM\n * so, while technically valid to not check if expanded, we are doing it to avoid automated tools marking an error\n * ******************************************************************************************************************** */\n isExpanded\n ? itemNode.plainChildren.map((child) => `ds-menu-item-${`${child.dsId}`.replace(/\\s/g, '')}`).join(' ')\n : undefined\n }\n aria-disabled={
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { ChevronSmallRight } from '@elliemae/ds-icons';\nimport {\n StyleMenuItemLabel,\n StyleMenuItemSecondaryLabel,\n StyledContentWrapper,\n StyledGlobalMenuItemWrapper,\n} from '@elliemae/ds-menu-items-commons';\nimport { useFloatingContext, type DSHookFloatingContextT } from '@elliemae/ds-floating-context';\nimport React from 'react';\nimport type { DSMenuButtonT } from '../../react-desc-prop-types.js';\nimport { MenuBehaviouralContextProviderContext } from '../DSMenuBehaviouralContextProvider/MenuBehaviouralContextProviderCTX.js';\nimport { MENU_FOCUS_REGIONS } from '../DSMenuBehaviouralContextProvider/constants/index.js';\nimport { type DSMenuItemRendererFactoryT } from './react-desc-prop-types.js';\nimport { focusNodeRacingConditionSolved } from './focusNodeRacingConditionSolved.js';\nimport { MenuButtonContextProvider } from '../../MenuButtonContextProviderCTX.js';\nimport { isItemLocked } from '../../utils/nodesTypeguardsAndGetters.js';\nconst placementOrderPreference: Required<DSHookFloatingContextT.Props>['placementOrderPreference'] = [\n 'right-start',\n 'right-start',\n 'right',\n 'left-start',\n 'left-end',\n 'left',\n];\nexport const WithSubmenuMenuItem: React.ComponentType<{\n itemNode: DSMenuButtonT.MenuNodeWithSubmenuItem;\n FlyoutMenuCircularDepInject: DSMenuItemRendererFactoryT.RequiredProps['FlyoutMenuCircularDepInject'];\n ariaPosInSet?: number;\n ariaSetSize?: number;\n}> = ({ itemNode, FlyoutMenuCircularDepInject, ariaPosInSet, ariaSetSize }) => {\n const { dsId, plainItem } = itemNode;\n const { label, secondaryLabel, leftDecoration: LeftDecComponent, minWidth, disabled } = plainItem;\n // locked = disabled || applyAriaDisabled. aria-disabled is printed as \"true\" or not at all (never \"false\")\n const locked = isItemLocked(plainItem);\n\n const {\n ownerProps: { getOwnerProps },\n } = React.useContext(MenuButtonContextProvider);\n const getOwnerPropsArguments = React.useCallback(() => plainItem, [plainItem]);\n\n const {\n focusRegion,\n openedSubItems,\n menuItemEventsHandlers: {\n handleFocusableMenuItemKeyDown,\n handleFocusableMenuItemClick,\n handleFocusableMenuItemOnMouseEnter,\n handleFocusableMenuItemNativeFocusEvent,\n },\n } = React.useContext(MenuBehaviouralContextProviderContext);\n\n const gridLayout = React.useMemo(() => {\n const cols = LeftDecComponent ? ['min-content', 'auto'] : ['auto'];\n if (secondaryLabel) cols.push('auto');\n cols.push('min-content');\n return cols;\n }, [LeftDecComponent, secondaryLabel]);\n\n const focusedRegionPerformanceHelper = React.useRef(focusRegion);\n focusedRegionPerformanceHelper.current = focusRegion;\n\n const isFocused = focusRegion === MENU_FOCUS_REGIONS.ITEM_BY_DSID(dsId);\n const isExpanded = openedSubItems.some((itemWithOpenSubmenu) => itemWithOpenSubmenu.dsId === dsId);\n\n const floatingContext = useFloatingContext({\n placement: placementOrderPreference[0],\n placementOrderPreference,\n animationDuration: 100,\n customOffset: [0, 0],\n externallyControlledIsOpen: isExpanded,\n });\n const {\n refs: { setReference },\n } = floatingContext;\n\n const handleFocusOnRender = React.useCallback(\n (node: HTMLDivElement) => {\n setReference(node);\n if (node && focusRegion === MENU_FOCUS_REGIONS.ITEM_BY_DSID(dsId)) {\n focusNodeRacingConditionSolved(node);\n }\n },\n // we need to change the callback reference every time the focusRegion changes or else the focus will not be set\n [dsId, focusRegion, setReference],\n // we are using the \"as='div'\", typescript is not able to infer the correct type\n // the logic here actually receives a ref to a HTMLDivElement,\n // but the component must think this is a HTMLLIElement ref callback\n ) as unknown as React.RefCallback<HTMLLIElement>;\n\n const handleOnMouseEnter = React.useCallback<React.MouseEventHandler<HTMLDivElement>>(() => {\n handleFocusableMenuItemOnMouseEnter(itemNode);\n }, [handleFocusableMenuItemOnMouseEnter, itemNode]);\n const handleOnFocus = React.useCallback<React.FocusEventHandler<HTMLDivElement>>(\n (e) => {\n handleFocusableMenuItemNativeFocusEvent(itemNode, e);\n },\n [handleFocusableMenuItemNativeFocusEvent, itemNode],\n );\n\n const spacelessDsIdForDom = `ds-menu-item-${`${dsId}`.replace(/\\s/g, '')}`;\n return (\n <>\n <StyledGlobalMenuItemWrapper\n innerRef={handleFocusOnRender}\n onKeyDown={handleFocusableMenuItemKeyDown}\n onClick={handleFocusableMenuItemClick}\n onMouseEnter={handleOnMouseEnter}\n onFocus={handleOnFocus}\n as=\"div\"\n id={`${spacelessDsIdForDom}`}\n tabIndex={isFocused ? 0 : -1}\n role=\"menuitem\"\n aria-haspopup=\"menu\"\n aria-expanded={isExpanded}\n aria-controls={\n /* ********************************************************************************************************************\n * https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-controls\n * The aria-controls only needs to be set when the popup is visible, but it is valid and easier to program to reference an element that is not visible.\n * ********************************************************************************************************************\n * ^^^ some automated tools will mark an error if the aria-controls references an element that does (yet) exist in the DOM\n * so, while technically valid to not check if expanded, we are doing it to avoid automated tools marking an error\n * ******************************************************************************************************************** */\n isExpanded\n ? itemNode.plainChildren.map((child) => `ds-menu-item-${`${child.dsId}`.replace(/\\s/g, '')}`).join(' ')\n : undefined\n }\n aria-disabled={locked ? true : undefined}\n aria-posinset={ariaPosInSet}\n aria-setsize={ariaSetSize}\n applyAriaDisabled={locked}\n $disabled={disabled}\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n >\n <StyledContentWrapper\n cols={gridLayout}\n minHeight=\"16px\"\n gutter=\"xxs\"\n alignItems=\"center\"\n minWidth={minWidth ?? undefined}\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n >\n {LeftDecComponent ? <LeftDecComponent /> : null}\n <StyleMenuItemLabel\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n variant=\"b2\"\n component=\"span\"\n >\n {label}\n </StyleMenuItemLabel>\n {secondaryLabel !== undefined && (\n <StyleMenuItemSecondaryLabel\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n $disabled={locked}\n >\n {secondaryLabel}\n </StyleMenuItemSecondaryLabel>\n )}\n <ChevronSmallRight />\n </StyledContentWrapper>\n </StyledGlobalMenuItemWrapper>\n <FlyoutMenuCircularDepInject\n isMenuOpen={isExpanded}\n floatingContext={floatingContext.context}\n floatingStyles={floatingContext.floatingStyles}\n setFloatingRef={floatingContext.refs.setFloating}\n itemNode={itemNode}\n />\n </>\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACqGnB,mBA0C0B,KATtB,YAjCJ;AArGJ,SAAS,yBAAyB;AAClC;AAAA,EACE;AAAA,E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QACf,gBAAc;AAAA,QACd,mBAAmB;AAAA,QACnB,WAAW;AAAA,QACX;AAAA,QACA;AAAA,QAEA;AAAA,UAAC;AAAA;AAAA,YACC,MAAM;AAAA,YACN,WAAU;AAAA,YACV,QAAO;AAAA,YACP,YAAW;AAAA,YACX,UAAU,YAAY;AAAA,YACtB;AAAA,YACA;AAAA,YAEC;AAAA,iCAAmB,oBAAC,oBAAiB,IAAK;AAAA,cAC3C;AAAA,gBAAC;AAAA;AAAA,kBACC;AAAA,kBACA;AAAA,kBACA,SAAQ;AAAA,kBACR,WAAU;AAAA,kBAET;AAAA;AAAA,cACH;AAAA,cACC,mBAAmB,UAClB;AAAA,gBAAC;AAAA;AAAA,kBACC;AAAA,kBACA;AAAA,kBACA,WAAW;AAAA,kBAEV;AAAA;AAAA,cACH;AAAA,cAEF,oBAAC,qBAAkB;AAAA;AAAA;AAAA,QACrB;AAAA;AAAA,IACF;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACC,YAAY;AAAA,QACZ,iBAAiB,gBAAgB;AAAA,QACjC,gBAAgB,gBAAgB;AAAA,QAChC,gBAAgB,gBAAgB,KAAK;AAAA,QACrC;AAAA;AAAA,IACF;AAAA,KACF;AAEJ;",
|
|
6
6
|
"names": ["React"]
|
|
7
7
|
}
|
|
@@ -22,11 +22,17 @@ const DSOpinionatedButton = (props) => {
|
|
|
22
22
|
} = React2.useContext(MenuButtonContextProvider);
|
|
23
23
|
const {
|
|
24
24
|
propsWithDefault: { children, menuSpecificProps, ...restOfTheProps },
|
|
25
|
-
eventsHandlers: {
|
|
25
|
+
eventsHandlers: {
|
|
26
|
+
handleOnClick,
|
|
27
|
+
handleOnDeliberateActivationWhileSoftLocked,
|
|
28
|
+
handleOnFocus,
|
|
29
|
+
handleFocusIfTriggerIsFocusRegion,
|
|
30
|
+
handleTriggerKeyDown
|
|
31
|
+
},
|
|
26
32
|
floatingContext
|
|
27
33
|
} = useOpinionatedButton(props, globalMenuContext);
|
|
28
34
|
return (
|
|
29
|
-
// onClick/onFocus/innerRef/onKeyDown ARE BEING OVERRIDEN ON PURPOSE
|
|
35
|
+
// onClick/onDeliberateActivationWhileSoftLocked/onFocus/innerRef/onKeyDown ARE BEING OVERRIDEN ON PURPOSE
|
|
30
36
|
// all the functions are being wrapped in a custom logic, they also invoke the original ones
|
|
31
37
|
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
32
38
|
/* @__PURE__ */ jsx(
|
|
@@ -34,6 +40,7 @@ const DSOpinionatedButton = (props) => {
|
|
|
34
40
|
{
|
|
35
41
|
...restOfTheProps,
|
|
36
42
|
onClick: handleOnClick,
|
|
43
|
+
onDeliberateActivationWhileSoftLocked: handleOnDeliberateActivationWhileSoftLocked,
|
|
37
44
|
onFocus: handleOnFocus,
|
|
38
45
|
onKeyDown: handleTriggerKeyDown,
|
|
39
46
|
innerRef: handleFocusIfTriggerIsFocusRegion,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/parts/DSOpinionatedButton/DSOpinionatedButton.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React from 'react';\nimport { describe } from '@elliemae/ds-props-helpers';\nimport { styled } from '@elliemae/ds-system';\nimport { DSButtonV3 } from '@elliemae/ds-button-v2';\nimport { type DSOpinionatedButtonT, DSOpinionatedButtonPropTypesSchema } from './react-desc-prop-types.js';\nimport { useOpinionatedButton } from './config/useOpinionatedButton.js';\nimport { OPINIONATED_BUTTON_SLOTS, DSOpinionatedButtonName } from './constants/index.js';\nimport { DSFlyoutMenu } from '../DSFlyoutMenu/index.js';\nimport { MenuBehaviouralContextProviderContext } from '../DSMenuBehaviouralContextProvider/MenuBehaviouralContextProviderCTX.js';\nimport type { DSMenuButtonT } from '../../react-desc-prop-types.js';\nimport { MenuButtonContextProvider } from '../../MenuButtonContextProviderCTX.js';\nconst StyledButton = styled(DSButtonV3, { name: DSOpinionatedButtonName, slot: OPINIONATED_BUTTON_SLOTS.ROOT })``;\n\nconst DSOpinionatedButton: React.ComponentType<DSOpinionatedButtonT.Props> = (props) => {\n // this is the state of the global menu, hosted in the global context\n // each flyout menu instance will have its own state, only this instances is mandated by the global context\n // that's why flyout menu is reading the info from props and not from the context\n const globalMenuContext = React.useContext(MenuBehaviouralContextProviderContext);\n const {\n isMenuOpen,\n propsWithDefault: { optionsTree },\n } = globalMenuContext;\n\n const {\n ownerProps: { getOwnerProps },\n } = React.useContext(MenuButtonContextProvider);\n const {\n propsWithDefault: { children, menuSpecificProps, ...restOfTheProps },\n eventsHandlers: {
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React from 'react';\nimport { describe } from '@elliemae/ds-props-helpers';\nimport { styled } from '@elliemae/ds-system';\nimport { DSButtonV3 } from '@elliemae/ds-button-v2';\nimport { type DSOpinionatedButtonT, DSOpinionatedButtonPropTypesSchema } from './react-desc-prop-types.js';\nimport { useOpinionatedButton } from './config/useOpinionatedButton.js';\nimport { OPINIONATED_BUTTON_SLOTS, DSOpinionatedButtonName } from './constants/index.js';\nimport { DSFlyoutMenu } from '../DSFlyoutMenu/index.js';\nimport { MenuBehaviouralContextProviderContext } from '../DSMenuBehaviouralContextProvider/MenuBehaviouralContextProviderCTX.js';\nimport type { DSMenuButtonT } from '../../react-desc-prop-types.js';\nimport { MenuButtonContextProvider } from '../../MenuButtonContextProviderCTX.js';\nconst StyledButton = styled(DSButtonV3, { name: DSOpinionatedButtonName, slot: OPINIONATED_BUTTON_SLOTS.ROOT })``;\n\nconst DSOpinionatedButton: React.ComponentType<DSOpinionatedButtonT.Props> = (props) => {\n // this is the state of the global menu, hosted in the global context\n // each flyout menu instance will have its own state, only this instances is mandated by the global context\n // that's why flyout menu is reading the info from props and not from the context\n const globalMenuContext = React.useContext(MenuBehaviouralContextProviderContext);\n const {\n isMenuOpen,\n propsWithDefault: { optionsTree },\n } = globalMenuContext;\n\n const {\n ownerProps: { getOwnerProps },\n } = React.useContext(MenuButtonContextProvider);\n const {\n propsWithDefault: { children, menuSpecificProps, ...restOfTheProps },\n eventsHandlers: {\n handleOnClick,\n handleOnDeliberateActivationWhileSoftLocked,\n handleOnFocus,\n handleFocusIfTriggerIsFocusRegion,\n handleTriggerKeyDown,\n },\n floatingContext,\n } = useOpinionatedButton(props, globalMenuContext);\n\n return (\n // onClick/onDeliberateActivationWhileSoftLocked/onFocus/innerRef/onKeyDown ARE BEING OVERRIDEN ON PURPOSE\n // all the functions are being wrapped in a custom logic, they also invoke the original ones\n <>\n <StyledButton\n {...restOfTheProps}\n onClick={handleOnClick}\n onDeliberateActivationWhileSoftLocked={handleOnDeliberateActivationWhileSoftLocked}\n onFocus={handleOnFocus}\n onKeyDown={handleTriggerKeyDown}\n innerRef={handleFocusIfTriggerIsFocusRegion}\n aria-haspopup=\"menu\"\n aria-controls={\n /* ********************************************************************************************************************\n * https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-controls\n * The aria-controls only needs to be set when the popup is visible, but it is valid and easier to program to reference an element that is not visible.\n * ********************************************************************************************************************\n * ^^^ some automated tools will mark an error if the aria-controls references an element that does (yet) exist in the DOM\n * so, while technically valid to not check if expanded, we are doing it to avoid automated tools marking an error\n * ******************************************************************************************************************** */\n isMenuOpen\n ? optionsTree.plainChildren.map((child) => `ds-menu-item-${`${child.dsId}`.replace(/\\s/g, '')}`).join(' ')\n : undefined\n }\n aria-expanded={isMenuOpen}\n getOwnerProps={getOwnerProps}\n >\n {children}\n </StyledButton>\n <DSFlyoutMenu\n {...menuSpecificProps}\n isMenuOpen={isMenuOpen}\n floatingContext={floatingContext.context}\n floatingStyles={floatingContext.floatingStyles}\n setFloatingRef={floatingContext.refs.setFloating}\n // DSTree doesn't support the root node having a different type than the children, so we need to cast it manually\n itemNode={optionsTree as unknown as DSMenuButtonT.MenuNodeRootItem}\n />\n </>\n );\n};\n\nDSOpinionatedButton.displayName = DSOpinionatedButtonName;\nconst DSOpinionatedButtonWithSchema = describe(DSOpinionatedButton);\nDSOpinionatedButtonWithSchema.propTypes = DSOpinionatedButtonPropTypesSchema;\n\nexport { DSOpinionatedButton, DSOpinionatedButtonWithSchema };\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACyCnB,mBACE,KADF;AAzCJ,OAAOA,YAAW;AAClB,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAoC,0CAA0C;AAC9E,SAAS,4BAA4B;AACrC,SAAS,0BAA0B,+BAA+B;AAClE,SAAS,oBAAoB;AAC7B,SAAS,6CAA6C;AAEtD,SAAS,iCAAiC;AAC1C,MAAM,eAAe,OAAO,YAAY,EAAE,MAAM,yBAAyB,MAAM,yBAAyB,KAAK,CAAC;AAE9G,MAAM,sBAAuE,CAAC,UAAU;AAItF,QAAM,oBAAoBA,OAAM,WAAW,qCAAqC;AAChF,QAAM;AAAA,IACJ;AAAA,IACA,kBAAkB,EAAE,YAAY;AAAA,EAClC,IAAI;AAEJ,QAAM;AAAA,IACJ,YAAY,EAAE,cAAc;AAAA,EAC9B,IAAIA,OAAM,WAAW,yBAAyB;AAC9C,QAAM;AAAA,IACJ,kBAAkB,EAAE,UAAU,mBAAmB,GAAG,eAAe;AAAA,IACnE,gBAAgB;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,EACF,IAAI,qBAAqB,OAAO,iBAAiB;AAEjD;AAAA;AAAA;AAAA,IAGE,iCACE;AAAA;AAAA,QAAC;AAAA;AAAA,UACE,GAAG;AAAA,UACJ,SAAS;AAAA,UACT,uCAAuC;AAAA,UACvC,SAAS;AAAA,UACT,WAAW;AAAA,UACX,UAAU;AAAA,UACV,iBAAc;AAAA,UACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAQE,aACI,YAAY,cAAc,IAAI,CAAC,UAAU,gBAAgB,GAAG,MAAM,IAAI,GAAG,QAAQ,OAAO,EAAE,CAAC,EAAE,EAAE,KAAK,GAAG,IACvG;AAAA;AAAA,UAEN,iBAAe;AAAA,UACf;AAAA,UAEC;AAAA;AAAA,MACH;AAAA,MACA;AAAA,QAAC;AAAA;AAAA,UACE,GAAG;AAAA,UACJ;AAAA,UACA,iBAAiB,gBAAgB;AAAA,UACjC,gBAAgB,gBAAgB;AAAA,UAChC,gBAAgB,gBAAgB,KAAK;AAAA,UAErC,UAAU;AAAA;AAAA,MACZ;AAAA,OACF;AAAA;AAEJ;AAEA,oBAAoB,cAAc;AAClC,MAAM,gCAAgC,SAAS,mBAAmB;AAClE,8BAA8B,YAAY;",
|
|
6
6
|
"names": ["React"]
|
|
7
7
|
}
|
|
@@ -4,37 +4,57 @@ import { resolveRef } from "../../../utils/resolveRef.js";
|
|
|
4
4
|
import { MenuBehaviouralContextProviderContext } from "../../DSMenuBehaviouralContextProvider/MenuBehaviouralContextProviderCTX.js";
|
|
5
5
|
import { MENU_FOCUS_REGIONS } from "../../DSMenuBehaviouralContextProvider/constants/index.js";
|
|
6
6
|
const useTriggerEventsHandlers = ({ propsWithDefault, floatingContext }) => {
|
|
7
|
-
const {
|
|
8
|
-
|
|
7
|
+
const {
|
|
8
|
+
focusRegion,
|
|
9
|
+
triggerFocusRequestId,
|
|
10
|
+
isMenuOpen,
|
|
11
|
+
onOpinionatedOpen,
|
|
12
|
+
onOpinionatedClose,
|
|
13
|
+
trackFocusTrigger,
|
|
14
|
+
shouldFocusImmediately,
|
|
15
|
+
shouldRefocusTrigger
|
|
16
|
+
} = React2.useContext(MenuBehaviouralContextProviderContext);
|
|
17
|
+
const { onClick, onFocus, innerRef, onKeyDown, disabled } = propsWithDefault;
|
|
18
|
+
const { firstOpenAxis } = propsWithDefault.menuSpecificProps;
|
|
9
19
|
const {
|
|
10
20
|
refs: { setReference }
|
|
11
21
|
} = floatingContext;
|
|
12
22
|
const focusedRegionPerformanceHelper = React2.useRef(focusRegion);
|
|
13
|
-
const reRenderButtonToAllowFocus = focusRegion === MENU_FOCUS_REGIONS.TRIGGER && focusedRegionPerformanceHelper.current !== focusRegion;
|
|
14
23
|
focusedRegionPerformanceHelper.current = focusRegion;
|
|
24
|
+
const lastHandledTriggerFocusRequestId = React2.useRef(triggerFocusRequestId);
|
|
15
25
|
const mutableIsMenuOpen = React2.useRef(isMenuOpen);
|
|
16
26
|
mutableIsMenuOpen.current = isMenuOpen;
|
|
17
|
-
const
|
|
18
|
-
(e
|
|
19
|
-
if (onClick) onClick(e, ...args);
|
|
27
|
+
const toggleMenu = React2.useCallback(
|
|
28
|
+
(e) => {
|
|
20
29
|
if (mutableIsMenuOpen.current) {
|
|
21
|
-
onOpinionatedClose();
|
|
30
|
+
onOpinionatedClose({ reason: "trigger-toggle", event: e });
|
|
22
31
|
} else {
|
|
23
|
-
onOpinionatedOpen();
|
|
32
|
+
onOpinionatedOpen({ reason: "trigger-click", event: e });
|
|
24
33
|
}
|
|
25
34
|
},
|
|
26
|
-
[
|
|
35
|
+
[onOpinionatedClose, onOpinionatedOpen]
|
|
36
|
+
);
|
|
37
|
+
const handleOnClick = React2.useCallback(
|
|
38
|
+
(e, ...args) => {
|
|
39
|
+
if (onClick) onClick(e, ...args);
|
|
40
|
+
toggleMenu(e);
|
|
41
|
+
},
|
|
42
|
+
[onClick, toggleMenu]
|
|
27
43
|
);
|
|
44
|
+
const handleOnDeliberateActivationWhileSoftLocked = React2.useCallback((e) => toggleMenu(e), [toggleMenu]);
|
|
28
45
|
const handleOnFocus = React2.useCallback(
|
|
29
46
|
(e, ...args) => {
|
|
30
|
-
if (focusedRegionPerformanceHelper.current !== MENU_FOCUS_REGIONS.TRIGGER)
|
|
47
|
+
if (focusedRegionPerformanceHelper.current !== MENU_FOCUS_REGIONS.TRIGGER)
|
|
48
|
+
trackFocusTrigger({ shouldFocusImmediately: false, refocusTrigger: false });
|
|
31
49
|
if (onFocus) onFocus(e, ...args);
|
|
32
50
|
},
|
|
33
51
|
[onFocus, trackFocusTrigger]
|
|
34
52
|
);
|
|
35
53
|
const handleFocusIfTriggerIsFocusRegion = React2.useCallback(
|
|
36
54
|
(node) => {
|
|
37
|
-
|
|
55
|
+
const isNewTriggerFocusRequest = lastHandledTriggerFocusRequestId.current !== triggerFocusRequestId;
|
|
56
|
+
if (node && isNewTriggerFocusRequest) lastHandledTriggerFocusRequestId.current = triggerFocusRequestId;
|
|
57
|
+
if (node && isNewTriggerFocusRequest && shouldRefocusTrigger.current) {
|
|
38
58
|
if (!shouldFocusImmediately.current) {
|
|
39
59
|
requestAnimationFrame(() => {
|
|
40
60
|
node.focus();
|
|
@@ -46,26 +66,43 @@ const useTriggerEventsHandlers = ({ propsWithDefault, floatingContext }) => {
|
|
|
46
66
|
setReference(node);
|
|
47
67
|
if (innerRef) resolveRef(innerRef, node);
|
|
48
68
|
},
|
|
49
|
-
[innerRef,
|
|
69
|
+
[innerRef, setReference, shouldFocusImmediately, shouldRefocusTrigger, triggerFocusRequestId]
|
|
50
70
|
);
|
|
51
71
|
const handleTriggerKeyDown = React2.useCallback(
|
|
52
72
|
(event, ...args) => {
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
73
|
+
if (!disabled) {
|
|
74
|
+
if (firstOpenAxis === "vertical") {
|
|
75
|
+
if (event.key === "ArrowRight") onOpinionatedOpen({ reason: "trigger-arrow-right", event });
|
|
76
|
+
if (event.key === "ArrowLeft")
|
|
77
|
+
onOpinionatedOpen({ focusLastChild: true, reason: "trigger-arrow-left", event });
|
|
78
|
+
} else {
|
|
79
|
+
if (event.key === "ArrowDown") onOpinionatedOpen({ reason: "trigger-arrow-down", event });
|
|
80
|
+
if (event.key === "ArrowUp") onOpinionatedOpen({ focusLastChild: true, reason: "trigger-arrow-up", event });
|
|
81
|
+
}
|
|
58
82
|
}
|
|
59
83
|
if (event.key === "Escape") {
|
|
60
|
-
|
|
84
|
+
if (mutableIsMenuOpen.current) event.stopPropagation();
|
|
85
|
+
onOpinionatedClose({ reason: "escape", event });
|
|
61
86
|
}
|
|
62
87
|
if (onKeyDown) onKeyDown(event, ...args);
|
|
63
88
|
},
|
|
64
|
-
[onKeyDown, onOpinionatedOpen, onOpinionatedClose]
|
|
89
|
+
[firstOpenAxis, disabled, onKeyDown, onOpinionatedOpen, onOpinionatedClose]
|
|
65
90
|
);
|
|
66
91
|
return React2.useMemo(
|
|
67
|
-
() => ({
|
|
68
|
-
|
|
92
|
+
() => ({
|
|
93
|
+
handleTriggerKeyDown,
|
|
94
|
+
handleOnClick,
|
|
95
|
+
handleOnDeliberateActivationWhileSoftLocked,
|
|
96
|
+
handleOnFocus,
|
|
97
|
+
handleFocusIfTriggerIsFocusRegion
|
|
98
|
+
}),
|
|
99
|
+
[
|
|
100
|
+
handleFocusIfTriggerIsFocusRegion,
|
|
101
|
+
handleOnClick,
|
|
102
|
+
handleOnDeliberateActivationWhileSoftLocked,
|
|
103
|
+
handleOnFocus,
|
|
104
|
+
handleTriggerKeyDown
|
|
105
|
+
]
|
|
69
106
|
);
|
|
70
107
|
};
|
|
71
108
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../src/parts/DSOpinionatedButton/config/useTriggerEventsHandlers.ts"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import type { DSButtonV3T } from '@elliemae/ds-button-v2';\nimport { type useFloatingContext } from '@elliemae/ds-floating-context';\nimport React from 'react';\nimport { resolveRef } from '../../../utils/resolveRef.js';\nimport { MenuBehaviouralContextProviderContext } from '../../DSMenuBehaviouralContextProvider/MenuBehaviouralContextProviderCTX.js';\nimport { MENU_FOCUS_REGIONS } from '../../DSMenuBehaviouralContextProvider/constants/index.js';\nimport { type DSOpinionatedButtonT } from '../react-desc-prop-types.js';\n\ntype UseTriggerEventsHandlersConfig = {\n propsWithDefault: DSOpinionatedButtonT.InternalProps;\n floatingContext: ReturnType<typeof useFloatingContext>;\n};\n\nexport const useTriggerEventsHandlers = ({ propsWithDefault, floatingContext }: UseTriggerEventsHandlersConfig) => {\n // =============================================================================\n // on click -> open the submenu\n // if the props already include an onClick, we will wrap it\n // =============================================================================\n const {
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACEvB,OAAOA,YAAW;AAClB,SAAS,kBAAkB;AAC3B,SAAS,6CAA6C;AACtD,SAAS,0BAA0B;AAQ5B,MAAM,2BAA2B,CAAC,EAAE,kBAAkB,gBAAgB,MAAsC;AAKjH,QAAM,
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import type { DSButtonV3T } from '@elliemae/ds-button-v2';\nimport { type useFloatingContext } from '@elliemae/ds-floating-context';\nimport React from 'react';\nimport { resolveRef } from '../../../utils/resolveRef.js';\nimport { MenuBehaviouralContextProviderContext } from '../../DSMenuBehaviouralContextProvider/MenuBehaviouralContextProviderCTX.js';\nimport { MENU_FOCUS_REGIONS } from '../../DSMenuBehaviouralContextProvider/constants/index.js';\nimport { type DSOpinionatedButtonT } from '../react-desc-prop-types.js';\n\ntype UseTriggerEventsHandlersConfig = {\n propsWithDefault: DSOpinionatedButtonT.InternalProps;\n floatingContext: ReturnType<typeof useFloatingContext>;\n};\n\nexport const useTriggerEventsHandlers = ({ propsWithDefault, floatingContext }: UseTriggerEventsHandlersConfig) => {\n // =============================================================================\n // on click -> open the submenu\n // if the props already include an onClick, we will wrap it\n // =============================================================================\n const {\n focusRegion,\n triggerFocusRequestId,\n isMenuOpen,\n onOpinionatedOpen,\n onOpinionatedClose,\n trackFocusTrigger,\n shouldFocusImmediately,\n shouldRefocusTrigger,\n } = React.useContext(MenuBehaviouralContextProviderContext);\n const { onClick, onFocus, innerRef, onKeyDown, disabled } = propsWithDefault;\n const { firstOpenAxis } = propsWithDefault.menuSpecificProps;\n const {\n refs: { setReference },\n } = floatingContext;\n\n // only read by the passive focus tracking below; assigning the current value is idempotent, so it is safe to do during render\n const focusedRegionPerformanceHelper = React.useRef(focusRegion);\n focusedRegionPerformanceHelper.current = focusRegion;\n\n // each request to return focus to the trigger changes `triggerFocusRequestId`, which changes the reference of the ref\n // callback below so React invokes it again with the node, and it focuses itself. Requests are consumed here, in the\n // commit phase, never while rendering: a render can run more than once (StrictMode) before it commits.\n const lastHandledTriggerFocusRequestId = React.useRef(triggerFocusRequestId);\n\n const mutableIsMenuOpen = React.useRef(isMenuOpen);\n // this is a boolean, so a primitive value,\n // we don't need to useEffect to change it\n // because we don't need to ensure referencial equality\n mutableIsMenuOpen.current = isMenuOpen;\n\n // opening the menu is not an action of the lock: the trigger is a view-only disclosure, what the user selects inside it\n // is the responsibility of the menu items. So a soft-locked trigger (applyAriaDisabled, readOnly) toggles the menu\n // through DSButton's `onDeliberateActivationWhileSoftLocked`, while the consumer's onClick stays withheld.\n // A `disabled` trigger is a hard lock: it never opens.\n const toggleMenu = React.useCallback(\n (e: React.MouseEvent | React.KeyboardEvent) => {\n // no reason to change this function reference every time the menu opens/closes\n // so we are using a mutable ref to optimize this\n if (mutableIsMenuOpen.current) {\n onOpinionatedClose({ reason: 'trigger-toggle', event: e });\n } else {\n onOpinionatedOpen({ reason: 'trigger-click', event: e });\n }\n },\n [onOpinionatedClose, onOpinionatedOpen],\n );\n const handleOnClick = React.useCallback<Required<DSButtonV3T.Props>['onClick']>(\n (e, ...args) => {\n if (onClick) onClick(e, ...args);\n toggleMenu(e);\n },\n [onClick, toggleMenu],\n );\n const handleOnDeliberateActivationWhileSoftLocked = React.useCallback<\n Required<DSButtonV3T.Props>['onDeliberateActivationWhileSoftLocked']\n >((e) => toggleMenu(e), [toggleMenu]);\n const handleOnFocus = React.useCallback<Required<DSButtonV3T.Props>['onFocus']>(\n (e, ...args) => {\n if (focusedRegionPerformanceHelper.current !== MENU_FOCUS_REGIONS.TRIGGER)\n // passive tracking only: focus is ALREADY on the trigger by definition of this event,\n // so it must not be re-requested \u2014 a deferred refocus would race a Tab\n // that has already legitimately moved focus to the next element, and could win, stealing it back\n trackFocusTrigger({ shouldFocusImmediately: false, refocusTrigger: false });\n if (onFocus) onFocus(e, ...args);\n },\n [onFocus, trackFocusTrigger],\n );\n\n const handleFocusIfTriggerIsFocusRegion = React.useCallback<React.RefCallback<HTMLButtonElement>>(\n (node) => {\n const isNewTriggerFocusRequest = lastHandledTriggerFocusRequestId.current !== triggerFocusRequestId;\n if (node && isNewTriggerFocusRequest) lastHandledTriggerFocusRequestId.current = triggerFocusRequestId;\n if (node && isNewTriggerFocusRequest && shouldRefocusTrigger.current) {\n // when user presses \"Enter\" different things happen depending on top of what element the focus is\n // if it is in the trigger (this function) then it spawns the submenu and focuses the first item\n // if it is in a menu item, it activates the item and closes the menu, triggering this function again\n // So, why do we need the requestAnimationFrame?\n // pressing enter in an item will focus the trigger\n // -> current react behaviour means the menu button \"keyDown\" event will also trigger with \"Enter\"\n // -> which will open the menu again\n // as of react 18 and 28/october/2025, this requestAnimationFrame prevents the keyDown event from triggering on top of the button\n if (!shouldFocusImmediately.current) {\n requestAnimationFrame(() => {\n node.focus();\n });\n } else {\n // In some cases, like when user presses \"Tab\" within a menu, we want to focus the trigger immediately.\n // So that the tab flow occurs from the trigger to the next focusable element in the page.\n // Therefore, we don't need to wait for the next frame.\n node.focus();\n }\n }\n setReference(node);\n if (innerRef) resolveRef(innerRef, node);\n },\n [innerRef, setReference, shouldFocusImmediately, shouldRefocusTrigger, triggerFocusRequestId],\n );\n\n /*\n * 13th August 2024:\n * https://www.w3.org/WAI/ARIA/apg/patterns/menu-button/\n * With focus on the button:\n * Enter: opens the menu and places focus on the first menu item.\n * Space: Opens the menu and places focus on the first menu item.\n * (Optional) Down Arrow: opens the menu and moves focus to the first menu item.\n * (Optional) Up Arrow: opens the menu and moves focus to the last menu item.\n *\n * Those optional keys assume the menu button sits on a horizontal bar (or on none): the menu opens below the\n * trigger. On a vertical bar Down and Up move between the items of the bar and the menus open to the side, so\n * with `firstOpenAxis: 'vertical'` the same two optional keys are Right Arrow (first item) and Left Arrow (last\n * item), and Down/Up are not used by the trigger at all: they reach the bar.\n */\n const handleTriggerKeyDown = React.useCallback<Required<DSButtonV3T.Props>['onKeyDown']>(\n (event, ...args) => {\n // DSButtonV3 triggers the onClick on Enter and Space, so we don't need to handle it here\n // if (event.key === 'Enter' || event.key === ' ') {\n // onOpinionatedOpen();\n // }\n // a soft-locked trigger still opens with the arrows (opening is not an action of the lock, see toggleMenu);\n // a disabled trigger leaves the page and never gets the key\n if (!disabled) {\n if (firstOpenAxis === 'vertical') {\n if (event.key === 'ArrowRight') onOpinionatedOpen({ reason: 'trigger-arrow-right', event });\n if (event.key === 'ArrowLeft')\n onOpinionatedOpen({ focusLastChild: true, reason: 'trigger-arrow-left', event });\n } else {\n if (event.key === 'ArrowDown') onOpinionatedOpen({ reason: 'trigger-arrow-down', event });\n if (event.key === 'ArrowUp') onOpinionatedOpen({ focusLastChild: true, reason: 'trigger-arrow-up', event });\n }\n }\n if (event.key === 'Escape') {\n // the menu consumes the Escape only when it is open: the event must not also reach an ancestor that closes on\n // Escape (DSDialog, DSModalSlide... React bubbles through portals). A closed menu has nothing to close,\n // so the Escape keeps propagating and the ancestor still gets it.\n if (mutableIsMenuOpen.current) event.stopPropagation();\n onOpinionatedClose({ reason: 'escape', event });\n }\n if (onKeyDown) onKeyDown(event, ...args);\n },\n [firstOpenAxis, disabled, onKeyDown, onOpinionatedOpen, onOpinionatedClose],\n );\n\n return React.useMemo(\n () => ({\n handleTriggerKeyDown,\n handleOnClick,\n handleOnDeliberateActivationWhileSoftLocked,\n handleOnFocus,\n handleFocusIfTriggerIsFocusRegion,\n }),\n [\n handleFocusIfTriggerIsFocusRegion,\n handleOnClick,\n handleOnDeliberateActivationWhileSoftLocked,\n handleOnFocus,\n handleTriggerKeyDown,\n ],\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAA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W,WAAU,OAAO,GAAG,IAAI;AAAA,IACzC;AAAA,IACA,CAAC,eAAe,UAAU,WAAW,mBAAmB,kBAAkB;AAAA,EAC5E;AAEA,SAAOA,OAAM;AAAA,IACX,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["React"]
|
|
7
7
|
}
|
|
@@ -3,6 +3,7 @@ import { PropTypes, getPropsPerSlotPropTypes } from "@elliemae/ds-props-helpers"
|
|
|
3
3
|
import { DSButtonV3PropTypes } from "@elliemae/ds-button-v2";
|
|
4
4
|
import { DSMenuButtonName, MENU_BUTTON_SLOTS } from "./constants/index.js";
|
|
5
5
|
const menuSpecificDefaultProps = {
|
|
6
|
+
firstOpenAxis: "horizontal",
|
|
6
7
|
onClickOutside: () => null,
|
|
7
8
|
onOptionClick: () => null,
|
|
8
9
|
openedSubmenus: {},
|
|
@@ -25,8 +26,20 @@ const MenuBehaviouralLayerPropTypes = {
|
|
|
25
26
|
itemNode: DSMenuButtonT.PseudoFocusableMenuNodes,
|
|
26
27
|
metainfo: { itemNode: DSMenuButtonT.PseudoFocusableMenuNodes; event?: React.SyntheticEvent },
|
|
27
28
|
) => void)`),
|
|
28
|
-
onOpen: PropTypes.func.description("function triggered when the widget opens the menu").signature(
|
|
29
|
-
|
|
29
|
+
onOpen: PropTypes.func.description("function triggered when the widget opens the menu, with the reason (intent) that triggered it").signature(
|
|
30
|
+
`((metainfo: { reason: 'trigger-click' | 'trigger-arrow-down' | 'trigger-arrow-up' | 'trigger-arrow-right' | 'trigger-arrow-left'; event?: React.SyntheticEvent }) => void)`
|
|
31
|
+
),
|
|
32
|
+
onClose: PropTypes.func.description("function triggered when the widget closes the menu, with the reason (intent) that triggered it").signature(
|
|
33
|
+
`((metainfo: { reason: 'outside-click' | 'window-blur' | 'escape' | 'tab' | 'item-activation' | 'trigger-toggle'; event?: React.SyntheticEvent | MouseEvent | TouchEvent | FocusEvent }) => void)`
|
|
34
|
+
),
|
|
35
|
+
onItemKeyDown: PropTypes.func.description(
|
|
36
|
+
"Function triggered when a key is pressed with focus on a menu item, before the menu handles or consumes it (Tab is not reported). `nestLevel` is how many submenus deep the item is (0: an item of the main menu), `hasSubmenu` tells whether the item opens a submenu. Left and Right Arrow never bubble out of the menu, this is how a host implements menubar behaviour"
|
|
37
|
+
).signature(
|
|
38
|
+
`((metainfo: { itemNode: DSMenuButtonT.PseudoFocusableMenuNodes; event: React.KeyboardEvent; nestLevel: number; hasSubmenu: boolean }) => void)`
|
|
39
|
+
),
|
|
40
|
+
a11yDangerouslyConsumerOwnedMenuOpenState: PropTypes.bool.description(
|
|
41
|
+
"Escape hatch: when a boolean is provided, the consumer owns the menu open state; onOpen/onClose fire for each intent that changes the effective state, and the consumer is expected to sync the prop from them. Invalidates the open-state-related a11y guarantees of the widget"
|
|
42
|
+
),
|
|
30
43
|
onDisplayedSubmenuChange: PropTypes.func.description("function triggered when the widget's closes or opens a submenu").signature(`((
|
|
31
44
|
newOpenedItems: DSMenuButtonT.PseudoFocusableMenuNodes[],
|
|
32
45
|
metainfo: { itemNode: DSMenuButtonT.PseudoFocusableMenuNodes; event?: React.SyntheticEvent },
|
|
@@ -34,6 +47,9 @@ const MenuBehaviouralLayerPropTypes = {
|
|
|
34
47
|
};
|
|
35
48
|
const DSMenuSpecificPropTypes = {
|
|
36
49
|
ItemRenderer: PropTypes.node.description("Component to be used to render the items"),
|
|
50
|
+
firstOpenAxis: PropTypes.oneOf(["horizontal", "vertical"]).description(
|
|
51
|
+
"The axis of the bar the menu button sits on, which decides the keys that open the menu from the trigger. 'horizontal': Down Arrow opens it with the focus on the first item and Up Arrow on the last one. 'vertical': Right Arrow opens it with the focus on the first item and Left Arrow on the last one, and Down and Up are left to the bar. A click, Enter and Space open it on any axis"
|
|
52
|
+
).defaultValue("horizontal"),
|
|
37
53
|
onClickOutside: PropTypes.func.description("Callback executed when you click outside the dropdown menu, or press the Esc key").defaultValue(() => null),
|
|
38
54
|
onOptionClick: PropTypes.func.description(
|
|
39
55
|
"Callback triggered when an item is clicked or pressed. We provide the next selected options, the clicked option and the event, in that order"
|