@react-spectrum/menu 3.22.8 → 3.22.10
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/ContextualHelpTrigger.main.js +6 -5
- package/dist/ContextualHelpTrigger.main.js.map +1 -1
- package/dist/ContextualHelpTrigger.mjs +6 -5
- package/dist/ContextualHelpTrigger.module.js +6 -5
- package/dist/ContextualHelpTrigger.module.js.map +1 -1
- package/dist/Menu.main.js +1 -1
- package/dist/Menu.main.js.map +1 -1
- package/dist/Menu.mjs +2 -2
- package/dist/Menu.module.js +2 -2
- package/dist/Menu.module.js.map +1 -1
- package/dist/Popover.main.js +196 -0
- package/dist/Popover.main.js.map +1 -0
- package/dist/Popover.mjs +191 -0
- package/dist/Popover.module.js +191 -0
- package/dist/Popover.module.js.map +1 -0
- package/dist/SubmenuTrigger.main.js +3 -3
- package/dist/SubmenuTrigger.main.js.map +1 -1
- package/dist/SubmenuTrigger.mjs +4 -4
- package/dist/SubmenuTrigger.module.js +4 -4
- package/dist/SubmenuTrigger.module.js.map +1 -1
- package/dist/Underlay.main.js +54 -0
- package/dist/Underlay.main.js.map +1 -0
- package/dist/Underlay.mjs +49 -0
- package/dist/Underlay.module.js +49 -0
- package/dist/Underlay.module.js.map +1 -0
- package/dist/calculatePosition.main.js +392 -0
- package/dist/calculatePosition.main.js.map +1 -0
- package/dist/calculatePosition.mjs +386 -0
- package/dist/calculatePosition.module.js +386 -0
- package/dist/calculatePosition.module.js.map +1 -0
- package/dist/menu.2259a533.css +210 -0
- package/dist/menu.2259a533.css.map +1 -0
- package/dist/menu.359a0c0a.css +131 -0
- package/dist/menu.359a0c0a.css.map +1 -0
- package/dist/menu.57b3a408.css +12 -0
- package/dist/menu.57b3a408.css.map +1 -0
- package/dist/overlays_css.main.js +35 -0
- package/dist/overlays_css.main.js.map +1 -0
- package/dist/overlays_css.mjs +37 -0
- package/dist/overlays_css.module.js +37 -0
- package/dist/overlays_css.module.js.map +1 -0
- package/dist/popover_vars_css.main.js +83 -0
- package/dist/popover_vars_css.main.js.map +1 -0
- package/dist/popover_vars_css.mjs +85 -0
- package/dist/popover_vars_css.module.js +85 -0
- package/dist/popover_vars_css.module.js.map +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/underlay_vars_css.main.js +50 -0
- package/dist/underlay_vars_css.main.js.map +1 -0
- package/dist/underlay_vars_css.mjs +52 -0
- package/dist/underlay_vars_css.module.js +52 -0
- package/dist/underlay_vars_css.module.js.map +1 -0
- package/dist/useCloseOnScroll.main.js +51 -0
- package/dist/useCloseOnScroll.main.js.map +1 -0
- package/dist/useCloseOnScroll.mjs +46 -0
- package/dist/useCloseOnScroll.module.js +46 -0
- package/dist/useCloseOnScroll.module.js.map +1 -0
- package/dist/useOverlayPosition.main.js +225 -0
- package/dist/useOverlayPosition.main.js.map +1 -0
- package/dist/useOverlayPosition.mjs +220 -0
- package/dist/useOverlayPosition.module.js +220 -0
- package/dist/useOverlayPosition.module.js.map +1 -0
- package/dist/usePopover.main.js +73 -0
- package/dist/usePopover.main.js.map +1 -0
- package/dist/usePopover.mjs +68 -0
- package/dist/usePopover.module.js +68 -0
- package/dist/usePopover.module.js.map +1 -0
- package/package.json +23 -23
- package/src/ContextualHelpTrigger.tsx +4 -3
- package/src/Menu.tsx +2 -1
- package/src/Popover.tsx +240 -0
- package/src/SubmenuTrigger.tsx +3 -3
- package/src/Underlay.tsx +43 -0
- package/src/calculatePosition.ts +627 -0
- package/src/useCloseOnScroll.ts +65 -0
- package/src/useOverlayPosition.ts +327 -0
- package/src/usePopover.ts +136 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require("./menu.5b49954a.css");
|
|
2
2
|
var $a10e565ec42bcf96$exports = require("./contextualhelp_vars_css.main.js");
|
|
3
|
+
var $25179ade6a3f679b$exports = require("./Popover.main.js");
|
|
3
4
|
require("./menu.2ec1fdaf.css");
|
|
4
5
|
var $3deee0fd2b46e64f$exports = require("./menu_vars_css.main.js");
|
|
5
6
|
var $cac834c4bc0a51d3$exports = require("./context.main.js");
|
|
@@ -7,7 +8,7 @@ var $63a7dff9cbe2d046$exports = require("./Menu.main.js");
|
|
|
7
8
|
var $hdb2e$reactspectrumutils = require("@react-spectrum/utils");
|
|
8
9
|
var $hdb2e$reactariafocus = require("@react-aria/focus");
|
|
9
10
|
var $hdb2e$reactariainteractions = require("@react-aria/interactions");
|
|
10
|
-
var $hdb2e$
|
|
11
|
+
var $hdb2e$reactariautils = require("@react-aria/utils");
|
|
11
12
|
var $hdb2e$react = require("react");
|
|
12
13
|
var $hdb2e$reactdom = require("react-dom");
|
|
13
14
|
var $hdb2e$reactariamenu = require("@react-aria/menu");
|
|
@@ -45,6 +46,7 @@ $parcel$export(module.exports, "ContextualHelpTrigger", () => $db380858d398b658$
|
|
|
45
46
|
|
|
46
47
|
|
|
47
48
|
|
|
49
|
+
|
|
48
50
|
function $db380858d398b658$var$ContextualHelpTrigger(props) {
|
|
49
51
|
let { isUnavailable: isUnavailable = false, targetKey: targetKey } = props;
|
|
50
52
|
let triggerRef = (0, $hdb2e$react.useRef)(null);
|
|
@@ -90,8 +92,7 @@ function $db380858d398b658$var$ContextualHelpTrigger(props) {
|
|
|
90
92
|
let [trigger] = (0, ($parcel$interopDefault($hdb2e$react))).Children.toArray(props.children);
|
|
91
93
|
let [, content] = props.children;
|
|
92
94
|
let onBlurWithin = (e)=>{
|
|
93
|
-
|
|
94
|
-
if (e.relatedTarget && popoverRef.current && !((_popoverRef_current_UNSAFE_getDOMNode = popoverRef.current.UNSAFE_getDOMNode()) === null || _popoverRef_current_UNSAFE_getDOMNode === void 0 ? void 0 : _popoverRef_current_UNSAFE_getDOMNode.contains(e.relatedTarget)) && !(e.relatedTarget === triggerRef.current && (0, $hdb2e$reactariainteractions.getInteractionModality)() === 'pointer')) {
|
|
95
|
+
if (e.relatedTarget && popoverRef.current && !(0, $hdb2e$reactariautils.nodeContains)(popoverRef.current.UNSAFE_getDOMNode(), e.relatedTarget) && !(e.relatedTarget === triggerRef.current && (0, $hdb2e$reactariainteractions.getInteractionModality)() === 'pointer')) {
|
|
95
96
|
if (submenuTriggerState.isOpen) submenuTriggerState.close();
|
|
96
97
|
}
|
|
97
98
|
};
|
|
@@ -101,7 +102,7 @@ function $db380858d398b658$var$ContextualHelpTrigger(props) {
|
|
|
101
102
|
setTraySubmenuAnimation('spectrum-TraySubmenu-exit');
|
|
102
103
|
setTimeout(()=>{
|
|
103
104
|
submenuTriggerState.close();
|
|
104
|
-
if (parentMenuRef.current && !parentMenuRef.current
|
|
105
|
+
if (parentMenuRef.current && !(0, $hdb2e$reactariautils.nodeContains)(parentMenuRef.current, document.activeElement)) parentMenuRef.current.focus();
|
|
105
106
|
}, 220); // Matches transition duration
|
|
106
107
|
};
|
|
107
108
|
if (isMobile) {
|
|
@@ -131,7 +132,7 @@ function $db380858d398b658$var$ContextualHelpTrigger(props) {
|
|
|
131
132
|
submenuTriggerState.close();
|
|
132
133
|
(_parentMenuRef_current = parentMenuRef.current) === null || _parentMenuRef_current === void 0 ? void 0 : _parentMenuRef_current.focus();
|
|
133
134
|
};
|
|
134
|
-
overlay = /*#__PURE__*/ (0, ($parcel$interopDefault($hdb2e$react))).createElement((0, $
|
|
135
|
+
overlay = /*#__PURE__*/ (0, ($parcel$interopDefault($hdb2e$react))).createElement((0, $25179ade6a3f679b$exports.Popover), {
|
|
135
136
|
...popoverProps,
|
|
136
137
|
UNSAFE_style: {
|
|
137
138
|
clipPath: 'unset',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;AA6BD,SAAS,4CAAsB,KAAqC;IAClE,IAAI,iBAAC,gBAAgB,kBAAO,SAAS,EAAC,GAAG;IAEzC,IAAI,aAAa,CAAA,GAAA,mBAAK,EAAiB;IACvC,IAAI,aAAa,CAAA,GAAA,mBAAK,EAAsC;IAC5D,IAAI,oBAAC,gBAAgB,oBA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DAAK,GAAG;YACrC,sBAAsB;YACtB,cAAc;YACd,WAAW;YACX,OAAO;YACP,KAAK;YACL,YAAY;YACZ,WAAU;YACV,kBAAkB;YAClB,WAAA;YACA,0BAAA;yBACA,0DAAC,CAAA,GAAA,gCAAS;YAAE,cAAA;YAAa,SAAA;WACtB;IAIT;IAEA,qBACE,oIACE,0DAAC,CAAA,GAAA,+CAAoB,EAAE,QAAQ;QAAC,OAAO;2BAAC;wBAAe;YAAY,GAAG,mBAAmB;QAAA;OAAI,wBAC7F,0DAAC,CAAA,GAAA,sCAAW;QAAE,OAAO;OAClB,oBAAoB,MAAM,IAAI;AAIvC;AAEA,4CAAsB,iBAAiB,GAAG,UAAU,kBAAqB,KAAmB;IAC1F,IAAI,aAA6B,EAAE;IACnC,CAAA,GAAA,sCAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,QAAQ,EAAE,CAAA;QACrC,kBAAI,CAAA,GAAA,sCAAI,EAAE,cAAc,CAAC,QACvB,WAAW,IAAI,CAAC;IAEpB;IACA,IAAI,CAAC,QAAQ,GAAG;IAChB,IAAI,GAAG,QAAQ,GAAG,MAAM,QAAQ;IAEhC,MAAM;QACJ,uBAAS,CAAA,GAAA,sCAAI,EAAE,YAAY,CAAC,SAAS;YAAC,GAAG,QAAQ,KAAK;YAAS,eAAe;YAAM,WAAW;QAAI;QACnG,SAAS,CAAC,wBACR,0DAAC;gBAAsB,KAAK,QAAQ,GAAG;gBAAE,WAAW,QAAQ,GAAG;gBAAG,GAAG,KAAK;eACvE,SACA;IAGP;AACF;AAEA,IAAI,4CAAQ","sources":["packages/@react-spectrum/menu/src/ContextualHelpTrigger.tsx"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {classNames, SlotProvider, unwrapDOMRef, useIsMobileDevice} from '@react-spectrum/utils';\nimport {DOMRefValue, ItemProps, Key} from '@react-types/shared';\nimport {FocusScope} from '@react-aria/focus';\nimport {getInteractionModality} from '@react-aria/interactions';\nimport helpStyles from '@adobe/spectrum-css-temp/components/contextualhelp/vars.css';\nimport {Popover} from '@react-spectrum/overlays';\nimport React, {JSX, KeyboardEventHandler, ReactElement, useEffect, useRef, useState} from 'react';\nimport ReactDOM from 'react-dom';\nimport styles from '@adobe/spectrum-css-temp/components/menu/vars.css';\nimport {SubmenuTriggerContext, useMenuStateContext} from './context';\nimport {TrayHeaderWrapper} from './Menu';\nimport {useSubmenuTrigger} from '@react-aria/menu';\nimport {useSubmenuTriggerState} from '@react-stately/menu';\n\ninterface MenuDialogTriggerProps {\n /** Whether the menu item is currently unavailable. */\n isUnavailable?: boolean,\n /** The triggering Item and the Dialog, respectively. */\n children: [ReactElement, ReactElement]\n}\n\ninterface InternalMenuDialogTriggerProps extends MenuDialogTriggerProps {\n targetKey: Key\n}\n\nexport interface SpectrumMenuDialogTriggerProps extends MenuDialogTriggerProps {}\n\nfunction ContextualHelpTrigger(props: InternalMenuDialogTriggerProps): ReactElement {\n let {isUnavailable = false, targetKey} = props;\n\n let triggerRef = useRef<HTMLLIElement>(null);\n let popoverRef = useRef<DOMRefValue<HTMLDivElement> | null>(null);\n let {popoverContainer, trayContainerRef, rootMenuTriggerState, menu: parentMenuRef, state} = useMenuStateContext()!;\n let submenuTriggerState = useSubmenuTriggerState({triggerKey: targetKey}, {...rootMenuTriggerState!, ...state});\n let submenuRef = unwrapDOMRef(popoverRef);\n let {submenuTriggerProps, popoverProps} = useSubmenuTrigger({\n parentMenuRef,\n submenuRef,\n type: 'dialog',\n isDisabled: !isUnavailable\n }, submenuTriggerState, triggerRef);\n let isMobile = useIsMobileDevice();\n let [traySubmenuAnimation, setTraySubmenuAnimation] = useState('');\n useEffect(() => {\n if (submenuTriggerState.isOpen) {\n setTraySubmenuAnimation('spectrum-TraySubmenu-enter');\n }\n }, [submenuTriggerState.isOpen]);\n let slots = {};\n if (isUnavailable) {\n slots = {\n dialog: {\n UNSAFE_className: classNames(\n helpStyles,\n 'react-spectrum-ContextualHelp-dialog',\n {\n 'react-spectrum-ContextualHelp-dialog--isMobile': isMobile\n },\n classNames(\n styles,\n {\n 'spectrum-Menu-subdialog': !isMobile,\n [traySubmenuAnimation]: isMobile\n }\n )\n )\n },\n content: {UNSAFE_className: helpStyles['react-spectrum-ContextualHelp-content']},\n footer: {UNSAFE_className: helpStyles['react-spectrum-ContextualHelp-footer']}\n };\n }\n let [trigger] = React.Children.toArray(props.children);\n let [, content] = props.children as [ReactElement, ReactElement];\n\n let onBlurWithin = (e) => {\n if (e.relatedTarget && popoverRef.current && (!popoverRef.current.UNSAFE_getDOMNode()?.contains(e.relatedTarget) && !(e.relatedTarget === triggerRef.current && getInteractionModality() === 'pointer'))) {\n if (submenuTriggerState.isOpen) {\n submenuTriggerState.close();\n }\n }\n };\n\n let overlay;\n let tray;\n let onBackButtonPress = () => {\n setTraySubmenuAnimation('spectrum-TraySubmenu-exit');\n setTimeout(() => {\n submenuTriggerState.close();\n if (parentMenuRef.current && !parentMenuRef.current.contains(document.activeElement)) {\n parentMenuRef.current.focus();\n }\n }, 220); // Matches transition duration\n };\n\n if (isMobile) {\n delete submenuTriggerProps.onBlur;\n delete submenuTriggerProps.onHoverChange;\n if (trayContainerRef.current && submenuTriggerState.isOpen) {\n let subDialogKeyDown: KeyboardEventHandler = (e) => {\n switch (e.key) {\n case 'Escape':\n e.stopPropagation();\n onBackButtonPress();\n break;\n }\n };\n\n tray = (\n <TrayHeaderWrapper\n isSubmenu\n parentMenuTreeState={state}\n rootMenuTriggerState={rootMenuTriggerState}\n wrapperKeyDown={subDialogKeyDown}\n onBackButtonPress={onBackButtonPress}>\n {content}\n </TrayHeaderWrapper>\n );\n\n overlay = ReactDOM.createPortal(tray, trayContainerRef.current);\n }\n } else {\n let onDismissButtonPress = () => {\n submenuTriggerState.close();\n parentMenuRef.current?.focus();\n };\n\n overlay = (\n <Popover\n {...popoverProps}\n UNSAFE_style={{clipPath: 'unset', overflow: 'visible', filter: 'unset', borderWidth: '0px'}}\n UNSAFE_className={classNames(styles, 'spectrum-Submenu-popover')}\n onDismissButtonPress={onDismissButtonPress}\n onBlurWithin={onBlurWithin}\n container={popoverContainer!}\n state={submenuTriggerState}\n ref={popoverRef}\n triggerRef={triggerRef}\n placement=\"end top\"\n containerPadding={0}\n hideArrow\n enableBothDismissButtons>\n <FocusScope restoreFocus contain>\n {content}\n </FocusScope>\n </Popover>\n );\n }\n\n return (\n <>\n <SubmenuTriggerContext.Provider value={{isUnavailable, triggerRef, ...submenuTriggerProps}}>{trigger}</SubmenuTriggerContext.Provider>\n <SlotProvider slots={slots}>\n {submenuTriggerState.isOpen && overlay}\n </SlotProvider>\n </>\n );\n}\n\nContextualHelpTrigger.getCollectionNode = function* getCollectionNode<T>(props: ItemProps<T>) {\n let childArray: ReactElement[] = [];\n React.Children.forEach(props.children, child => {\n if (React.isValidElement(child)) {\n childArray.push(child);\n }\n });\n let [trigger] = childArray;\n let [, content] = props.children as [ReactElement, ReactElement];\n\n yield {\n element: React.cloneElement(trigger, {...trigger.props as any, hasChildItems: true, isTrigger: true}),\n wrapper: (element) => (\n <ContextualHelpTrigger key={element.key} targetKey={element.key} {...props}>\n {element}\n {content}\n </ContextualHelpTrigger>\n )\n };\n};\n\nlet _Item = ContextualHelpTrigger as unknown as (props: SpectrumMenuDialogTriggerProps) => JSX.Element;\nexport {_Item as ContextualHelpTrigger};\n"],"names":[],"version":3,"file":"ContextualHelpTrigger.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;;AA8BD,SAAS,4CAAs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 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {classNames, SlotProvider, unwrapDOMRef, useIsMobileDevice} from '@react-spectrum/utils';\nimport {DOMRefValue, ItemProps, Key} from '@react-types/shared';\nimport {FocusScope} from '@react-aria/focus';\nimport {getInteractionModality} from '@react-aria/interactions';\nimport helpStyles from '@adobe/spectrum-css-temp/components/contextualhelp/vars.css';\nimport {nodeContains} from '@react-aria/utils';\nimport {Popover} from './Popover';\nimport React, {JSX, KeyboardEventHandler, ReactElement, useEffect, useRef, useState} from 'react';\nimport ReactDOM from 'react-dom';\nimport styles from '@adobe/spectrum-css-temp/components/menu/vars.css';\nimport {SubmenuTriggerContext, useMenuStateContext} from './context';\nimport {TrayHeaderWrapper} from './Menu';\nimport {useSubmenuTrigger} from '@react-aria/menu';\nimport {useSubmenuTriggerState} from '@react-stately/menu';\n\ninterface MenuDialogTriggerProps {\n /** Whether the menu item is currently unavailable. */\n isUnavailable?: boolean,\n /** The triggering Item and the Dialog, respectively. */\n children: [ReactElement, ReactElement]\n}\n\ninterface InternalMenuDialogTriggerProps extends MenuDialogTriggerProps {\n targetKey: Key\n}\n\nexport interface SpectrumMenuDialogTriggerProps extends MenuDialogTriggerProps {}\n\nfunction ContextualHelpTrigger(props: InternalMenuDialogTriggerProps): ReactElement {\n let {isUnavailable = false, targetKey} = props;\n\n let triggerRef = useRef<HTMLLIElement>(null);\n let popoverRef = useRef<DOMRefValue<HTMLDivElement> | null>(null);\n let {popoverContainer, trayContainerRef, rootMenuTriggerState, menu: parentMenuRef, state} = useMenuStateContext()!;\n let submenuTriggerState = useSubmenuTriggerState({triggerKey: targetKey}, {...rootMenuTriggerState!, ...state});\n let submenuRef = unwrapDOMRef(popoverRef);\n let {submenuTriggerProps, popoverProps} = useSubmenuTrigger({\n parentMenuRef,\n submenuRef,\n type: 'dialog',\n isDisabled: !isUnavailable\n }, submenuTriggerState, triggerRef);\n let isMobile = useIsMobileDevice();\n let [traySubmenuAnimation, setTraySubmenuAnimation] = useState('');\n useEffect(() => {\n if (submenuTriggerState.isOpen) {\n setTraySubmenuAnimation('spectrum-TraySubmenu-enter');\n }\n }, [submenuTriggerState.isOpen]);\n let slots = {};\n if (isUnavailable) {\n slots = {\n dialog: {\n UNSAFE_className: classNames(\n helpStyles,\n 'react-spectrum-ContextualHelp-dialog',\n {\n 'react-spectrum-ContextualHelp-dialog--isMobile': isMobile\n },\n classNames(\n styles,\n {\n 'spectrum-Menu-subdialog': !isMobile,\n [traySubmenuAnimation]: isMobile\n }\n )\n )\n },\n content: {UNSAFE_className: helpStyles['react-spectrum-ContextualHelp-content']},\n footer: {UNSAFE_className: helpStyles['react-spectrum-ContextualHelp-footer']}\n };\n }\n let [trigger] = React.Children.toArray(props.children);\n let [, content] = props.children as [ReactElement, ReactElement];\n\n let onBlurWithin = (e) => {\n if (e.relatedTarget && popoverRef.current && (!nodeContains(popoverRef.current.UNSAFE_getDOMNode(), e.relatedTarget) && !(e.relatedTarget === triggerRef.current && getInteractionModality() === 'pointer'))) {\n if (submenuTriggerState.isOpen) {\n submenuTriggerState.close();\n }\n }\n };\n\n let overlay;\n let tray;\n let onBackButtonPress = () => {\n setTraySubmenuAnimation('spectrum-TraySubmenu-exit');\n setTimeout(() => {\n submenuTriggerState.close();\n if (parentMenuRef.current && !nodeContains(parentMenuRef.current, document.activeElement)) {\n parentMenuRef.current.focus();\n }\n }, 220); // Matches transition duration\n };\n\n if (isMobile) {\n delete submenuTriggerProps.onBlur;\n delete submenuTriggerProps.onHoverChange;\n if (trayContainerRef.current && submenuTriggerState.isOpen) {\n let subDialogKeyDown: KeyboardEventHandler = (e) => {\n switch (e.key) {\n case 'Escape':\n e.stopPropagation();\n onBackButtonPress();\n break;\n }\n };\n\n tray = (\n <TrayHeaderWrapper\n isSubmenu\n parentMenuTreeState={state}\n rootMenuTriggerState={rootMenuTriggerState}\n wrapperKeyDown={subDialogKeyDown}\n onBackButtonPress={onBackButtonPress}>\n {content}\n </TrayHeaderWrapper>\n );\n\n overlay = ReactDOM.createPortal(tray, trayContainerRef.current);\n }\n } else {\n let onDismissButtonPress = () => {\n submenuTriggerState.close();\n parentMenuRef.current?.focus();\n };\n\n overlay = (\n <Popover\n {...popoverProps}\n UNSAFE_style={{clipPath: 'unset', overflow: 'visible', filter: 'unset', borderWidth: '0px'}}\n UNSAFE_className={classNames(styles, 'spectrum-Submenu-popover')}\n onDismissButtonPress={onDismissButtonPress}\n onBlurWithin={onBlurWithin}\n container={popoverContainer!}\n state={submenuTriggerState}\n ref={popoverRef}\n triggerRef={triggerRef}\n placement=\"end top\"\n containerPadding={0}\n hideArrow\n enableBothDismissButtons>\n <FocusScope restoreFocus contain>\n {content}\n </FocusScope>\n </Popover>\n );\n }\n\n return (\n <>\n <SubmenuTriggerContext.Provider value={{isUnavailable, triggerRef, ...submenuTriggerProps}}>{trigger}</SubmenuTriggerContext.Provider>\n <SlotProvider slots={slots}>\n {submenuTriggerState.isOpen && overlay}\n </SlotProvider>\n </>\n );\n}\n\nContextualHelpTrigger.getCollectionNode = function* getCollectionNode<T>(props: ItemProps<T>) {\n let childArray: ReactElement[] = [];\n React.Children.forEach(props.children, child => {\n if (React.isValidElement(child)) {\n childArray.push(child);\n }\n });\n let [trigger] = childArray;\n let [, content] = props.children as [ReactElement, ReactElement];\n\n yield {\n element: React.cloneElement(trigger, {...trigger.props as any, hasChildItems: true, isTrigger: true}),\n wrapper: (element) => (\n <ContextualHelpTrigger key={element.key} targetKey={element.key} {...props}>\n {element}\n {content}\n </ContextualHelpTrigger>\n )\n };\n};\n\nlet _Item = ContextualHelpTrigger as unknown as (props: SpectrumMenuDialogTriggerProps) => JSX.Element;\nexport {_Item as ContextualHelpTrigger};\n"],"names":[],"version":3,"file":"ContextualHelpTrigger.main.js.map"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import "./menu.5b49954a.css";
|
|
2
2
|
import $7Y1uy$contextualhelp_vars_cssmodulejs from "./contextualhelp_vars_css.mjs";
|
|
3
|
+
import {Popover as $bf810f3fb07f8592$export$5b6b19405a83ff9d} from "./Popover.mjs";
|
|
3
4
|
import "./menu.2ec1fdaf.css";
|
|
4
5
|
import $7Y1uy$menu_vars_cssmodulejs from "./menu_vars_css.mjs";
|
|
5
6
|
import {SubmenuTriggerContext as $d94604d52c3e3feb$export$8d97fe02339fc0e3, useMenuStateContext as $d94604d52c3e3feb$export$efa3856fc0e85e7f} from "./context.mjs";
|
|
@@ -7,7 +8,7 @@ import {TrayHeaderWrapper as $49b26f4b606348f6$export$3dfe97b5c32d8d8c} from "./
|
|
|
7
8
|
import {unwrapDOMRef as $7Y1uy$unwrapDOMRef, useIsMobileDevice as $7Y1uy$useIsMobileDevice, classNames as $7Y1uy$classNames, SlotProvider as $7Y1uy$SlotProvider} from "@react-spectrum/utils";
|
|
8
9
|
import {FocusScope as $7Y1uy$FocusScope} from "@react-aria/focus";
|
|
9
10
|
import {getInteractionModality as $7Y1uy$getInteractionModality} from "@react-aria/interactions";
|
|
10
|
-
import {
|
|
11
|
+
import {nodeContains as $7Y1uy$nodeContains} from "@react-aria/utils";
|
|
11
12
|
import $7Y1uy$react, {useRef as $7Y1uy$useRef, useState as $7Y1uy$useState, useEffect as $7Y1uy$useEffect} from "react";
|
|
12
13
|
import $7Y1uy$reactdom from "react-dom";
|
|
13
14
|
import {useSubmenuTrigger as $7Y1uy$useSubmenuTrigger} from "@react-aria/menu";
|
|
@@ -39,6 +40,7 @@ function $parcel$interopDefault(a) {
|
|
|
39
40
|
|
|
40
41
|
|
|
41
42
|
|
|
43
|
+
|
|
42
44
|
function $726fb1b478e356bf$var$ContextualHelpTrigger(props) {
|
|
43
45
|
let { isUnavailable: isUnavailable = false, targetKey: targetKey } = props;
|
|
44
46
|
let triggerRef = (0, $7Y1uy$useRef)(null);
|
|
@@ -84,8 +86,7 @@ function $726fb1b478e356bf$var$ContextualHelpTrigger(props) {
|
|
|
84
86
|
let [trigger] = (0, $7Y1uy$react).Children.toArray(props.children);
|
|
85
87
|
let [, content] = props.children;
|
|
86
88
|
let onBlurWithin = (e)=>{
|
|
87
|
-
|
|
88
|
-
if (e.relatedTarget && popoverRef.current && !((_popoverRef_current_UNSAFE_getDOMNode = popoverRef.current.UNSAFE_getDOMNode()) === null || _popoverRef_current_UNSAFE_getDOMNode === void 0 ? void 0 : _popoverRef_current_UNSAFE_getDOMNode.contains(e.relatedTarget)) && !(e.relatedTarget === triggerRef.current && (0, $7Y1uy$getInteractionModality)() === 'pointer')) {
|
|
89
|
+
if (e.relatedTarget && popoverRef.current && !(0, $7Y1uy$nodeContains)(popoverRef.current.UNSAFE_getDOMNode(), e.relatedTarget) && !(e.relatedTarget === triggerRef.current && (0, $7Y1uy$getInteractionModality)() === 'pointer')) {
|
|
89
90
|
if (submenuTriggerState.isOpen) submenuTriggerState.close();
|
|
90
91
|
}
|
|
91
92
|
};
|
|
@@ -95,7 +96,7 @@ function $726fb1b478e356bf$var$ContextualHelpTrigger(props) {
|
|
|
95
96
|
setTraySubmenuAnimation('spectrum-TraySubmenu-exit');
|
|
96
97
|
setTimeout(()=>{
|
|
97
98
|
submenuTriggerState.close();
|
|
98
|
-
if (parentMenuRef.current && !parentMenuRef.current
|
|
99
|
+
if (parentMenuRef.current && !(0, $7Y1uy$nodeContains)(parentMenuRef.current, document.activeElement)) parentMenuRef.current.focus();
|
|
99
100
|
}, 220); // Matches transition duration
|
|
100
101
|
};
|
|
101
102
|
if (isMobile) {
|
|
@@ -125,7 +126,7 @@ function $726fb1b478e356bf$var$ContextualHelpTrigger(props) {
|
|
|
125
126
|
submenuTriggerState.close();
|
|
126
127
|
(_parentMenuRef_current = parentMenuRef.current) === null || _parentMenuRef_current === void 0 ? void 0 : _parentMenuRef_current.focus();
|
|
127
128
|
};
|
|
128
|
-
overlay = /*#__PURE__*/ (0, $7Y1uy$react).createElement((0, $
|
|
129
|
+
overlay = /*#__PURE__*/ (0, $7Y1uy$react).createElement((0, $bf810f3fb07f8592$export$5b6b19405a83ff9d), {
|
|
129
130
|
...popoverProps,
|
|
130
131
|
UNSAFE_style: {
|
|
131
132
|
clipPath: 'unset',
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import "./menu.5b49954a.css";
|
|
2
2
|
import $7Y1uy$contextualhelp_vars_cssmodulejs from "./contextualhelp_vars_css.module.js";
|
|
3
|
+
import {Popover as $bf810f3fb07f8592$export$5b6b19405a83ff9d} from "./Popover.module.js";
|
|
3
4
|
import "./menu.2ec1fdaf.css";
|
|
4
5
|
import $7Y1uy$menu_vars_cssmodulejs from "./menu_vars_css.module.js";
|
|
5
6
|
import {SubmenuTriggerContext as $d94604d52c3e3feb$export$8d97fe02339fc0e3, useMenuStateContext as $d94604d52c3e3feb$export$efa3856fc0e85e7f} from "./context.module.js";
|
|
@@ -7,7 +8,7 @@ import {TrayHeaderWrapper as $49b26f4b606348f6$export$3dfe97b5c32d8d8c} from "./
|
|
|
7
8
|
import {unwrapDOMRef as $7Y1uy$unwrapDOMRef, useIsMobileDevice as $7Y1uy$useIsMobileDevice, classNames as $7Y1uy$classNames, SlotProvider as $7Y1uy$SlotProvider} from "@react-spectrum/utils";
|
|
8
9
|
import {FocusScope as $7Y1uy$FocusScope} from "@react-aria/focus";
|
|
9
10
|
import {getInteractionModality as $7Y1uy$getInteractionModality} from "@react-aria/interactions";
|
|
10
|
-
import {
|
|
11
|
+
import {nodeContains as $7Y1uy$nodeContains} from "@react-aria/utils";
|
|
11
12
|
import $7Y1uy$react, {useRef as $7Y1uy$useRef, useState as $7Y1uy$useState, useEffect as $7Y1uy$useEffect} from "react";
|
|
12
13
|
import $7Y1uy$reactdom from "react-dom";
|
|
13
14
|
import {useSubmenuTrigger as $7Y1uy$useSubmenuTrigger} from "@react-aria/menu";
|
|
@@ -39,6 +40,7 @@ function $parcel$interopDefault(a) {
|
|
|
39
40
|
|
|
40
41
|
|
|
41
42
|
|
|
43
|
+
|
|
42
44
|
function $726fb1b478e356bf$var$ContextualHelpTrigger(props) {
|
|
43
45
|
let { isUnavailable: isUnavailable = false, targetKey: targetKey } = props;
|
|
44
46
|
let triggerRef = (0, $7Y1uy$useRef)(null);
|
|
@@ -84,8 +86,7 @@ function $726fb1b478e356bf$var$ContextualHelpTrigger(props) {
|
|
|
84
86
|
let [trigger] = (0, $7Y1uy$react).Children.toArray(props.children);
|
|
85
87
|
let [, content] = props.children;
|
|
86
88
|
let onBlurWithin = (e)=>{
|
|
87
|
-
|
|
88
|
-
if (e.relatedTarget && popoverRef.current && !((_popoverRef_current_UNSAFE_getDOMNode = popoverRef.current.UNSAFE_getDOMNode()) === null || _popoverRef_current_UNSAFE_getDOMNode === void 0 ? void 0 : _popoverRef_current_UNSAFE_getDOMNode.contains(e.relatedTarget)) && !(e.relatedTarget === triggerRef.current && (0, $7Y1uy$getInteractionModality)() === 'pointer')) {
|
|
89
|
+
if (e.relatedTarget && popoverRef.current && !(0, $7Y1uy$nodeContains)(popoverRef.current.UNSAFE_getDOMNode(), e.relatedTarget) && !(e.relatedTarget === triggerRef.current && (0, $7Y1uy$getInteractionModality)() === 'pointer')) {
|
|
89
90
|
if (submenuTriggerState.isOpen) submenuTriggerState.close();
|
|
90
91
|
}
|
|
91
92
|
};
|
|
@@ -95,7 +96,7 @@ function $726fb1b478e356bf$var$ContextualHelpTrigger(props) {
|
|
|
95
96
|
setTraySubmenuAnimation('spectrum-TraySubmenu-exit');
|
|
96
97
|
setTimeout(()=>{
|
|
97
98
|
submenuTriggerState.close();
|
|
98
|
-
if (parentMenuRef.current && !parentMenuRef.current
|
|
99
|
+
if (parentMenuRef.current && !(0, $7Y1uy$nodeContains)(parentMenuRef.current, document.activeElement)) parentMenuRef.current.focus();
|
|
99
100
|
}, 220); // Matches transition duration
|
|
100
101
|
};
|
|
101
102
|
if (isMobile) {
|
|
@@ -125,7 +126,7 @@ function $726fb1b478e356bf$var$ContextualHelpTrigger(props) {
|
|
|
125
126
|
submenuTriggerState.close();
|
|
126
127
|
(_parentMenuRef_current = parentMenuRef.current) === null || _parentMenuRef_current === void 0 ? void 0 : _parentMenuRef_current.focus();
|
|
127
128
|
};
|
|
128
|
-
overlay = /*#__PURE__*/ (0, $7Y1uy$react).createElement((0, $
|
|
129
|
+
overlay = /*#__PURE__*/ (0, $7Y1uy$react).createElement((0, $bf810f3fb07f8592$export$5b6b19405a83ff9d), {
|
|
129
130
|
...popoverProps,
|
|
130
131
|
UNSAFE_style: {
|
|
131
132
|
clipPath: 'unset',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;AA6BD,SAAS,4CAAsB,KAAqC;IAClE,IAAI,iBAAC,gBAAgB,kBAAO,SAAS,EAAC,GAAG;IAEzC,IAAI,aAAa,CAAA,GAAA,aAAK,EAAiB;IACvC,IAAI,aAAa,CAAA,GAAA,aAAK,EAAsC;IAC5D,IAAI,oBAAC,gBAAgB,oBAAE,gBAAgB,wBAAE,oBAAoB,EAAE,MAAM,aAAa,SAAE,KAAK,EAAC,GAAG,CAAA,GAAA,yCAAkB;IAC/G,IAAI,sBAAsB,CAAA,GAAA,6BAAqB,EAAE;QAAC,YAAY;IAAS,GAAG;QAAC,GAAG,oBAAoB;QAAG,GAAG,KAAK;IAAA;IAC7G,IAAI,aAAa,CAAA,GAAA,mBAAW,EAAE;IAC9B,IAAI,uBAAC,mBAAmB,gBAAE,YAAY,EAAC,GAAG,CAAA,GAAA,wBAAgB,EAAE;uBAC1D;oBACA;QACA,MAAM;QACN,YAAY,CAAC;IACf,GAAG,qBAAqB;IACxB,IAAI,WAAW,CAAA,GAAA,wBAAgB;IAC/B,IAAI,CA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1F,IAAI,aAA6B,EAAE;IACnC,CAAA,GAAA,YAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,QAAQ,EAAE,CAAA;QACrC,kBAAI,CAAA,GAAA,YAAI,EAAE,cAAc,CAAC,QACvB,WAAW,IAAI,CAAC;IAEpB;IACA,IAAI,CAAC,QAAQ,GAAG;IAChB,IAAI,GAAG,QAAQ,GAAG,MAAM,QAAQ;IAEhC,MAAM;QACJ,uBAAS,CAAA,GAAA,YAAI,EAAE,YAAY,CAAC,SAAS;YAAC,GAAG,QAAQ,KAAK;YAAS,eAAe;YAAM,WAAW;QAAI;QACnG,SAAS,CAAC,wBACR,gCAAC;gBAAsB,KAAK,QAAQ,GAAG;gBAAE,WAAW,QAAQ,GAAG;gBAAG,GAAG,KAAK;eACvE,SACA;IAGP;AACF;AAEA,IAAI,4CAAQ","sources":["packages/@react-spectrum/menu/src/ContextualHelpTrigger.tsx"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {classNames, SlotProvider, unwrapDOMRef, useIsMobileDevice} from '@react-spectrum/utils';\nimport {DOMRefValue, ItemProps, Key} from '@react-types/shared';\nimport {FocusScope} from '@react-aria/focus';\nimport {getInteractionModality} from '@react-aria/interactions';\nimport helpStyles from '@adobe/spectrum-css-temp/components/contextualhelp/vars.css';\nimport {Popover} from '@react-spectrum/overlays';\nimport React, {JSX, KeyboardEventHandler, ReactElement, useEffect, useRef, useState} from 'react';\nimport ReactDOM from 'react-dom';\nimport styles from '@adobe/spectrum-css-temp/components/menu/vars.css';\nimport {SubmenuTriggerContext, useMenuStateContext} from './context';\nimport {TrayHeaderWrapper} from './Menu';\nimport {useSubmenuTrigger} from '@react-aria/menu';\nimport {useSubmenuTriggerState} from '@react-stately/menu';\n\ninterface MenuDialogTriggerProps {\n /** Whether the menu item is currently unavailable. */\n isUnavailable?: boolean,\n /** The triggering Item and the Dialog, respectively. */\n children: [ReactElement, ReactElement]\n}\n\ninterface InternalMenuDialogTriggerProps extends MenuDialogTriggerProps {\n targetKey: Key\n}\n\nexport interface SpectrumMenuDialogTriggerProps extends MenuDialogTriggerProps {}\n\nfunction ContextualHelpTrigger(props: InternalMenuDialogTriggerProps): ReactElement {\n let {isUnavailable = false, targetKey} = props;\n\n let triggerRef = useRef<HTMLLIElement>(null);\n let popoverRef = useRef<DOMRefValue<HTMLDivElement> | null>(null);\n let {popoverContainer, trayContainerRef, rootMenuTriggerState, menu: parentMenuRef, state} = useMenuStateContext()!;\n let submenuTriggerState = useSubmenuTriggerState({triggerKey: targetKey}, {...rootMenuTriggerState!, ...state});\n let submenuRef = unwrapDOMRef(popoverRef);\n let {submenuTriggerProps, popoverProps} = useSubmenuTrigger({\n parentMenuRef,\n submenuRef,\n type: 'dialog',\n isDisabled: !isUnavailable\n }, submenuTriggerState, triggerRef);\n let isMobile = useIsMobileDevice();\n let [traySubmenuAnimation, setTraySubmenuAnimation] = useState('');\n useEffect(() => {\n if (submenuTriggerState.isOpen) {\n setTraySubmenuAnimation('spectrum-TraySubmenu-enter');\n }\n }, [submenuTriggerState.isOpen]);\n let slots = {};\n if (isUnavailable) {\n slots = {\n dialog: {\n UNSAFE_className: classNames(\n helpStyles,\n 'react-spectrum-ContextualHelp-dialog',\n {\n 'react-spectrum-ContextualHelp-dialog--isMobile': isMobile\n },\n classNames(\n styles,\n {\n 'spectrum-Menu-subdialog': !isMobile,\n [traySubmenuAnimation]: isMobile\n }\n )\n )\n },\n content: {UNSAFE_className: helpStyles['react-spectrum-ContextualHelp-content']},\n footer: {UNSAFE_className: helpStyles['react-spectrum-ContextualHelp-footer']}\n };\n }\n let [trigger] = React.Children.toArray(props.children);\n let [, content] = props.children as [ReactElement, ReactElement];\n\n let onBlurWithin = (e) => {\n if (e.relatedTarget && popoverRef.current && (!popoverRef.current.UNSAFE_getDOMNode()?.contains(e.relatedTarget) && !(e.relatedTarget === triggerRef.current && getInteractionModality() === 'pointer'))) {\n if (submenuTriggerState.isOpen) {\n submenuTriggerState.close();\n }\n }\n };\n\n let overlay;\n let tray;\n let onBackButtonPress = () => {\n setTraySubmenuAnimation('spectrum-TraySubmenu-exit');\n setTimeout(() => {\n submenuTriggerState.close();\n if (parentMenuRef.current && !parentMenuRef.current.contains(document.activeElement)) {\n parentMenuRef.current.focus();\n }\n }, 220); // Matches transition duration\n };\n\n if (isMobile) {\n delete submenuTriggerProps.onBlur;\n delete submenuTriggerProps.onHoverChange;\n if (trayContainerRef.current && submenuTriggerState.isOpen) {\n let subDialogKeyDown: KeyboardEventHandler = (e) => {\n switch (e.key) {\n case 'Escape':\n e.stopPropagation();\n onBackButtonPress();\n break;\n }\n };\n\n tray = (\n <TrayHeaderWrapper\n isSubmenu\n parentMenuTreeState={state}\n rootMenuTriggerState={rootMenuTriggerState}\n wrapperKeyDown={subDialogKeyDown}\n onBackButtonPress={onBackButtonPress}>\n {content}\n </TrayHeaderWrapper>\n );\n\n overlay = ReactDOM.createPortal(tray, trayContainerRef.current);\n }\n } else {\n let onDismissButtonPress = () => {\n submenuTriggerState.close();\n parentMenuRef.current?.focus();\n };\n\n overlay = (\n <Popover\n {...popoverProps}\n UNSAFE_style={{clipPath: 'unset', overflow: 'visible', filter: 'unset', borderWidth: '0px'}}\n UNSAFE_className={classNames(styles, 'spectrum-Submenu-popover')}\n onDismissButtonPress={onDismissButtonPress}\n onBlurWithin={onBlurWithin}\n container={popoverContainer!}\n state={submenuTriggerState}\n ref={popoverRef}\n triggerRef={triggerRef}\n placement=\"end top\"\n containerPadding={0}\n hideArrow\n enableBothDismissButtons>\n <FocusScope restoreFocus contain>\n {content}\n </FocusScope>\n </Popover>\n );\n }\n\n return (\n <>\n <SubmenuTriggerContext.Provider value={{isUnavailable, triggerRef, ...submenuTriggerProps}}>{trigger}</SubmenuTriggerContext.Provider>\n <SlotProvider slots={slots}>\n {submenuTriggerState.isOpen && overlay}\n </SlotProvider>\n </>\n );\n}\n\nContextualHelpTrigger.getCollectionNode = function* getCollectionNode<T>(props: ItemProps<T>) {\n let childArray: ReactElement[] = [];\n React.Children.forEach(props.children, child => {\n if (React.isValidElement(child)) {\n childArray.push(child);\n }\n });\n let [trigger] = childArray;\n let [, content] = props.children as [ReactElement, ReactElement];\n\n yield {\n element: React.cloneElement(trigger, {...trigger.props as any, hasChildItems: true, isTrigger: true}),\n wrapper: (element) => (\n <ContextualHelpTrigger key={element.key} targetKey={element.key} {...props}>\n {element}\n {content}\n </ContextualHelpTrigger>\n )\n };\n};\n\nlet _Item = ContextualHelpTrigger as unknown as (props: SpectrumMenuDialogTriggerProps) => JSX.Element;\nexport {_Item as ContextualHelpTrigger};\n"],"names":[],"version":3,"file":"ContextualHelpTrigger.module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;;AA8BD,SAAS,4CAAsB,KAAqC;IAClE,IAAI,iBAAC,gBAAgB,kBAAO,SAAS,EAAC,GAAG;IAEzC,IAAI,aAAa,CAAA,GAAA,aAAK,EAAiB;IACvC,IAAI,aAAa,CAAA,GAAA,aAAK,EAAsC;IAC5D,IAAI,oBAAC,gBAAgB,oBAAE,gBAAgB,wBAAE,oBAAoB,EAAE,MAAM,aAAa,SAAE,KAAK,EAAC,GAAG,CAAA,GAAA,yCAAkB;IAC/G,IAAI,sBAAsB,CAAA,GAAA,6BAAqB,EAAE;QAAC,YAAY;IAAS,GAAG;QAAC,GAAG,oBAAoB;QAAG,GAAG,KAAK;IAAA;IAC7G,IAAI,aAAa,CAAA,GAAA,mBAAW,EAAE;IAC9B,IAAI,uBAAC,mBAAmB,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AAG,mBAAmB;QAAA;OAAI,wBAC7F,gCAAC,CAAA,GAAA,mBAAW;QAAE,OAAO;OAClB,oBAAoB,MAAM,IAAI;AAIvC;AAEA,4CAAsB,iBAAiB,GAAG,UAAU,kBAAqB,KAAmB;IAC1F,IAAI,aAA6B,EAAE;IACnC,CAAA,GAAA,YAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,QAAQ,EAAE,CAAA;QACrC,kBAAI,CAAA,GAAA,YAAI,EAAE,cAAc,CAAC,QACvB,WAAW,IAAI,CAAC;IAEpB;IACA,IAAI,CAAC,QAAQ,GAAG;IAChB,IAAI,GAAG,QAAQ,GAAG,MAAM,QAAQ;IAEhC,MAAM;QACJ,uBAAS,CAAA,GAAA,YAAI,EAAE,YAAY,CAAC,SAAS;YAAC,GAAG,QAAQ,KAAK;YAAS,eAAe;YAAM,WAAW;QAAI;QACnG,SAAS,CAAC,wBACR,gCAAC;gBAAsB,KAAK,QAAQ,GAAG;gBAAE,WAAW,QAAQ,GAAG;gBAAG,GAAG,KAAK;eACvE,SACA;IAGP;AACF;AAEA,IAAI,4CAAQ","sources":["packages/@react-spectrum/menu/src/ContextualHelpTrigger.tsx"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {classNames, SlotProvider, unwrapDOMRef, useIsMobileDevice} from '@react-spectrum/utils';\nimport {DOMRefValue, ItemProps, Key} from '@react-types/shared';\nimport {FocusScope} from '@react-aria/focus';\nimport {getInteractionModality} from '@react-aria/interactions';\nimport helpStyles from '@adobe/spectrum-css-temp/components/contextualhelp/vars.css';\nimport {nodeContains} from '@react-aria/utils';\nimport {Popover} from './Popover';\nimport React, {JSX, KeyboardEventHandler, ReactElement, useEffect, useRef, useState} from 'react';\nimport ReactDOM from 'react-dom';\nimport styles from '@adobe/spectrum-css-temp/components/menu/vars.css';\nimport {SubmenuTriggerContext, useMenuStateContext} from './context';\nimport {TrayHeaderWrapper} from './Menu';\nimport {useSubmenuTrigger} from '@react-aria/menu';\nimport {useSubmenuTriggerState} from '@react-stately/menu';\n\ninterface MenuDialogTriggerProps {\n /** Whether the menu item is currently unavailable. */\n isUnavailable?: boolean,\n /** The triggering Item and the Dialog, respectively. */\n children: [ReactElement, ReactElement]\n}\n\ninterface InternalMenuDialogTriggerProps extends MenuDialogTriggerProps {\n targetKey: Key\n}\n\nexport interface SpectrumMenuDialogTriggerProps extends MenuDialogTriggerProps {}\n\nfunction ContextualHelpTrigger(props: InternalMenuDialogTriggerProps): ReactElement {\n let {isUnavailable = false, targetKey} = props;\n\n let triggerRef = useRef<HTMLLIElement>(null);\n let popoverRef = useRef<DOMRefValue<HTMLDivElement> | null>(null);\n let {popoverContainer, trayContainerRef, rootMenuTriggerState, menu: parentMenuRef, state} = useMenuStateContext()!;\n let submenuTriggerState = useSubmenuTriggerState({triggerKey: targetKey}, {...rootMenuTriggerState!, ...state});\n let submenuRef = unwrapDOMRef(popoverRef);\n let {submenuTriggerProps, popoverProps} = useSubmenuTrigger({\n parentMenuRef,\n submenuRef,\n type: 'dialog',\n isDisabled: !isUnavailable\n }, submenuTriggerState, triggerRef);\n let isMobile = useIsMobileDevice();\n let [traySubmenuAnimation, setTraySubmenuAnimation] = useState('');\n useEffect(() => {\n if (submenuTriggerState.isOpen) {\n setTraySubmenuAnimation('spectrum-TraySubmenu-enter');\n }\n }, [submenuTriggerState.isOpen]);\n let slots = {};\n if (isUnavailable) {\n slots = {\n dialog: {\n UNSAFE_className: classNames(\n helpStyles,\n 'react-spectrum-ContextualHelp-dialog',\n {\n 'react-spectrum-ContextualHelp-dialog--isMobile': isMobile\n },\n classNames(\n styles,\n {\n 'spectrum-Menu-subdialog': !isMobile,\n [traySubmenuAnimation]: isMobile\n }\n )\n )\n },\n content: {UNSAFE_className: helpStyles['react-spectrum-ContextualHelp-content']},\n footer: {UNSAFE_className: helpStyles['react-spectrum-ContextualHelp-footer']}\n };\n }\n let [trigger] = React.Children.toArray(props.children);\n let [, content] = props.children as [ReactElement, ReactElement];\n\n let onBlurWithin = (e) => {\n if (e.relatedTarget && popoverRef.current && (!nodeContains(popoverRef.current.UNSAFE_getDOMNode(), e.relatedTarget) && !(e.relatedTarget === triggerRef.current && getInteractionModality() === 'pointer'))) {\n if (submenuTriggerState.isOpen) {\n submenuTriggerState.close();\n }\n }\n };\n\n let overlay;\n let tray;\n let onBackButtonPress = () => {\n setTraySubmenuAnimation('spectrum-TraySubmenu-exit');\n setTimeout(() => {\n submenuTriggerState.close();\n if (parentMenuRef.current && !nodeContains(parentMenuRef.current, document.activeElement)) {\n parentMenuRef.current.focus();\n }\n }, 220); // Matches transition duration\n };\n\n if (isMobile) {\n delete submenuTriggerProps.onBlur;\n delete submenuTriggerProps.onHoverChange;\n if (trayContainerRef.current && submenuTriggerState.isOpen) {\n let subDialogKeyDown: KeyboardEventHandler = (e) => {\n switch (e.key) {\n case 'Escape':\n e.stopPropagation();\n onBackButtonPress();\n break;\n }\n };\n\n tray = (\n <TrayHeaderWrapper\n isSubmenu\n parentMenuTreeState={state}\n rootMenuTriggerState={rootMenuTriggerState}\n wrapperKeyDown={subDialogKeyDown}\n onBackButtonPress={onBackButtonPress}>\n {content}\n </TrayHeaderWrapper>\n );\n\n overlay = ReactDOM.createPortal(tray, trayContainerRef.current);\n }\n } else {\n let onDismissButtonPress = () => {\n submenuTriggerState.close();\n parentMenuRef.current?.focus();\n };\n\n overlay = (\n <Popover\n {...popoverProps}\n UNSAFE_style={{clipPath: 'unset', overflow: 'visible', filter: 'unset', borderWidth: '0px'}}\n UNSAFE_className={classNames(styles, 'spectrum-Submenu-popover')}\n onDismissButtonPress={onDismissButtonPress}\n onBlurWithin={onBlurWithin}\n container={popoverContainer!}\n state={submenuTriggerState}\n ref={popoverRef}\n triggerRef={triggerRef}\n placement=\"end top\"\n containerPadding={0}\n hideArrow\n enableBothDismissButtons>\n <FocusScope restoreFocus contain>\n {content}\n </FocusScope>\n </Popover>\n );\n }\n\n return (\n <>\n <SubmenuTriggerContext.Provider value={{isUnavailable, triggerRef, ...submenuTriggerProps}}>{trigger}</SubmenuTriggerContext.Provider>\n <SlotProvider slots={slots}>\n {submenuTriggerState.isOpen && overlay}\n </SlotProvider>\n </>\n );\n}\n\nContextualHelpTrigger.getCollectionNode = function* getCollectionNode<T>(props: ItemProps<T>) {\n let childArray: ReactElement[] = [];\n React.Children.forEach(props.children, child => {\n if (React.isValidElement(child)) {\n childArray.push(child);\n }\n });\n let [trigger] = childArray;\n let [, content] = props.children as [ReactElement, ReactElement];\n\n yield {\n element: React.cloneElement(trigger, {...trigger.props as any, hasChildItems: true, isTrigger: true}),\n wrapper: (element) => (\n <ContextualHelpTrigger key={element.key} targetKey={element.key} {...props}>\n {element}\n {content}\n </ContextualHelpTrigger>\n )\n };\n};\n\nlet _Item = ContextualHelpTrigger as unknown as (props: SpectrumMenuDialogTriggerProps) => JSX.Element;\nexport {_Item as ContextualHelpTrigger};\n"],"names":[],"version":3,"file":"ContextualHelpTrigger.module.js.map"}
|
package/dist/Menu.main.js
CHANGED
|
@@ -72,7 +72,7 @@ const $63a7dff9cbe2d046$export$d9b273488cd8ce6f = /*#__PURE__*/ (0, ($parcel$int
|
|
|
72
72
|
left: 0
|
|
73
73
|
});
|
|
74
74
|
let prevPopoverContainer = (0, $hl8gx$react.useRef)(null);
|
|
75
|
-
(0, $hl8gx$
|
|
75
|
+
(0, $hl8gx$reactariautils.useLayoutEffect)(()=>{
|
|
76
76
|
if (popoverContainer && prevPopoverContainer.current !== popoverContainer && leftOffset.left === 0) {
|
|
77
77
|
prevPopoverContainer.current = popoverContainer;
|
|
78
78
|
let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AAa;QAAE,cAAc;YAAC,QAAQ;QAAO;uBAE9H,0DAAC;QAAG,IAAI;QAAW,WAAW,CAAA,GAAA,oCAAS,EAAE,CAAA,GAAA,mDAAK,GAAG;OAA8B,kBAGlF;AAKX","sources":["packages/@react-spectrum/menu/src/Menu.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {ActionButton} from '@react-spectrum/button';\nimport ArrowDownSmall from '@spectrum-icons/ui/ArrowDownSmall';\nimport {classNames, useDOMRef, useIsMobileDevice, useStyleProps} from '@react-spectrum/utils';\nimport {DOMRef} from '@react-types/shared';\nimport {FocusScope} from '@react-aria/focus';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {MenuContext, MenuStateContext, useMenuStateContext} from './context';\nimport {MenuItem} from './MenuItem';\nimport {MenuSection} from './MenuSection';\nimport {mergeProps, useLayoutEffect, useSlotId, useSyncRef} from '@react-aria/utils';\nimport React, {KeyboardEventHandler, ReactElement, ReactNode, RefObject, useContext, useEffect, useRef, useState} from 'react';\nimport {RootMenuTriggerState} from '@react-stately/menu';\nimport {SpectrumMenuProps} from '@react-types/menu';\nimport styles from '@adobe/spectrum-css-temp/components/menu/vars.css';\nimport {TreeState, useTreeState} from '@react-stately/tree';\nimport {useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useMenu} from '@react-aria/menu';\n\n/**\n * Menus display a list of actions or options that a user can choose.\n */\n// forwardRef doesn't support generic parameters, so cast the result to the correct type\n// https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref\nexport const Menu = React.forwardRef(function Menu<T extends object>(props: SpectrumMenuProps<T>, ref: DOMRef<HTMLDivElement>) {\n let isSubmenu = true;\n let contextProps = useContext(MenuContext);\n let parentMenuContext = useMenuStateContext();\n let {rootMenuTriggerState, state: parentMenuTreeState} = parentMenuContext || {rootMenuTriggerState: contextProps.state};\n if (!parentMenuContext) {\n isSubmenu = false;\n }\n let completeProps = {\n ...mergeProps(contextProps, props)\n };\n let domRef = useDOMRef(ref);\n let [popoverContainer, setPopoverContainer] = useState<HTMLElement | null>(null);\n let trayContainerRef = useRef<HTMLDivElement | null>(null);\n let state = useTreeState(completeProps);\n let submenuRef = useRef<HTMLDivElement>(null);\n let {menuProps} = useMenu(completeProps, state, domRef);\n let {styleProps} = useStyleProps(completeProps);\n useSyncRef(contextProps, domRef);\n let [leftOffset, setLeftOffset] = useState({left: 0});\n let prevPopoverContainer = useRef<HTMLElement | null>(null);\n useEffect(() => {\n if (popoverContainer && prevPopoverContainer.current !== popoverContainer && leftOffset.left === 0) {\n prevPopoverContainer.current = popoverContainer;\n let {left} = popoverContainer.getBoundingClientRect();\n setLeftOffset({left: -1 * left});\n }\n }, [leftOffset, popoverContainer]);\n\n let menuLevel = contextProps.submenuLevel ?? -1;\n let nextMenuLevelKey = rootMenuTriggerState?.expandedKeysStack[menuLevel + 1];\n let hasOpenSubmenu = false;\n if (nextMenuLevelKey != null) {\n let nextMenuLevel = state.collection.getItem(nextMenuLevelKey);\n hasOpenSubmenu = nextMenuLevel != null;\n }\n\n return (\n <MenuStateContext.Provider value={{popoverContainer, trayContainerRef, menu: domRef, submenu: submenuRef, rootMenuTriggerState, state}}>\n <div style={{height: hasOpenSubmenu ? '100%' : undefined}} ref={trayContainerRef} />\n <FocusScope>\n <TrayHeaderWrapper\n onBackButtonPress={contextProps.onBackButtonPress}\n hasOpenSubmenu={hasOpenSubmenu}\n isSubmenu={isSubmenu}\n parentMenuTreeState={parentMenuTreeState}\n rootMenuTriggerState={rootMenuTriggerState}\n menuRef={domRef}>\n <div\n {...menuProps}\n style={mergeProps(styleProps.style, menuProps.style)}\n ref={domRef}\n className={\n classNames(\n styles,\n 'spectrum-Menu',\n styleProps.className\n )\n }>\n {[...state.collection].map(item => {\n if (item.type === 'section') {\n return (\n <MenuSection\n key={item.key}\n item={item}\n state={state} />\n );\n }\n\n let menuItem = (\n <MenuItem\n key={item.key}\n item={item}\n state={state} />\n );\n\n if (item.wrapper) {\n menuItem = item.wrapper(menuItem);\n }\n\n return menuItem;\n })}\n </div>\n </TrayHeaderWrapper>\n {rootMenuTriggerState?.isOpen && <div ref={setPopoverContainer} style={{width: '100vw', position: 'absolute', top: -5, ...leftOffset}} /> }\n </FocusScope>\n </MenuStateContext.Provider>\n );\n}) as <T>(props: SpectrumMenuProps<T> & {ref?: DOMRef<HTMLDivElement>}) => ReactElement;\n\nexport function TrayHeaderWrapper(props: {\n children: ReactNode,\n isSubmenu?: boolean,\n hasOpenSubmenu?: boolean,\n parentMenuTreeState?: TreeState<any>,\n rootMenuTriggerState?: RootMenuTriggerState,\n onBackButtonPress?: (() => void),\n wrapperKeyDown?: KeyboardEventHandler<HTMLDivElement> | undefined,\n menuRef?: RefObject<HTMLDivElement | null>\n}): ReactNode {\n let {children, isSubmenu, hasOpenSubmenu, parentMenuTreeState, rootMenuTriggerState, onBackButtonPress, wrapperKeyDown, menuRef} = props;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/menu');\n let lastKey = rootMenuTriggerState?.expandedKeysStack.slice(-1)[0];\n let backButtonText = '';\n if (lastKey != null) {\n backButtonText = parentMenuTreeState?.collection.getItem(lastKey)?.textValue ?? '';\n }\n let backButtonLabel = stringFormatter.format('backButton', {\n prevMenuButton: backButtonText ?? ''\n });\n let headingId = useSlotId();\n let isMobile = useIsMobileDevice();\n let {direction} = useLocale();\n\n let [traySubmenuAnimation, setTraySubmenuAnimation] = useState('');\n useLayoutEffect(() => {\n if (!hasOpenSubmenu) {\n setTraySubmenuAnimation('spectrum-TraySubmenu-enter');\n }\n }, [hasOpenSubmenu, isMobile]);\n\n let timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n let handleBackButtonPress = () => {\n setTraySubmenuAnimation('spectrum-TraySubmenu-exit');\n timeoutRef.current = setTimeout(() => {\n onBackButtonPress?.();\n }, 220); // Matches transition duration\n };\n\n useEffect(() => {\n return () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n };\n }, []);\n\n // When opening submenu in tray, focus the first item in the submenu after animation completes\n // This fixes an issue with iOS VO where the closed submenu was getting focus\n let focusTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n useEffect(() => {\n if (isMobile && isSubmenu && !hasOpenSubmenu && traySubmenuAnimation === 'spectrum-TraySubmenu-enter') {\n focusTimeoutRef.current = setTimeout(() => {\n let firstItem = menuRef?.current?.querySelector('[role=\"menuitem\"], [role=\"menuitemcheckbox\"], [role=\"menuitemradio\"]') as HTMLElement;\n firstItem?.focus();\n }, 220);\n }\n return () => {\n if (focusTimeoutRef.current) {\n clearTimeout(focusTimeoutRef.current);\n }\n };\n }, [hasOpenSubmenu, isMobile, isSubmenu, menuRef, traySubmenuAnimation]);\n\n return (\n <>\n <div\n role={headingId ? 'dialog' : undefined}\n aria-labelledby={headingId}\n aria-hidden={isMobile && hasOpenSubmenu}\n data-testid=\"menu-wrapper\"\n className={\n classNames(\n styles,\n 'spectrum-Menu-wrapper',\n {\n 'spectrum-Menu-wrapper--isMobile': isMobile,\n 'is-expanded': hasOpenSubmenu,\n [traySubmenuAnimation]: isMobile\n }\n )\n }>\n <div role=\"presentation\" className={classNames(styles, 'spectrum-Submenu-wrapper', {'spectrum-Submenu-wrapper--isMobile': isMobile})} onKeyDown={wrapperKeyDown}>\n {isMobile && isSubmenu && !hasOpenSubmenu && (\n <div className={classNames(styles, 'spectrum-Submenu-headingWrapper')}>\n <ActionButton\n aria-label={backButtonLabel}\n isQuiet\n onPress={handleBackButtonPress}>\n {/* We don't have a ArrowLeftSmall so make due with ArrowDownSmall and transforms */}\n {direction === 'rtl' ? <ArrowDownSmall UNSAFE_style={{rotate: '270deg'}} /> : <ArrowDownSmall UNSAFE_style={{rotate: '90deg'}} />}\n </ActionButton>\n <h1 id={headingId} className={classNames(styles, 'spectrum-Submenu-heading')}>{backButtonText}</h1>\n </div>\n )}\n {children}\n </div>\n </div>\n </>\n );\n}\n"],"names":[],"version":3,"file":"Menu.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;;;AA0BM,MAAM,0DAAO,CAAA,GAAA,sCAAI,EAAE,UAAU,CAAC,SAAS,KAAuB,KAA2B,EAAE,GAA2B;IAC3H,IAAI,YAAY;IAChB,IAAI,eAAe,CAAA,GAAA,uBAAS,EAAE,CAAA,GAAA,qCAAU;IACxC,IAAI,oBAAoB,CAAA,GAAA,6CAAkB;IAC1C,IAAI,wBAAC,oBAAoB,EAAE,OAAO,mBAAmB,EAAC,GAAG,qBAAqB;QAAC,sBAAsB,aAAa,KAAK;IAAA;IACvH,IAAI,CAAC,mBACH,YAAY;IAEd,IAAI,gBAAgB;QAClB,GAAG,CAAA,GAAA,gCAAS,EAAE,cAAc,MAAM;IACpC;IACA,IAAI,SAAS,CAAA,GAAA,mCAAQ,EAAE;IACvB,IAAI,CAAC,kBAAkB,oBAAoB,GAAG,CAAA,GAAA,qBAAO,EAAsB;IAC3E,IAAI,mBAAmB,CAAA,GAAA,mBAAK,EAAyB;IACrD,IAAI,QAAQ,CAAA,GAAA,oCAAW,EAAE;IACzB,IAAI,aAAa,CAAA,GAAA,mBAAK,EAAkB;IACxC,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,4BAAM,EAAE,eAAe,OAAO;IAChD,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,uCAAY,EAAE;IACjC,CAAA,GAAA,gCAAS,EAAE,cAAc;IACzB,IAAI,CAAC,YAAY,cAAc,GAAG,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DAAK,GAAG;qBACjC,0DAAC,CAAA,GAAA,uCAAW;QACV,cAAY;QACZ,SAAA;QACA,SAAS;OAER,cAAc,sBAAQ,0DAAC,CAAA,GAAA,8DAAa;QAAE,cAAc;YAAC,QAAQ;QAAQ;uBAAQ,0DAAC,CAAA,GAAA,8DAAa;QAAE,cAAc;YAAC,QAAQ;QAAO;uBAE9H,0DAAC;QAAG,IAAI;QAAW,WAAW,CAAA,GAAA,oCAAS,EAAE,CAAA,GAAA,mDAAK,GAAG;OAA8B,kBAGlF;AAKX","sources":["packages/@react-spectrum/menu/src/Menu.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {ActionButton} from '@react-spectrum/button';\nimport ArrowDownSmall from '@spectrum-icons/ui/ArrowDownSmall';\nimport {classNames, useDOMRef, useIsMobileDevice, useStyleProps} from '@react-spectrum/utils';\nimport {DOMRef} from '@react-types/shared';\nimport {FocusScope} from '@react-aria/focus';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {MenuContext, MenuStateContext, useMenuStateContext} from './context';\nimport {MenuItem} from './MenuItem';\nimport {MenuSection} from './MenuSection';\nimport {mergeProps, useLayoutEffect, useSlotId, useSyncRef} from '@react-aria/utils';\nimport React, {KeyboardEventHandler, ReactElement, ReactNode, RefObject, useContext, useEffect, useRef, useState} from 'react';\nimport {RootMenuTriggerState} from '@react-stately/menu';\nimport {SpectrumMenuProps} from '@react-types/menu';\nimport styles from '@adobe/spectrum-css-temp/components/menu/vars.css';\nimport {TreeState, useTreeState} from '@react-stately/tree';\nimport {useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useMenu} from '@react-aria/menu';\n\n/**\n * Menus display a list of actions or options that a user can choose.\n */\n// forwardRef doesn't support generic parameters, so cast the result to the correct type\n// https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref\nexport const Menu = React.forwardRef(function Menu<T extends object>(props: SpectrumMenuProps<T>, ref: DOMRef<HTMLDivElement>) {\n let isSubmenu = true;\n let contextProps = useContext(MenuContext);\n let parentMenuContext = useMenuStateContext();\n let {rootMenuTriggerState, state: parentMenuTreeState} = parentMenuContext || {rootMenuTriggerState: contextProps.state};\n if (!parentMenuContext) {\n isSubmenu = false;\n }\n let completeProps = {\n ...mergeProps(contextProps, props)\n };\n let domRef = useDOMRef(ref);\n let [popoverContainer, setPopoverContainer] = useState<HTMLElement | null>(null);\n let trayContainerRef = useRef<HTMLDivElement | null>(null);\n let state = useTreeState(completeProps);\n let submenuRef = useRef<HTMLDivElement>(null);\n let {menuProps} = useMenu(completeProps, state, domRef);\n let {styleProps} = useStyleProps(completeProps);\n useSyncRef(contextProps, domRef);\n let [leftOffset, setLeftOffset] = useState({left: 0});\n let prevPopoverContainer = useRef<HTMLElement | null>(null);\n\n useLayoutEffect(() => {\n if (popoverContainer && prevPopoverContainer.current !== popoverContainer && leftOffset.left === 0) {\n prevPopoverContainer.current = popoverContainer;\n let {left} = popoverContainer.getBoundingClientRect();\n setLeftOffset({left: -1 * left});\n }\n }, [leftOffset, popoverContainer]);\n\n let menuLevel = contextProps.submenuLevel ?? -1;\n let nextMenuLevelKey = rootMenuTriggerState?.expandedKeysStack[menuLevel + 1];\n let hasOpenSubmenu = false;\n if (nextMenuLevelKey != null) {\n let nextMenuLevel = state.collection.getItem(nextMenuLevelKey);\n hasOpenSubmenu = nextMenuLevel != null;\n }\n\n return (\n <MenuStateContext.Provider value={{popoverContainer, trayContainerRef, menu: domRef, submenu: submenuRef, rootMenuTriggerState, state}}>\n <div style={{height: hasOpenSubmenu ? '100%' : undefined}} ref={trayContainerRef} />\n <FocusScope>\n <TrayHeaderWrapper\n onBackButtonPress={contextProps.onBackButtonPress}\n hasOpenSubmenu={hasOpenSubmenu}\n isSubmenu={isSubmenu}\n parentMenuTreeState={parentMenuTreeState}\n rootMenuTriggerState={rootMenuTriggerState}\n menuRef={domRef}>\n <div\n {...menuProps}\n style={mergeProps(styleProps.style, menuProps.style)}\n ref={domRef}\n className={\n classNames(\n styles,\n 'spectrum-Menu',\n styleProps.className\n )\n }>\n {[...state.collection].map(item => {\n if (item.type === 'section') {\n return (\n <MenuSection\n key={item.key}\n item={item}\n state={state} />\n );\n }\n\n let menuItem = (\n <MenuItem\n key={item.key}\n item={item}\n state={state} />\n );\n\n if (item.wrapper) {\n menuItem = item.wrapper(menuItem);\n }\n\n return menuItem;\n })}\n </div>\n </TrayHeaderWrapper>\n {rootMenuTriggerState?.isOpen && <div ref={setPopoverContainer} style={{width: '100vw', position: 'absolute', top: -5, ...leftOffset}} /> }\n </FocusScope>\n </MenuStateContext.Provider>\n );\n}) as <T>(props: SpectrumMenuProps<T> & {ref?: DOMRef<HTMLDivElement>}) => ReactElement;\n\nexport function TrayHeaderWrapper(props: {\n children: ReactNode,\n isSubmenu?: boolean,\n hasOpenSubmenu?: boolean,\n parentMenuTreeState?: TreeState<any>,\n rootMenuTriggerState?: RootMenuTriggerState,\n onBackButtonPress?: (() => void),\n wrapperKeyDown?: KeyboardEventHandler<HTMLDivElement> | undefined,\n menuRef?: RefObject<HTMLDivElement | null>\n}): ReactNode {\n let {children, isSubmenu, hasOpenSubmenu, parentMenuTreeState, rootMenuTriggerState, onBackButtonPress, wrapperKeyDown, menuRef} = props;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/menu');\n let lastKey = rootMenuTriggerState?.expandedKeysStack.slice(-1)[0];\n let backButtonText = '';\n if (lastKey != null) {\n backButtonText = parentMenuTreeState?.collection.getItem(lastKey)?.textValue ?? '';\n }\n let backButtonLabel = stringFormatter.format('backButton', {\n prevMenuButton: backButtonText ?? ''\n });\n let headingId = useSlotId();\n let isMobile = useIsMobileDevice();\n let {direction} = useLocale();\n\n let [traySubmenuAnimation, setTraySubmenuAnimation] = useState('');\n useLayoutEffect(() => {\n if (!hasOpenSubmenu) {\n setTraySubmenuAnimation('spectrum-TraySubmenu-enter');\n }\n }, [hasOpenSubmenu, isMobile]);\n\n let timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n let handleBackButtonPress = () => {\n setTraySubmenuAnimation('spectrum-TraySubmenu-exit');\n timeoutRef.current = setTimeout(() => {\n onBackButtonPress?.();\n }, 220); // Matches transition duration\n };\n\n useEffect(() => {\n return () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n };\n }, []);\n\n // When opening submenu in tray, focus the first item in the submenu after animation completes\n // This fixes an issue with iOS VO where the closed submenu was getting focus\n let focusTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n useEffect(() => {\n if (isMobile && isSubmenu && !hasOpenSubmenu && traySubmenuAnimation === 'spectrum-TraySubmenu-enter') {\n focusTimeoutRef.current = setTimeout(() => {\n let firstItem = menuRef?.current?.querySelector('[role=\"menuitem\"], [role=\"menuitemcheckbox\"], [role=\"menuitemradio\"]') as HTMLElement;\n firstItem?.focus();\n }, 220);\n }\n return () => {\n if (focusTimeoutRef.current) {\n clearTimeout(focusTimeoutRef.current);\n }\n };\n }, [hasOpenSubmenu, isMobile, isSubmenu, menuRef, traySubmenuAnimation]);\n\n return (\n <>\n <div\n role={headingId ? 'dialog' : undefined}\n aria-labelledby={headingId}\n aria-hidden={isMobile && hasOpenSubmenu}\n data-testid=\"menu-wrapper\"\n className={\n classNames(\n styles,\n 'spectrum-Menu-wrapper',\n {\n 'spectrum-Menu-wrapper--isMobile': isMobile,\n 'is-expanded': hasOpenSubmenu,\n [traySubmenuAnimation]: isMobile\n }\n )\n }>\n <div role=\"presentation\" className={classNames(styles, 'spectrum-Submenu-wrapper', {'spectrum-Submenu-wrapper--isMobile': isMobile})} onKeyDown={wrapperKeyDown}>\n {isMobile && isSubmenu && !hasOpenSubmenu && (\n <div className={classNames(styles, 'spectrum-Submenu-headingWrapper')}>\n <ActionButton\n aria-label={backButtonLabel}\n isQuiet\n onPress={handleBackButtonPress}>\n {/* We don't have a ArrowLeftSmall so make due with ArrowDownSmall and transforms */}\n {direction === 'rtl' ? <ArrowDownSmall UNSAFE_style={{rotate: '270deg'}} /> : <ArrowDownSmall UNSAFE_style={{rotate: '90deg'}} />}\n </ActionButton>\n <h1 id={headingId} className={classNames(styles, 'spectrum-Submenu-heading')}>{backButtonText}</h1>\n </div>\n )}\n {children}\n </div>\n </div>\n </>\n );\n}\n"],"names":[],"version":3,"file":"Menu.main.js.map"}
|
package/dist/Menu.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import {ActionButton as $4oXwn$ActionButton} from "@react-spectrum/button";
|
|
|
8
8
|
import $4oXwn$spectrumiconsuiArrowDownSmall from "@spectrum-icons/ui/ArrowDownSmall";
|
|
9
9
|
import {useDOMRef as $4oXwn$useDOMRef, useStyleProps as $4oXwn$useStyleProps, classNames as $4oXwn$classNames, useIsMobileDevice as $4oXwn$useIsMobileDevice} from "@react-spectrum/utils";
|
|
10
10
|
import {FocusScope as $4oXwn$FocusScope} from "@react-aria/focus";
|
|
11
|
-
import {mergeProps as $4oXwn$mergeProps, useSyncRef as $4oXwn$useSyncRef,
|
|
11
|
+
import {mergeProps as $4oXwn$mergeProps, useSyncRef as $4oXwn$useSyncRef, useLayoutEffect as $4oXwn$useLayoutEffect, useSlotId as $4oXwn$useSlotId} from "@react-aria/utils";
|
|
12
12
|
import $4oXwn$react, {useContext as $4oXwn$useContext, useState as $4oXwn$useState, useRef as $4oXwn$useRef, useEffect as $4oXwn$useEffect} from "react";
|
|
13
13
|
import {useTreeState as $4oXwn$useTreeState} from "@react-stately/tree";
|
|
14
14
|
import {useLocalizedStringFormatter as $4oXwn$useLocalizedStringFormatter, useLocale as $4oXwn$useLocale} from "@react-aria/i18n";
|
|
@@ -65,7 +65,7 @@ const $49b26f4b606348f6$export$d9b273488cd8ce6f = /*#__PURE__*/ (0, $4oXwn$react
|
|
|
65
65
|
left: 0
|
|
66
66
|
});
|
|
67
67
|
let prevPopoverContainer = (0, $4oXwn$useRef)(null);
|
|
68
|
-
(0, $4oXwn$
|
|
68
|
+
(0, $4oXwn$useLayoutEffect)(()=>{
|
|
69
69
|
if (popoverContainer && prevPopoverContainer.current !== popoverContainer && leftOffset.left === 0) {
|
|
70
70
|
prevPopoverContainer.current = popoverContainer;
|
|
71
71
|
let { left: left } = popoverContainer.getBoundingClientRect();
|
package/dist/Menu.module.js
CHANGED
|
@@ -8,7 +8,7 @@ import {ActionButton as $4oXwn$ActionButton} from "@react-spectrum/button";
|
|
|
8
8
|
import $4oXwn$spectrumiconsuiArrowDownSmall from "@spectrum-icons/ui/ArrowDownSmall";
|
|
9
9
|
import {useDOMRef as $4oXwn$useDOMRef, useStyleProps as $4oXwn$useStyleProps, classNames as $4oXwn$classNames, useIsMobileDevice as $4oXwn$useIsMobileDevice} from "@react-spectrum/utils";
|
|
10
10
|
import {FocusScope as $4oXwn$FocusScope} from "@react-aria/focus";
|
|
11
|
-
import {mergeProps as $4oXwn$mergeProps, useSyncRef as $4oXwn$useSyncRef,
|
|
11
|
+
import {mergeProps as $4oXwn$mergeProps, useSyncRef as $4oXwn$useSyncRef, useLayoutEffect as $4oXwn$useLayoutEffect, useSlotId as $4oXwn$useSlotId} from "@react-aria/utils";
|
|
12
12
|
import $4oXwn$react, {useContext as $4oXwn$useContext, useState as $4oXwn$useState, useRef as $4oXwn$useRef, useEffect as $4oXwn$useEffect} from "react";
|
|
13
13
|
import {useTreeState as $4oXwn$useTreeState} from "@react-stately/tree";
|
|
14
14
|
import {useLocalizedStringFormatter as $4oXwn$useLocalizedStringFormatter, useLocale as $4oXwn$useLocale} from "@react-aria/i18n";
|
|
@@ -65,7 +65,7 @@ const $49b26f4b606348f6$export$d9b273488cd8ce6f = /*#__PURE__*/ (0, $4oXwn$react
|
|
|
65
65
|
left: 0
|
|
66
66
|
});
|
|
67
67
|
let prevPopoverContainer = (0, $4oXwn$useRef)(null);
|
|
68
|
-
(0, $4oXwn$
|
|
68
|
+
(0, $4oXwn$useLayoutEffect)(()=>{
|
|
69
69
|
if (popoverContainer && prevPopoverContainer.current !== popoverContainer && leftOffset.left === 0) {
|
|
70
70
|
prevPopoverContainer.current = popoverContainer;
|
|
71
71
|
let { left: left } = popoverContainer.getBoundingClientRect();
|
package/dist/Menu.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;;;AA0BM,MAAM,0DAAO,CAAA,GAAA,YAAI,EAAE,UAAU,CAAC,SAAS,KAAuB,KAA2B,EAAE,GAA2B;IAC3H,IAAI,YAAY;IAChB,IAAI,eAAe,CAAA,GAAA,iBAAS,EAAE,CAAA,GAAA,yCAAU;IACxC,IAAI,oBAAoB,CAAA,GAAA,yCAAkB;IAC1C,IAAI,wBAAC,oBAAoB,EAAE,OAAO,mBAAmB,EAAC,GAAG,qBAAqB;QAAC,sBAAsB,aAAa,KAAK;IAAA;IACvH,IAAI,CAAC,mBACH,YAAY;IAEd,IAAI,gBAAgB;QAClB,GAAG,CAAA,GAAA,iBAAS,EAAE,cAAc,MAAM;IACpC;IACA,IAAI,SAAS,CAAA,GAAA,gBAAQ,EAAE;IACvB,IAAI,CAAC,kBAAkB,oBAAoB,GAAG,CAAA,GAAA,eAAO,EAAsB;IAC3E,IAAI,mBAAmB,CAAA,GAAA,aAAK,EAAyB;IACrD,IAAI,QAAQ,CAAA,GAAA,mBAAW,EAAE;IACzB,IAAI,aAAa,CAAA,GAAA,aAAK,EAAkB;IACxC,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,cAAM,EAAE,eAAe,OAAO;IAChD,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,o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Y,aAAa,CAAC,gCACzB,gCAAC;QAAI,WAAW,CAAA,GAAA,iBAAS,EAAE,CAAA,GAAA,sDAAK,GAAG;qBACjC,gCAAC,CAAA,GAAA,mBAAW;QACV,cAAY;QACZ,SAAA;QACA,SAAS;OAER,cAAc,sBAAQ,gCAAC,CAAA,GAAA,oCAAa;QAAE,cAAc;YAAC,QAAQ;QAAQ;uBAAQ,gCAAC,CAAA,GAAA,oCAAa;QAAE,cAAc;YAAC,QAAQ;QAAO;uBAE9H,gCAAC;QAAG,IAAI;QAAW,WAAW,CAAA,GAAA,iBAAS,EAAE,CAAA,GAAA,sDAAK,GAAG;OAA8B,kBAGlF;AAKX","sources":["packages/@react-spectrum/menu/src/Menu.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {ActionButton} from '@react-spectrum/button';\nimport ArrowDownSmall from '@spectrum-icons/ui/ArrowDownSmall';\nimport {classNames, useDOMRef, useIsMobileDevice, useStyleProps} from '@react-spectrum/utils';\nimport {DOMRef} from '@react-types/shared';\nimport {FocusScope} from '@react-aria/focus';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {MenuContext, MenuStateContext, useMenuStateContext} from './context';\nimport {MenuItem} from './MenuItem';\nimport {MenuSection} from './MenuSection';\nimport {mergeProps, useLayoutEffect, useSlotId, useSyncRef} from '@react-aria/utils';\nimport React, {KeyboardEventHandler, ReactElement, ReactNode, RefObject, useContext, useEffect, useRef, useState} from 'react';\nimport {RootMenuTriggerState} from '@react-stately/menu';\nimport {SpectrumMenuProps} from '@react-types/menu';\nimport styles from '@adobe/spectrum-css-temp/components/menu/vars.css';\nimport {TreeState, useTreeState} from '@react-stately/tree';\nimport {useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useMenu} from '@react-aria/menu';\n\n/**\n * Menus display a list of actions or options that a user can choose.\n */\n// forwardRef doesn't support generic parameters, so cast the result to the correct type\n// https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref\nexport const Menu = React.forwardRef(function Menu<T extends object>(props: SpectrumMenuProps<T>, ref: DOMRef<HTMLDivElement>) {\n let isSubmenu = true;\n let contextProps = useContext(MenuContext);\n let parentMenuContext = useMenuStateContext();\n let {rootMenuTriggerState, state: parentMenuTreeState} = parentMenuContext || {rootMenuTriggerState: contextProps.state};\n if (!parentMenuContext) {\n isSubmenu = false;\n }\n let completeProps = {\n ...mergeProps(contextProps, props)\n };\n let domRef = useDOMRef(ref);\n let [popoverContainer, setPopoverContainer] = useState<HTMLElement | null>(null);\n let trayContainerRef = useRef<HTMLDivElement | null>(null);\n let state = useTreeState(completeProps);\n let submenuRef = useRef<HTMLDivElement>(null);\n let {menuProps} = useMenu(completeProps, state, domRef);\n let {styleProps} = useStyleProps(completeProps);\n useSyncRef(contextProps, domRef);\n let [leftOffset, setLeftOffset] = useState({left: 0});\n let prevPopoverContainer = useRef<HTMLElement | null>(null);\n useEffect(() => {\n if (popoverContainer && prevPopoverContainer.current !== popoverContainer && leftOffset.left === 0) {\n prevPopoverContainer.current = popoverContainer;\n let {left} = popoverContainer.getBoundingClientRect();\n setLeftOffset({left: -1 * left});\n }\n }, [leftOffset, popoverContainer]);\n\n let menuLevel = contextProps.submenuLevel ?? -1;\n let nextMenuLevelKey = rootMenuTriggerState?.expandedKeysStack[menuLevel + 1];\n let hasOpenSubmenu = false;\n if (nextMenuLevelKey != null) {\n let nextMenuLevel = state.collection.getItem(nextMenuLevelKey);\n hasOpenSubmenu = nextMenuLevel != null;\n }\n\n return (\n <MenuStateContext.Provider value={{popoverContainer, trayContainerRef, menu: domRef, submenu: submenuRef, rootMenuTriggerState, state}}>\n <div style={{height: hasOpenSubmenu ? '100%' : undefined}} ref={trayContainerRef} />\n <FocusScope>\n <TrayHeaderWrapper\n onBackButtonPress={contextProps.onBackButtonPress}\n hasOpenSubmenu={hasOpenSubmenu}\n isSubmenu={isSubmenu}\n parentMenuTreeState={parentMenuTreeState}\n rootMenuTriggerState={rootMenuTriggerState}\n menuRef={domRef}>\n <div\n {...menuProps}\n style={mergeProps(styleProps.style, menuProps.style)}\n ref={domRef}\n className={\n classNames(\n styles,\n 'spectrum-Menu',\n styleProps.className\n )\n }>\n {[...state.collection].map(item => {\n if (item.type === 'section') {\n return (\n <MenuSection\n key={item.key}\n item={item}\n state={state} />\n );\n }\n\n let menuItem = (\n <MenuItem\n key={item.key}\n item={item}\n state={state} />\n );\n\n if (item.wrapper) {\n menuItem = item.wrapper(menuItem);\n }\n\n return menuItem;\n })}\n </div>\n </TrayHeaderWrapper>\n {rootMenuTriggerState?.isOpen && <div ref={setPopoverContainer} style={{width: '100vw', position: 'absolute', top: -5, ...leftOffset}} /> }\n </FocusScope>\n </MenuStateContext.Provider>\n );\n}) as <T>(props: SpectrumMenuProps<T> & {ref?: DOMRef<HTMLDivElement>}) => ReactElement;\n\nexport function TrayHeaderWrapper(props: {\n children: ReactNode,\n isSubmenu?: boolean,\n hasOpenSubmenu?: boolean,\n parentMenuTreeState?: TreeState<any>,\n rootMenuTriggerState?: RootMenuTriggerState,\n onBackButtonPress?: (() => void),\n wrapperKeyDown?: KeyboardEventHandler<HTMLDivElement> | undefined,\n menuRef?: RefObject<HTMLDivElement | null>\n}): ReactNode {\n let {children, isSubmenu, hasOpenSubmenu, parentMenuTreeState, rootMenuTriggerState, onBackButtonPress, wrapperKeyDown, menuRef} = props;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/menu');\n let lastKey = rootMenuTriggerState?.expandedKeysStack.slice(-1)[0];\n let backButtonText = '';\n if (lastKey != null) {\n backButtonText = parentMenuTreeState?.collection.getItem(lastKey)?.textValue ?? '';\n }\n let backButtonLabel = stringFormatter.format('backButton', {\n prevMenuButton: backButtonText ?? ''\n });\n let headingId = useSlotId();\n let isMobile = useIsMobileDevice();\n let {direction} = useLocale();\n\n let [traySubmenuAnimation, setTraySubmenuAnimation] = useState('');\n useLayoutEffect(() => {\n if (!hasOpenSubmenu) {\n setTraySubmenuAnimation('spectrum-TraySubmenu-enter');\n }\n }, [hasOpenSubmenu, isMobile]);\n\n let timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n let handleBackButtonPress = () => {\n setTraySubmenuAnimation('spectrum-TraySubmenu-exit');\n timeoutRef.current = setTimeout(() => {\n onBackButtonPress?.();\n }, 220); // Matches transition duration\n };\n\n useEffect(() => {\n return () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n };\n }, []);\n\n // When opening submenu in tray, focus the first item in the submenu after animation completes\n // This fixes an issue with iOS VO where the closed submenu was getting focus\n let focusTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n useEffect(() => {\n if (isMobile && isSubmenu && !hasOpenSubmenu && traySubmenuAnimation === 'spectrum-TraySubmenu-enter') {\n focusTimeoutRef.current = setTimeout(() => {\n let firstItem = menuRef?.current?.querySelector('[role=\"menuitem\"], [role=\"menuitemcheckbox\"], [role=\"menuitemradio\"]') as HTMLElement;\n firstItem?.focus();\n }, 220);\n }\n return () => {\n if (focusTimeoutRef.current) {\n clearTimeout(focusTimeoutRef.current);\n }\n };\n }, [hasOpenSubmenu, isMobile, isSubmenu, menuRef, traySubmenuAnimation]);\n\n return (\n <>\n <div\n role={headingId ? 'dialog' : undefined}\n aria-labelledby={headingId}\n aria-hidden={isMobile && hasOpenSubmenu}\n data-testid=\"menu-wrapper\"\n className={\n classNames(\n styles,\n 'spectrum-Menu-wrapper',\n {\n 'spectrum-Menu-wrapper--isMobile': isMobile,\n 'is-expanded': hasOpenSubmenu,\n [traySubmenuAnimation]: isMobile\n }\n )\n }>\n <div role=\"presentation\" className={classNames(styles, 'spectrum-Submenu-wrapper', {'spectrum-Submenu-wrapper--isMobile': isMobile})} onKeyDown={wrapperKeyDown}>\n {isMobile && isSubmenu && !hasOpenSubmenu && (\n <div className={classNames(styles, 'spectrum-Submenu-headingWrapper')}>\n <ActionButton\n aria-label={backButtonLabel}\n isQuiet\n onPress={handleBackButtonPress}>\n {/* We don't have a ArrowLeftSmall so make due with ArrowDownSmall and transforms */}\n {direction === 'rtl' ? <ArrowDownSmall UNSAFE_style={{rotate: '270deg'}} /> : <ArrowDownSmall UNSAFE_style={{rotate: '90deg'}} />}\n </ActionButton>\n <h1 id={headingId} className={classNames(styles, 'spectrum-Submenu-heading')}>{backButtonText}</h1>\n </div>\n )}\n {children}\n </div>\n </div>\n </>\n );\n}\n"],"names":[],"version":3,"file":"Menu.module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;;;AA0BM,MAAM,0DAAO,CAAA,GAAA,YAAI,EAAE,UAAU,CAAC,SAAS,KAAuB,KAA2B,EAAE,GAA2B;IAC3H,IAAI,YAAY;IAChB,IAAI,eAAe,CAAA,GAAA,iBAAS,EAAE,CAAA,GAAA,yCAAU;IACxC,IAAI,oBAAoB,CAAA,GAAA,yCAAkB;IAC1C,IAAI,wBAAC,oBAAoB,EAAE,OAAO,mBAAmB,EAAC,GAAG,qBAAqB;QAAC,sBAAsB,aAAa,KAAK;IAAA;IACvH,IAAI,CAAC,mBACH,YAAY;IAEd,IAAI,gBAAgB;QAClB,GAAG,CAAA,GAAA,iBAAS,EAAE,cAAc,MAAM;IACpC;IACA,IAAI,SAAS,CAAA,GAAA,gBAAQ,EAAE;IACvB,IAAI,CAAC,kBAAkB,oBAAoB,GAAG,CAAA,GAAA,eAAO,EAAsB;IAC3E,IAAI,mBAAmB,CAAA,GAAA,aAAK,EAAyB;IACrD,IAAI,QAAQ,CAAA,GAAA,mBAAW,EAA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C,qBAAqB,EAAE;QAC1B;qBAGJ,gCAAC;QAAI,MAAK;QAAe,WAAW,CAAA,GAAA,iBAAS,EAAE,CAAA,GAAA,sDAAK,GAAG,4BAA4B;YAAC,sCAAsC;QAAQ;QAAI,WAAW;OAC9I,YAAY,aAAa,CAAC,gCACzB,gCAAC;QAAI,WAAW,CAAA,GAAA,iBAAS,EAAE,CAAA,GAAA,sDAAK,GAAG;qBACjC,gCAAC,CAAA,GAAA,mBAAW;QACV,cAAY;QACZ,SAAA;QACA,SAAS;OAER,cAAc,sBAAQ,gCAAC,CAAA,GAAA,oCAAa;QAAE,cAAc;YAAC,QAAQ;QAAQ;uBAAQ,gCAAC,CAAA,GAAA,oCAAa;QAAE,cAAc;YAAC,QAAQ;QAAO;uBAE9H,gCAAC;QAAG,IAAI;QAAW,WAAW,CAAA,GAAA,iBAAS,EAAE,CAAA,GAAA,sDAAK,GAAG;OAA8B,kBAGlF;AAKX","sources":["packages/@react-spectrum/menu/src/Menu.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {ActionButton} from '@react-spectrum/button';\nimport ArrowDownSmall from '@spectrum-icons/ui/ArrowDownSmall';\nimport {classNames, useDOMRef, useIsMobileDevice, useStyleProps} from '@react-spectrum/utils';\nimport {DOMRef} from '@react-types/shared';\nimport {FocusScope} from '@react-aria/focus';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {MenuContext, MenuStateContext, useMenuStateContext} from './context';\nimport {MenuItem} from './MenuItem';\nimport {MenuSection} from './MenuSection';\nimport {mergeProps, useLayoutEffect, useSlotId, useSyncRef} from '@react-aria/utils';\nimport React, {KeyboardEventHandler, ReactElement, ReactNode, RefObject, useContext, useEffect, useRef, useState} from 'react';\nimport {RootMenuTriggerState} from '@react-stately/menu';\nimport {SpectrumMenuProps} from '@react-types/menu';\nimport styles from '@adobe/spectrum-css-temp/components/menu/vars.css';\nimport {TreeState, useTreeState} from '@react-stately/tree';\nimport {useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useMenu} from '@react-aria/menu';\n\n/**\n * Menus display a list of actions or options that a user can choose.\n */\n// forwardRef doesn't support generic parameters, so cast the result to the correct type\n// https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref\nexport const Menu = React.forwardRef(function Menu<T extends object>(props: SpectrumMenuProps<T>, ref: DOMRef<HTMLDivElement>) {\n let isSubmenu = true;\n let contextProps = useContext(MenuContext);\n let parentMenuContext = useMenuStateContext();\n let {rootMenuTriggerState, state: parentMenuTreeState} = parentMenuContext || {rootMenuTriggerState: contextProps.state};\n if (!parentMenuContext) {\n isSubmenu = false;\n }\n let completeProps = {\n ...mergeProps(contextProps, props)\n };\n let domRef = useDOMRef(ref);\n let [popoverContainer, setPopoverContainer] = useState<HTMLElement | null>(null);\n let trayContainerRef = useRef<HTMLDivElement | null>(null);\n let state = useTreeState(completeProps);\n let submenuRef = useRef<HTMLDivElement>(null);\n let {menuProps} = useMenu(completeProps, state, domRef);\n let {styleProps} = useStyleProps(completeProps);\n useSyncRef(contextProps, domRef);\n let [leftOffset, setLeftOffset] = useState({left: 0});\n let prevPopoverContainer = useRef<HTMLElement | null>(null);\n\n useLayoutEffect(() => {\n if (popoverContainer && prevPopoverContainer.current !== popoverContainer && leftOffset.left === 0) {\n prevPopoverContainer.current = popoverContainer;\n let {left} = popoverContainer.getBoundingClientRect();\n setLeftOffset({left: -1 * left});\n }\n }, [leftOffset, popoverContainer]);\n\n let menuLevel = contextProps.submenuLevel ?? -1;\n let nextMenuLevelKey = rootMenuTriggerState?.expandedKeysStack[menuLevel + 1];\n let hasOpenSubmenu = false;\n if (nextMenuLevelKey != null) {\n let nextMenuLevel = state.collection.getItem(nextMenuLevelKey);\n hasOpenSubmenu = nextMenuLevel != null;\n }\n\n return (\n <MenuStateContext.Provider value={{popoverContainer, trayContainerRef, menu: domRef, submenu: submenuRef, rootMenuTriggerState, state}}>\n <div style={{height: hasOpenSubmenu ? '100%' : undefined}} ref={trayContainerRef} />\n <FocusScope>\n <TrayHeaderWrapper\n onBackButtonPress={contextProps.onBackButtonPress}\n hasOpenSubmenu={hasOpenSubmenu}\n isSubmenu={isSubmenu}\n parentMenuTreeState={parentMenuTreeState}\n rootMenuTriggerState={rootMenuTriggerState}\n menuRef={domRef}>\n <div\n {...menuProps}\n style={mergeProps(styleProps.style, menuProps.style)}\n ref={domRef}\n className={\n classNames(\n styles,\n 'spectrum-Menu',\n styleProps.className\n )\n }>\n {[...state.collection].map(item => {\n if (item.type === 'section') {\n return (\n <MenuSection\n key={item.key}\n item={item}\n state={state} />\n );\n }\n\n let menuItem = (\n <MenuItem\n key={item.key}\n item={item}\n state={state} />\n );\n\n if (item.wrapper) {\n menuItem = item.wrapper(menuItem);\n }\n\n return menuItem;\n })}\n </div>\n </TrayHeaderWrapper>\n {rootMenuTriggerState?.isOpen && <div ref={setPopoverContainer} style={{width: '100vw', position: 'absolute', top: -5, ...leftOffset}} /> }\n </FocusScope>\n </MenuStateContext.Provider>\n );\n}) as <T>(props: SpectrumMenuProps<T> & {ref?: DOMRef<HTMLDivElement>}) => ReactElement;\n\nexport function TrayHeaderWrapper(props: {\n children: ReactNode,\n isSubmenu?: boolean,\n hasOpenSubmenu?: boolean,\n parentMenuTreeState?: TreeState<any>,\n rootMenuTriggerState?: RootMenuTriggerState,\n onBackButtonPress?: (() => void),\n wrapperKeyDown?: KeyboardEventHandler<HTMLDivElement> | undefined,\n menuRef?: RefObject<HTMLDivElement | null>\n}): ReactNode {\n let {children, isSubmenu, hasOpenSubmenu, parentMenuTreeState, rootMenuTriggerState, onBackButtonPress, wrapperKeyDown, menuRef} = props;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/menu');\n let lastKey = rootMenuTriggerState?.expandedKeysStack.slice(-1)[0];\n let backButtonText = '';\n if (lastKey != null) {\n backButtonText = parentMenuTreeState?.collection.getItem(lastKey)?.textValue ?? '';\n }\n let backButtonLabel = stringFormatter.format('backButton', {\n prevMenuButton: backButtonText ?? ''\n });\n let headingId = useSlotId();\n let isMobile = useIsMobileDevice();\n let {direction} = useLocale();\n\n let [traySubmenuAnimation, setTraySubmenuAnimation] = useState('');\n useLayoutEffect(() => {\n if (!hasOpenSubmenu) {\n setTraySubmenuAnimation('spectrum-TraySubmenu-enter');\n }\n }, [hasOpenSubmenu, isMobile]);\n\n let timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n let handleBackButtonPress = () => {\n setTraySubmenuAnimation('spectrum-TraySubmenu-exit');\n timeoutRef.current = setTimeout(() => {\n onBackButtonPress?.();\n }, 220); // Matches transition duration\n };\n\n useEffect(() => {\n return () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n };\n }, []);\n\n // When opening submenu in tray, focus the first item in the submenu after animation completes\n // This fixes an issue with iOS VO where the closed submenu was getting focus\n let focusTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n useEffect(() => {\n if (isMobile && isSubmenu && !hasOpenSubmenu && traySubmenuAnimation === 'spectrum-TraySubmenu-enter') {\n focusTimeoutRef.current = setTimeout(() => {\n let firstItem = menuRef?.current?.querySelector('[role=\"menuitem\"], [role=\"menuitemcheckbox\"], [role=\"menuitemradio\"]') as HTMLElement;\n firstItem?.focus();\n }, 220);\n }\n return () => {\n if (focusTimeoutRef.current) {\n clearTimeout(focusTimeoutRef.current);\n }\n };\n }, [hasOpenSubmenu, isMobile, isSubmenu, menuRef, traySubmenuAnimation]);\n\n return (\n <>\n <div\n role={headingId ? 'dialog' : undefined}\n aria-labelledby={headingId}\n aria-hidden={isMobile && hasOpenSubmenu}\n data-testid=\"menu-wrapper\"\n className={\n classNames(\n styles,\n 'spectrum-Menu-wrapper',\n {\n 'spectrum-Menu-wrapper--isMobile': isMobile,\n 'is-expanded': hasOpenSubmenu,\n [traySubmenuAnimation]: isMobile\n }\n )\n }>\n <div role=\"presentation\" className={classNames(styles, 'spectrum-Submenu-wrapper', {'spectrum-Submenu-wrapper--isMobile': isMobile})} onKeyDown={wrapperKeyDown}>\n {isMobile && isSubmenu && !hasOpenSubmenu && (\n <div className={classNames(styles, 'spectrum-Submenu-headingWrapper')}>\n <ActionButton\n aria-label={backButtonLabel}\n isQuiet\n onPress={handleBackButtonPress}>\n {/* We don't have a ArrowLeftSmall so make due with ArrowDownSmall and transforms */}\n {direction === 'rtl' ? <ArrowDownSmall UNSAFE_style={{rotate: '270deg'}} /> : <ArrowDownSmall UNSAFE_style={{rotate: '90deg'}} />}\n </ActionButton>\n <h1 id={headingId} className={classNames(styles, 'spectrum-Submenu-heading')}>{backButtonText}</h1>\n </div>\n )}\n {children}\n </div>\n </div>\n </>\n );\n}\n"],"names":[],"version":3,"file":"Menu.module.js.map"}
|