@react-aria/menu 3.2.4-nightly.2949 → 3.2.4-nightly.2967
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/main.js +15 -5
- package/dist/main.js.map +1 -1
- package/dist/module.js +15 -5
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/useMenuItem.ts +2 -2
- package/src/useMenuTrigger.ts +8 -1
package/dist/main.js
CHANGED
|
@@ -51,7 +51,7 @@ function useMenuTrigger(props, state, ref) {
|
|
|
51
51
|
}, state, ref);
|
|
52
52
|
|
|
53
53
|
let onKeyDown = e => {
|
|
54
|
-
if (
|
|
54
|
+
if (isDisabled) {
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
|
|
@@ -60,11 +60,20 @@ function useMenuTrigger(props, state, ref) {
|
|
|
60
60
|
case 'ArrowDown':
|
|
61
61
|
case 'Enter':
|
|
62
62
|
case ' ':
|
|
63
|
+
// Stop propagation, unless it would already be handled by useKeyboard.
|
|
64
|
+
if (!('continuePropagation' in e)) {
|
|
65
|
+
e.stopPropagation();
|
|
66
|
+
}
|
|
67
|
+
|
|
63
68
|
e.preventDefault();
|
|
64
69
|
state.toggle('first');
|
|
65
70
|
break;
|
|
66
71
|
|
|
67
72
|
case 'ArrowUp':
|
|
73
|
+
if (!('continuePropagation' in e)) {
|
|
74
|
+
e.stopPropagation();
|
|
75
|
+
}
|
|
76
|
+
|
|
68
77
|
e.preventDefault();
|
|
69
78
|
state.toggle('last');
|
|
70
79
|
break;
|
|
@@ -237,12 +246,11 @@ function useMenuItem(props, state, ref) {
|
|
|
237
246
|
});
|
|
238
247
|
let {
|
|
239
248
|
pressProps
|
|
240
|
-
} = usePress(
|
|
249
|
+
} = usePress({
|
|
241
250
|
onPressStart,
|
|
242
251
|
onPressUp,
|
|
243
|
-
onKeyDown,
|
|
244
252
|
isDisabled
|
|
245
|
-
}
|
|
253
|
+
});
|
|
246
254
|
let {
|
|
247
255
|
hoverProps
|
|
248
256
|
} = useHover({
|
|
@@ -257,7 +265,9 @@ function useMenuItem(props, state, ref) {
|
|
|
257
265
|
|
|
258
266
|
});
|
|
259
267
|
return {
|
|
260
|
-
menuItemProps: _babelRuntimeHelpersExtends({}, ariaProps, mergeProps(pressProps, hoverProps
|
|
268
|
+
menuItemProps: _babelRuntimeHelpersExtends({}, ariaProps, mergeProps(itemProps, pressProps, hoverProps, {
|
|
269
|
+
onKeyDown
|
|
270
|
+
})),
|
|
261
271
|
labelProps: {
|
|
262
272
|
id: labelId
|
|
263
273
|
},
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,sBAAT,CAAgCC,CAAhC,EAAmC;AACjC,SAAOA,CAAC,IAAIA,CAAC,CAACC,UAAP,GAAoBD,CAAC,CAACE,OAAtB,GAAgCF,CAAvC;AACD;;AC+BD;;;;;AAKO,SAASG,cAAT,CAAwBC,KAAxB,EAAqDC,KAArD,EAA8EC,GAA9E,EAA4H;AACjI,MAAI;AACFC,IAAAA,IAAI,GAAG,MADL;AAEFC,IAAAA;AAFE,MAGAJ,KAHJ;AAKA,MAAIK,aAAa,GAAGC,KAAK,EAAzB;AACA,MAAI;AAACC,IAAAA,YAAD;AAAeC,IAAAA;AAAf,MAA+BC,iBAAiB,CAAC;AAACN,IAAAA;AAAD,GAAD,EAASF,KAAT,EAAgBC,GAAhB,CAApD;;AAEA,MAAIQ,SAAS,GAAIC,CAAD,IAAO;AACrB,QAAK,OAAOA,CAAC,CAACC,kBAAT,KAAgC,UAAhC,IAA8CD,CAAC,CAACC,kBAAF,EAA/C,IAA0ED,CAAC,CAACE,gBAA5E,IAAgGT,UAApG,EAAgH;AAC9G;AACD;;AAED,QAAIF,GAAG,IAAIA,GAAG,CAACY,OAAf,EAAwB;AACtB,cAAQH,CAAC,CAACI,GAAV;AACE,aAAK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;;;;AAKO,SAAS0B,cAAT,CAAwB3E,KAAxB,EAAsE;AAC3E,MAAI;AAAC4E,IAAAA,OAAD;AAAU,kBAAcC;AAAxB,MAAqC7E,KAAzC;AACA,MAAI8E,SAAS,GAAGxE,KAAK,EAArB;AAEA,SAAO;AACLsD,IAAAA,SAAS,EAAE;AACTtB,MAAAA,IAAI,EAAE;AADG,KADN;AAILyC,IAAAA,YAAY,EAAEH,OAAO,GAAG;AACtB;AACA;AACA;AACAzD,MAAAA,EAAE,EAAE2D,SAJkB;AAKtB,qBAAe;AALO,KAAH,GAMjB,EAVC;AAWLE,IAAAA,UAAU,EAAE;AACV1C,MAAAA,IAAI,EAAE,OADI;AAEV,oBAAcuC,SAFJ;AAGV,yBAAmBD,OAAO,GAAGE,SAAH,GAAexB;AAH/B;AAXP,GAAP;AAiBD","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/@react-aria/menu/src/useMenuTrigger.ts","./packages/@react-aria/menu/src/useMenu.ts","./packages/@react-aria/menu/src/useMenuItem.ts","./packages/@react-aria/menu/src/useMenuSection.ts"],"sourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\n","/*\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 {AriaButtonProps} from '@react-types/button';\nimport {HTMLAttributes, RefObject} from 'react';\nimport {MenuTriggerState} from '@react-stately/menu';\nimport {useId} from '@react-aria/utils';\nimport {useOverlayTrigger} from '@react-aria/overlays';\n\ninterface MenuTriggerAriaProps {\n /** The type of menu that the menu trigger opens. */\n type?: 'menu' | 'listbox',\n /** Whether menu trigger is disabled. */\n isDisabled?: boolean\n}\n\ninterface MenuTriggerAria {\n /** Props for the menu trigger element. */\n menuTriggerProps: AriaButtonProps,\n\n /** Props for the menu. */\n menuProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a menu trigger.\n * @param props - Props for the menu trigger.\n * @param state - State for the menu trigger.\n */\nexport function useMenuTrigger(props: MenuTriggerAriaProps, state: MenuTriggerState, ref: RefObject<HTMLElement>): MenuTriggerAria {\n let {\n type = 'menu' as MenuTriggerAriaProps['type'],\n isDisabled\n } = props;\n\n let menuTriggerId = useId();\n let {triggerProps, overlayProps} = useOverlayTrigger({type}, state, ref);\n\n let onKeyDown = (e) => {\n if ((typeof e.isDefaultPrevented === 'function' && e.isDefaultPrevented()) || e.defaultPrevented || isDisabled) {\n return;\n }\n\n if (ref && ref.current) {\n switch (e.key) {\n case 'ArrowDown':\n case 'Enter':\n case ' ':\n e.preventDefault();\n state.toggle('first');\n break;\n case 'ArrowUp':\n e.preventDefault();\n state.toggle('last');\n break;\n }\n }\n };\n\n return {\n menuTriggerProps: {\n ...triggerProps,\n id: menuTriggerId,\n onPressStart(e) {\n // For consistency with native, open the menu on mouse/key down, but touch up.\n if (e.pointerType !== 'touch' && e.pointerType !== 'keyboard') {\n // If opened with a screen reader, auto focus the first item.\n // Otherwise, the menu itself will be focused.\n state.toggle(e.pointerType === 'virtual' ? 'first' : null);\n }\n },\n onPress(e) {\n if (e.pointerType === 'touch') {\n state.toggle();\n }\n },\n onKeyDown\n },\n menuProps: {\n ...overlayProps,\n 'aria-labelledby': menuTriggerId\n }\n };\n}\n","/*\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 {AriaMenuProps} from '@react-types/menu';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {HTMLAttributes, RefObject} from 'react';\nimport {KeyboardDelegate} from '@react-types/shared';\nimport {TreeState} from '@react-stately/tree';\nimport {useSelectableList} from '@react-aria/selection';\n\ninterface MenuAria {\n /** Props for the menu element. */\n menuProps: HTMLAttributes<HTMLElement>\n}\n\ninterface AriaMenuOptions<T> extends AriaMenuProps<T> {\n /** Whether the menu uses virtual scrolling. */\n isVirtualized?: boolean,\n\n /**\n * An optional keyboard delegate implementation for type to select,\n * to override the default.\n */\n keyboardDelegate?: KeyboardDelegate\n}\n\n/**\n * Provides the behavior and accessibility implementation for a menu component.\n * A menu displays a list of actions or options that a user can choose.\n * @param props - Props for the menu.\n * @param state - State for the menu, as returned by `useListState`.\n */\nexport function useMenu<T>(props: AriaMenuOptions<T>, state: TreeState<T>, ref: RefObject<HTMLElement>): MenuAria {\n let {\n shouldFocusWrap = true,\n ...otherProps\n } = props;\n\n if (!props['aria-label'] && !props['aria-labelledby']) {\n console.warn('An aria-label or aria-labelledby prop is required for accessibility.');\n }\n\n let domProps = filterDOMProps(props, {labelable: true});\n let {listProps} = useSelectableList({\n ...otherProps,\n ref,\n selectionManager: state.selectionManager,\n collection: state.collection,\n disabledKeys: state.disabledKeys,\n shouldFocusWrap\n });\n\n return {\n menuProps: mergeProps(domProps, {\n role: 'menu',\n ...listProps\n })\n };\n}\n","/*\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 {getItemCount} from '@react-stately/collections';\nimport {HTMLAttributes, Key, RefObject} from 'react';\nimport {isFocusVisible, useHover, usePress} from '@react-aria/interactions';\nimport {mergeProps, useSlotId} from '@react-aria/utils';\nimport {PressEvent} from '@react-types/shared';\nimport {TreeState} from '@react-stately/tree';\nimport {useSelectableItem} from '@react-aria/selection';\n\ninterface MenuItemAria {\n /** Props for the menu item element. */\n menuItemProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the main text element inside the menu item. */\n labelProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the description text element inside the menu item, if any. */\n descriptionProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the keyboard shortcut text element inside the item, if any. */\n keyboardShortcutProps: HTMLAttributes<HTMLElement>\n}\n\ninterface AriaMenuItemProps {\n /** Whether the menu item is disabled. */\n isDisabled?: boolean,\n\n /** Whether the menu item is selected. */\n isSelected?: boolean,\n\n /** A screen reader only label for the menu item. */\n 'aria-label'?: string,\n\n /** The unique key for the menu item. */\n key?: Key,\n\n /** Handler that is called when the menu should close after selecting an item. */\n onClose?: () => void,\n\n /**\n * Whether the menu should close when the menu item is selected.\n * @default true\n */\n closeOnSelect?: boolean,\n\n /** Whether the menu item is contained in a virtual scrolling menu. */\n isVirtualized?: boolean,\n\n /** Handler that is called when the user activates the item. */\n onAction?: (key: Key) => void\n}\n\n/**\n * Provides the behavior and accessibility implementation for an item in a menu.\n * See `useMenu` for more details about menus.\n * @param props - Props for the item.\n * @param state - State for the menu, as returned by `useTreeState`.\n */\nexport function useMenuItem<T>(props: AriaMenuItemProps, state: TreeState<T>, ref: RefObject<HTMLElement>): MenuItemAria {\n let {\n isSelected,\n isDisabled,\n key,\n onClose,\n closeOnSelect,\n isVirtualized,\n onAction\n } = props;\n\n let role = 'menuitem';\n if (state.selectionManager.selectionMode === 'single') {\n role = 'menuitemradio';\n } else if (state.selectionManager.selectionMode === 'multiple') {\n role = 'menuitemcheckbox';\n }\n\n let labelId = useSlotId();\n let descriptionId = useSlotId();\n let keyboardId = useSlotId();\n\n let ariaProps = {\n 'aria-disabled': isDisabled,\n role,\n 'aria-label': props['aria-label'],\n 'aria-labelledby': labelId,\n 'aria-describedby': [descriptionId, keyboardId].filter(Boolean).join(' ') || undefined\n };\n\n if (state.selectionManager.selectionMode !== 'none') {\n ariaProps['aria-checked'] = isSelected;\n }\n\n if (isVirtualized) {\n ariaProps['aria-posinset'] = state.collection.getItem(key).index;\n ariaProps['aria-setsize'] = getItemCount(state.collection);\n }\n\n let onKeyDown = (e: KeyboardEvent) => {\n // Ignore repeating events, which may have started on the menu trigger before moving\n // focus to the menu item. We want to wait for a second complete key press sequence.\n if (e.repeat) {\n return;\n }\n\n switch (e.key) {\n case ' ':\n if (!isDisabled && state.selectionManager.selectionMode === 'none' && closeOnSelect !== false && onClose) {\n onClose();\n }\n break;\n case 'Enter':\n // The Enter key should always close on select, except if overridden.\n if (!isDisabled && closeOnSelect !== false && onClose) {\n onClose();\n }\n break;\n }\n };\n\n let onPressStart = (e: PressEvent) => {\n if (e.pointerType === 'keyboard' && onAction) {\n onAction(key);\n }\n };\n\n let onPressUp = (e: PressEvent) => {\n if (e.pointerType !== 'keyboard') {\n if (onAction) {\n onAction(key);\n }\n\n // Pressing a menu item should close by default in single selection mode but not multiple\n // selection mode, except if overridden by the closeOnSelect prop.\n if (onClose && (closeOnSelect ?? state.selectionManager.selectionMode !== 'multiple')) {\n onClose();\n }\n }\n };\n\n let {itemProps} = useSelectableItem({\n selectionManager: state.selectionManager,\n key,\n ref,\n shouldSelectOnPressUp: true\n });\n\n let {pressProps} = usePress(mergeProps({onPressStart, onPressUp, onKeyDown, isDisabled}, itemProps));\n let {hoverProps} = useHover({\n isDisabled,\n onHoverStart() {\n if (!isFocusVisible()) {\n state.selectionManager.setFocused(true);\n state.selectionManager.setFocusedKey(key);\n }\n }\n });\n\n return {\n menuItemProps: {\n ...ariaProps,\n ...mergeProps(pressProps, hoverProps)\n },\n labelProps: {\n id: labelId\n },\n descriptionProps: {\n id: descriptionId\n },\n keyboardShortcutProps: {\n id: keyboardId\n }\n };\n}\n","/*\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 {HTMLAttributes, ReactNode} from 'react';\nimport {useId} from '@react-aria/utils';\n\ninterface AriaMenuSectionProps {\n /** The heading for the section. */\n heading?: ReactNode,\n /** An accessibility label for the section. Required if `heading` is not present. */\n 'aria-label'?: string\n}\n\ninterface MenuSectionAria {\n /** Props for the wrapper list item. */\n itemProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the heading element, if any. */\n headingProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the group element. */\n groupProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a section in a menu.\n * See `useMenu` for more details about menus.\n * @param props - Props for the section.\n */\nexport function useMenuSection(props: AriaMenuSectionProps): MenuSectionAria {\n let {heading, 'aria-label': ariaLabel} = props;\n let headingId = useId();\n\n return {\n itemProps: {\n role: 'presentation'\n },\n headingProps: heading ? {\n // Techincally, menus cannot contain headings according to ARIA.\n // We hide the heading from assistive technology, and only use it\n // as a label for the nested group.\n id: headingId,\n 'aria-hidden': true\n } : {},\n groupProps: {\n role: 'group',\n 'aria-label': ariaLabel,\n 'aria-labelledby': heading ? headingId : undefined\n }\n };\n}\n"],"names":["$parcel$interopDefault","a","__esModule","default","useMenuTrigger","props","state","ref","type","isDisabled","menuTriggerId","useId","triggerProps","overlayProps","useOverlayTrigger","onKeyDown","e","isDefaultPrevented","defaultPrevented","current","key","preventDefault","toggle","menuTriggerProps","id","onPressStart","pointerType","onPress","menuProps","useMenu","shouldFocusWrap","otherProps","console","warn","domProps","filterDOMProps","labelable","listProps","useSelectableList","selectionManager","collection","disabledKeys","mergeProps","role","useMenuItem","isSelected","onClose","closeOnSelect","isVirtualized","onAction","selectionMode","labelId","useSlotId","descriptionId","keyboardId","ariaProps","filter","Boolean","join","undefined","getItem","index","getItemCount","repeat","onPressUp","itemProps","useSelectableItem","shouldSelectOnPressUp","pressProps","usePress","hoverProps","useHover","onHoverStart","isFocusVisible","setFocused","setFocusedKey","menuItemProps","labelProps","descriptionProps","keyboardShortcutProps","useMenuSection","heading","ariaLabel","headingId","headingProps","groupProps"],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,sBAAT,CAAgCC,CAAhC,EAAmC;AACjC,SAAOA,CAAC,IAAIA,CAAC,CAACC,UAAP,GAAoBD,CAAC,CAACE,OAAtB,GAAgCF,CAAvC;AACD;;AC+BD;;;;;AAKO,SAASG,cAAT,CAAwBC,KAAxB,EAAqDC,KAArD,EAA8EC,GAA9E,EAA4H;AACjI,MAAI;AACFC,IAAAA,IAAI,GAAG,MADL;AAEFC,IAAAA;AAFE,MAGAJ,KAHJ;AAKA,MAAIK,aAAa,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AAvB,CAAkC,IAAlC;AACAnE,QAAAA,KAAK,CAACgC,gBAAN,CAAuBoC,aAAvB,CAAqCxD,GAArC;AACD;AACF;;AAPyB,GAAD,CAA3B;AAUA,SAAO;AACLyD,IAAAA,aAAa,kCACRrB,SADQ,EAERb,UAAU,CAACuB,SAAD,EAAYG,UAAZ,EAAwBE,UAAxB,EAAoC;AAACtD,MAAAA;AAAD,KAApC,CAFF,CADR;AAKL6D,IAAAA,UAAU,EAAE;AACVrD,MAAAA,EAAE,EAAE2B;AADM,KALP;AAQL2B,IAAAA,gBAAgB,EAAE;AAChBtD,MAAAA,EAAE,EAAE6B;AADY,KARb;AAWL0B,IAAAA,qBAAqB,EAAE;AACrBvD,MAAAA,EAAE,EAAE8B;AADiB;AAXlB,GAAP;AAeD;;;;ACtJD;;;;;AAKO,SAAS0B,cAAT,CAAwB1E,KAAxB,EAAsE;AAC3E,MAAI;AAAC2E,IAAAA,OAAD;AAAU,kBAAcC;AAAxB,MAAqC5E,KAAzC;AACA,MAAI6E,SAAS,GAAGvE,KAAK,EAArB;AAEA,SAAO;AACLqD,IAAAA,SAAS,EAAE;AACTtB,MAAAA,IAAI,EAAE;AADG,KADN;AAILyC,IAAAA,YAAY,EAAEH,OAAO,GAAG;AACtB;AACA;AACA;AACAzD,MAAAA,EAAE,EAAE2D,SAJkB;AAKtB,qBAAe;AALO,KAAH,GAMjB,EAVC;AAWLE,IAAAA,UAAU,EAAE;AACV1C,MAAAA,IAAI,EAAE,OADI;AAEV,oBAAcuC,SAFJ;AAGV,yBAAmBD,OAAO,GAAGE,SAAH,GAAexB;AAH/B;AAXP,GAAP;AAiBD","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/@react-aria/menu/src/useMenuTrigger.ts","./packages/@react-aria/menu/src/useMenu.ts","./packages/@react-aria/menu/src/useMenuItem.ts","./packages/@react-aria/menu/src/useMenuSection.ts"],"sourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\n","/*\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 {AriaButtonProps} from '@react-types/button';\nimport {HTMLAttributes, RefObject} from 'react';\nimport {MenuTriggerState} from '@react-stately/menu';\nimport {useId} from '@react-aria/utils';\nimport {useOverlayTrigger} from '@react-aria/overlays';\n\ninterface MenuTriggerAriaProps {\n /** The type of menu that the menu trigger opens. */\n type?: 'menu' | 'listbox',\n /** Whether menu trigger is disabled. */\n isDisabled?: boolean\n}\n\ninterface MenuTriggerAria {\n /** Props for the menu trigger element. */\n menuTriggerProps: AriaButtonProps,\n\n /** Props for the menu. */\n menuProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a menu trigger.\n * @param props - Props for the menu trigger.\n * @param state - State for the menu trigger.\n */\nexport function useMenuTrigger(props: MenuTriggerAriaProps, state: MenuTriggerState, ref: RefObject<HTMLElement>): MenuTriggerAria {\n let {\n type = 'menu' as MenuTriggerAriaProps['type'],\n isDisabled\n } = props;\n\n let menuTriggerId = useId();\n let {triggerProps, overlayProps} = useOverlayTrigger({type}, state, ref);\n\n let onKeyDown = (e) => {\n if (isDisabled) {\n return;\n }\n\n if (ref && ref.current) {\n switch (e.key) {\n case 'ArrowDown':\n case 'Enter':\n case ' ':\n // Stop propagation, unless it would already be handled by useKeyboard.\n if (!('continuePropagation' in e)) {\n e.stopPropagation();\n }\n e.preventDefault();\n state.toggle('first');\n break;\n case 'ArrowUp':\n if (!('continuePropagation' in e)) {\n e.stopPropagation();\n }\n e.preventDefault();\n state.toggle('last');\n break;\n }\n }\n };\n\n return {\n menuTriggerProps: {\n ...triggerProps,\n id: menuTriggerId,\n onPressStart(e) {\n // For consistency with native, open the menu on mouse/key down, but touch up.\n if (e.pointerType !== 'touch' && e.pointerType !== 'keyboard') {\n // If opened with a screen reader, auto focus the first item.\n // Otherwise, the menu itself will be focused.\n state.toggle(e.pointerType === 'virtual' ? 'first' : null);\n }\n },\n onPress(e) {\n if (e.pointerType === 'touch') {\n state.toggle();\n }\n },\n onKeyDown\n },\n menuProps: {\n ...overlayProps,\n 'aria-labelledby': menuTriggerId\n }\n };\n}\n","/*\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 {AriaMenuProps} from '@react-types/menu';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {HTMLAttributes, RefObject} from 'react';\nimport {KeyboardDelegate} from '@react-types/shared';\nimport {TreeState} from '@react-stately/tree';\nimport {useSelectableList} from '@react-aria/selection';\n\ninterface MenuAria {\n /** Props for the menu element. */\n menuProps: HTMLAttributes<HTMLElement>\n}\n\ninterface AriaMenuOptions<T> extends AriaMenuProps<T> {\n /** Whether the menu uses virtual scrolling. */\n isVirtualized?: boolean,\n\n /**\n * An optional keyboard delegate implementation for type to select,\n * to override the default.\n */\n keyboardDelegate?: KeyboardDelegate\n}\n\n/**\n * Provides the behavior and accessibility implementation for a menu component.\n * A menu displays a list of actions or options that a user can choose.\n * @param props - Props for the menu.\n * @param state - State for the menu, as returned by `useListState`.\n */\nexport function useMenu<T>(props: AriaMenuOptions<T>, state: TreeState<T>, ref: RefObject<HTMLElement>): MenuAria {\n let {\n shouldFocusWrap = true,\n ...otherProps\n } = props;\n\n if (!props['aria-label'] && !props['aria-labelledby']) {\n console.warn('An aria-label or aria-labelledby prop is required for accessibility.');\n }\n\n let domProps = filterDOMProps(props, {labelable: true});\n let {listProps} = useSelectableList({\n ...otherProps,\n ref,\n selectionManager: state.selectionManager,\n collection: state.collection,\n disabledKeys: state.disabledKeys,\n shouldFocusWrap\n });\n\n return {\n menuProps: mergeProps(domProps, {\n role: 'menu',\n ...listProps\n })\n };\n}\n","/*\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 {getItemCount} from '@react-stately/collections';\nimport {HTMLAttributes, Key, RefObject} from 'react';\nimport {isFocusVisible, useHover, usePress} from '@react-aria/interactions';\nimport {mergeProps, useSlotId} from '@react-aria/utils';\nimport {PressEvent} from '@react-types/shared';\nimport {TreeState} from '@react-stately/tree';\nimport {useSelectableItem} from '@react-aria/selection';\n\ninterface MenuItemAria {\n /** Props for the menu item element. */\n menuItemProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the main text element inside the menu item. */\n labelProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the description text element inside the menu item, if any. */\n descriptionProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the keyboard shortcut text element inside the item, if any. */\n keyboardShortcutProps: HTMLAttributes<HTMLElement>\n}\n\ninterface AriaMenuItemProps {\n /** Whether the menu item is disabled. */\n isDisabled?: boolean,\n\n /** Whether the menu item is selected. */\n isSelected?: boolean,\n\n /** A screen reader only label for the menu item. */\n 'aria-label'?: string,\n\n /** The unique key for the menu item. */\n key?: Key,\n\n /** Handler that is called when the menu should close after selecting an item. */\n onClose?: () => void,\n\n /**\n * Whether the menu should close when the menu item is selected.\n * @default true\n */\n closeOnSelect?: boolean,\n\n /** Whether the menu item is contained in a virtual scrolling menu. */\n isVirtualized?: boolean,\n\n /** Handler that is called when the user activates the item. */\n onAction?: (key: Key) => void\n}\n\n/**\n * Provides the behavior and accessibility implementation for an item in a menu.\n * See `useMenu` for more details about menus.\n * @param props - Props for the item.\n * @param state - State for the menu, as returned by `useTreeState`.\n */\nexport function useMenuItem<T>(props: AriaMenuItemProps, state: TreeState<T>, ref: RefObject<HTMLElement>): MenuItemAria {\n let {\n isSelected,\n isDisabled,\n key,\n onClose,\n closeOnSelect,\n isVirtualized,\n onAction\n } = props;\n\n let role = 'menuitem';\n if (state.selectionManager.selectionMode === 'single') {\n role = 'menuitemradio';\n } else if (state.selectionManager.selectionMode === 'multiple') {\n role = 'menuitemcheckbox';\n }\n\n let labelId = useSlotId();\n let descriptionId = useSlotId();\n let keyboardId = useSlotId();\n\n let ariaProps = {\n 'aria-disabled': isDisabled,\n role,\n 'aria-label': props['aria-label'],\n 'aria-labelledby': labelId,\n 'aria-describedby': [descriptionId, keyboardId].filter(Boolean).join(' ') || undefined\n };\n\n if (state.selectionManager.selectionMode !== 'none') {\n ariaProps['aria-checked'] = isSelected;\n }\n\n if (isVirtualized) {\n ariaProps['aria-posinset'] = state.collection.getItem(key).index;\n ariaProps['aria-setsize'] = getItemCount(state.collection);\n }\n\n let onKeyDown = (e: KeyboardEvent) => {\n // Ignore repeating events, which may have started on the menu trigger before moving\n // focus to the menu item. We want to wait for a second complete key press sequence.\n if (e.repeat) {\n return;\n }\n\n switch (e.key) {\n case ' ':\n if (!isDisabled && state.selectionManager.selectionMode === 'none' && closeOnSelect !== false && onClose) {\n onClose();\n }\n break;\n case 'Enter':\n // The Enter key should always close on select, except if overridden.\n if (!isDisabled && closeOnSelect !== false && onClose) {\n onClose();\n }\n break;\n }\n };\n\n let onPressStart = (e: PressEvent) => {\n if (e.pointerType === 'keyboard' && onAction) {\n onAction(key);\n }\n };\n\n let onPressUp = (e: PressEvent) => {\n if (e.pointerType !== 'keyboard') {\n if (onAction) {\n onAction(key);\n }\n\n // Pressing a menu item should close by default in single selection mode but not multiple\n // selection mode, except if overridden by the closeOnSelect prop.\n if (onClose && (closeOnSelect ?? state.selectionManager.selectionMode !== 'multiple')) {\n onClose();\n }\n }\n };\n\n let {itemProps} = useSelectableItem({\n selectionManager: state.selectionManager,\n key,\n ref,\n shouldSelectOnPressUp: true\n });\n\n let {pressProps} = usePress({onPressStart, onPressUp, isDisabled});\n let {hoverProps} = useHover({\n isDisabled,\n onHoverStart() {\n if (!isFocusVisible()) {\n state.selectionManager.setFocused(true);\n state.selectionManager.setFocusedKey(key);\n }\n }\n });\n\n return {\n menuItemProps: {\n ...ariaProps,\n ...mergeProps(itemProps, pressProps, hoverProps, {onKeyDown})\n },\n labelProps: {\n id: labelId\n },\n descriptionProps: {\n id: descriptionId\n },\n keyboardShortcutProps: {\n id: keyboardId\n }\n };\n}\n","/*\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 {HTMLAttributes, ReactNode} from 'react';\nimport {useId} from '@react-aria/utils';\n\ninterface AriaMenuSectionProps {\n /** The heading for the section. */\n heading?: ReactNode,\n /** An accessibility label for the section. Required if `heading` is not present. */\n 'aria-label'?: string\n}\n\ninterface MenuSectionAria {\n /** Props for the wrapper list item. */\n itemProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the heading element, if any. */\n headingProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the group element. */\n groupProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a section in a menu.\n * See `useMenu` for more details about menus.\n * @param props - Props for the section.\n */\nexport function useMenuSection(props: AriaMenuSectionProps): MenuSectionAria {\n let {heading, 'aria-label': ariaLabel} = props;\n let headingId = useId();\n\n return {\n itemProps: {\n role: 'presentation'\n },\n headingProps: heading ? {\n // Techincally, menus cannot contain headings according to ARIA.\n // We hide the heading from assistive technology, and only use it\n // as a label for the nested group.\n id: headingId,\n 'aria-hidden': true\n } : {},\n groupProps: {\n role: 'group',\n 'aria-label': ariaLabel,\n 'aria-labelledby': heading ? headingId : undefined\n }\n };\n}\n"],"names":["$parcel$interopDefault","a","__esModule","default","useMenuTrigger","props","state","ref","type","isDisabled","menuTriggerId","useId","triggerProps","overlayProps","useOverlayTrigger","onKeyDown","e","current","key","stopPropagation","preventDefault","toggle","menuTriggerProps","id","onPressStart","pointerType","onPress","menuProps","useMenu","shouldFocusWrap","otherProps","console","warn","domProps","filterDOMProps","labelable","listProps","useSelectableList","selectionManager","collection","disabledKeys","mergeProps","role","useMenuItem","isSelected","onClose","closeOnSelect","isVirtualized","onAction","selectionMode","labelId","useSlotId","descriptionId","keyboardId","ariaProps","filter","Boolean","join","undefined","getItem","index","getItemCount","repeat","onPressUp","itemProps","useSelectableItem","shouldSelectOnPressUp","pressProps","usePress","hoverProps","useHover","onHoverStart","isFocusVisible","setFocused","setFocusedKey","menuItemProps","labelProps","descriptionProps","keyboardShortcutProps","useMenuSection","heading","ariaLabel","headingId","headingProps","groupProps"],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -25,7 +25,7 @@ export function useMenuTrigger(props, state, ref) {
|
|
|
25
25
|
}, state, ref);
|
|
26
26
|
|
|
27
27
|
let onKeyDown = e => {
|
|
28
|
-
if (
|
|
28
|
+
if (isDisabled) {
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -34,11 +34,20 @@ export function useMenuTrigger(props, state, ref) {
|
|
|
34
34
|
case 'ArrowDown':
|
|
35
35
|
case 'Enter':
|
|
36
36
|
case ' ':
|
|
37
|
+
// Stop propagation, unless it would already be handled by useKeyboard.
|
|
38
|
+
if (!('continuePropagation' in e)) {
|
|
39
|
+
e.stopPropagation();
|
|
40
|
+
}
|
|
41
|
+
|
|
37
42
|
e.preventDefault();
|
|
38
43
|
state.toggle('first');
|
|
39
44
|
break;
|
|
40
45
|
|
|
41
46
|
case 'ArrowUp':
|
|
47
|
+
if (!('continuePropagation' in e)) {
|
|
48
|
+
e.stopPropagation();
|
|
49
|
+
}
|
|
50
|
+
|
|
42
51
|
e.preventDefault();
|
|
43
52
|
state.toggle('last');
|
|
44
53
|
break;
|
|
@@ -207,12 +216,11 @@ export function useMenuItem(props, state, ref) {
|
|
|
207
216
|
});
|
|
208
217
|
let {
|
|
209
218
|
pressProps
|
|
210
|
-
} = usePress(
|
|
219
|
+
} = usePress({
|
|
211
220
|
onPressStart,
|
|
212
221
|
onPressUp,
|
|
213
|
-
onKeyDown,
|
|
214
222
|
isDisabled
|
|
215
|
-
}
|
|
223
|
+
});
|
|
216
224
|
let {
|
|
217
225
|
hoverProps
|
|
218
226
|
} = useHover({
|
|
@@ -227,7 +235,9 @@ export function useMenuItem(props, state, ref) {
|
|
|
227
235
|
|
|
228
236
|
});
|
|
229
237
|
return {
|
|
230
|
-
menuItemProps: _babelRuntimeHelpersEsmExtends({}, ariaProps, mergeProps(pressProps, hoverProps
|
|
238
|
+
menuItemProps: _babelRuntimeHelpersEsmExtends({}, ariaProps, mergeProps(itemProps, pressProps, hoverProps, {
|
|
239
|
+
onKeyDown
|
|
240
|
+
})),
|
|
231
241
|
labelProps: {
|
|
232
242
|
id: labelId
|
|
233
243
|
},
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;AAiCA;;;;;OAKO,SAASA,cAAT,CAAwBC,KAAxB,EAAqDC,KAArD,EAA8EC,GAA9E,EAA4H;AACjI,MAAI;AACFC,IAAAA,IAAI,GAAG,MADL;AAEFC,IAAAA;AAFE,MAGAJ,KAHJ;AAKA,MAAIK,aAAa,GAAGC,KAAK,EAAzB;AACA,MAAI;AAACC,IAAAA,YAAD;AAAeC,IAAAA;AAAf,MAA+BC,iBAAiB,CAAC;AAACN,IAAAA;AAAD,GAAD,EAASF,KAAT,EAAgBC,GAAhB,CAApD;;AAEA,MAAIQ,SAAS,GAAIC,CAAD,IAAO;AACrB,QAAK,OAAOA,CAAC,CAACC,kBAAT,KAAgC,UAAhC,IAA8CD,CAAC,CAACC,kBAAF,EAA/C,IAA0ED,CAAC,CAACE,gBAA5E,IAAgGT,UAApG,EAAgH;AAC9G;AACD;;AAED,QAAIF,GAAG,IAAIA,GAAG,CAACY,OAAf,EAAwB;AACtB,cAAQH,CAAC,CAACI,GAAV;AACE,aAAK,WAAL;AACA,aAAK,OAAL;AACA,aAAK,GAAL;AACEJ,UAAAA,CAAC,CAACK,cAAF;AACAf,UAAAA,KAAK,CAACgB,MAAN,CAAa,OAAb;AACA;;AACF,aAAK,SAAL;AACEN,UAAAA,CAAC,CAACK,cAAF;AACAf,UAAAA,KAAK,CAACgB,MAAN,CAAa,MAAb;AACA;AAVJ;AAYD;AACF,GAnBD;;AAqBA,SAAO;AACLC,IAAAA,gBAAgB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ACA;AACAzD,MAAAA,EAAE,EAAE2D,SAJkB;AAKtB,qBAAe;AALO,KAAH,GAMjB,EAVC;AAWLE,IAAAA,UAAU,EAAE;AACV1C,MAAAA,IAAI,EAAE,OADI;AAEV,oBAAcuC,SAFJ;AAGV,yBAAmBD,OAAO,GAAGE,SAAH,GAAexB;AAH/B;AAXP,GAAP;AAiBD","sources":["./packages/@react-aria/menu/src/useMenuTrigger.ts","./packages/@react-aria/menu/src/useMenu.ts","./packages/@react-aria/menu/src/useMenuItem.ts","./packages/@react-aria/menu/src/useMenuSection.ts"],"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 {AriaButtonProps} from '@react-types/button';\nimport {HTMLAttributes, RefObject} from 'react';\nimport {MenuTriggerState} from '@react-stately/menu';\nimport {useId} from '@react-aria/utils';\nimport {useOverlayTrigger} from '@react-aria/overlays';\n\ninterface MenuTriggerAriaProps {\n /** The type of menu that the menu trigger opens. */\n type?: 'menu' | 'listbox',\n /** Whether menu trigger is disabled. */\n isDisabled?: boolean\n}\n\ninterface MenuTriggerAria {\n /** Props for the menu trigger element. */\n menuTriggerProps: AriaButtonProps,\n\n /** Props for the menu. */\n menuProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a menu trigger.\n * @param props - Props for the menu trigger.\n * @param state - State for the menu trigger.\n */\nexport function useMenuTrigger(props: MenuTriggerAriaProps, state: MenuTriggerState, ref: RefObject<HTMLElement>): MenuTriggerAria {\n let {\n type = 'menu' as MenuTriggerAriaProps['type'],\n isDisabled\n } = props;\n\n let menuTriggerId = useId();\n let {triggerProps, overlayProps} = useOverlayTrigger({type}, state, ref);\n\n let onKeyDown = (e) => {\n if ((typeof e.isDefaultPrevented === 'function' && e.isDefaultPrevented()) || e.defaultPrevented || isDisabled) {\n return;\n }\n\n if (ref && ref.current) {\n switch (e.key) {\n case 'ArrowDown':\n case 'Enter':\n case ' ':\n e.preventDefault();\n state.toggle('first');\n break;\n case 'ArrowUp':\n e.preventDefault();\n state.toggle('last');\n break;\n }\n }\n };\n\n return {\n menuTriggerProps: {\n ...triggerProps,\n id: menuTriggerId,\n onPressStart(e) {\n // For consistency with native, open the menu on mouse/key down, but touch up.\n if (e.pointerType !== 'touch' && e.pointerType !== 'keyboard') {\n // If opened with a screen reader, auto focus the first item.\n // Otherwise, the menu itself will be focused.\n state.toggle(e.pointerType === 'virtual' ? 'first' : null);\n }\n },\n onPress(e) {\n if (e.pointerType === 'touch') {\n state.toggle();\n }\n },\n onKeyDown\n },\n menuProps: {\n ...overlayProps,\n 'aria-labelledby': menuTriggerId\n }\n };\n}\n","/*\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 {AriaMenuProps} from '@react-types/menu';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {HTMLAttributes, RefObject} from 'react';\nimport {KeyboardDelegate} from '@react-types/shared';\nimport {TreeState} from '@react-stately/tree';\nimport {useSelectableList} from '@react-aria/selection';\n\ninterface MenuAria {\n /** Props for the menu element. */\n menuProps: HTMLAttributes<HTMLElement>\n}\n\ninterface AriaMenuOptions<T> extends AriaMenuProps<T> {\n /** Whether the menu uses virtual scrolling. */\n isVirtualized?: boolean,\n\n /**\n * An optional keyboard delegate implementation for type to select,\n * to override the default.\n */\n keyboardDelegate?: KeyboardDelegate\n}\n\n/**\n * Provides the behavior and accessibility implementation for a menu component.\n * A menu displays a list of actions or options that a user can choose.\n * @param props - Props for the menu.\n * @param state - State for the menu, as returned by `useListState`.\n */\nexport function useMenu<T>(props: AriaMenuOptions<T>, state: TreeState<T>, ref: RefObject<HTMLElement>): MenuAria {\n let {\n shouldFocusWrap = true,\n ...otherProps\n } = props;\n\n if (!props['aria-label'] && !props['aria-labelledby']) {\n console.warn('An aria-label or aria-labelledby prop is required for accessibility.');\n }\n\n let domProps = filterDOMProps(props, {labelable: true});\n let {listProps} = useSelectableList({\n ...otherProps,\n ref,\n selectionManager: state.selectionManager,\n collection: state.collection,\n disabledKeys: state.disabledKeys,\n shouldFocusWrap\n });\n\n return {\n menuProps: mergeProps(domProps, {\n role: 'menu',\n ...listProps\n })\n };\n}\n","/*\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 {getItemCount} from '@react-stately/collections';\nimport {HTMLAttributes, Key, RefObject} from 'react';\nimport {isFocusVisible, useHover, usePress} from '@react-aria/interactions';\nimport {mergeProps, useSlotId} from '@react-aria/utils';\nimport {PressEvent} from '@react-types/shared';\nimport {TreeState} from '@react-stately/tree';\nimport {useSelectableItem} from '@react-aria/selection';\n\ninterface MenuItemAria {\n /** Props for the menu item element. */\n menuItemProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the main text element inside the menu item. */\n labelProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the description text element inside the menu item, if any. */\n descriptionProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the keyboard shortcut text element inside the item, if any. */\n keyboardShortcutProps: HTMLAttributes<HTMLElement>\n}\n\ninterface AriaMenuItemProps {\n /** Whether the menu item is disabled. */\n isDisabled?: boolean,\n\n /** Whether the menu item is selected. */\n isSelected?: boolean,\n\n /** A screen reader only label for the menu item. */\n 'aria-label'?: string,\n\n /** The unique key for the menu item. */\n key?: Key,\n\n /** Handler that is called when the menu should close after selecting an item. */\n onClose?: () => void,\n\n /**\n * Whether the menu should close when the menu item is selected.\n * @default true\n */\n closeOnSelect?: boolean,\n\n /** Whether the menu item is contained in a virtual scrolling menu. */\n isVirtualized?: boolean,\n\n /** Handler that is called when the user activates the item. */\n onAction?: (key: Key) => void\n}\n\n/**\n * Provides the behavior and accessibility implementation for an item in a menu.\n * See `useMenu` for more details about menus.\n * @param props - Props for the item.\n * @param state - State for the menu, as returned by `useTreeState`.\n */\nexport function useMenuItem<T>(props: AriaMenuItemProps, state: TreeState<T>, ref: RefObject<HTMLElement>): MenuItemAria {\n let {\n isSelected,\n isDisabled,\n key,\n onClose,\n closeOnSelect,\n isVirtualized,\n onAction\n } = props;\n\n let role = 'menuitem';\n if (state.selectionManager.selectionMode === 'single') {\n role = 'menuitemradio';\n } else if (state.selectionManager.selectionMode === 'multiple') {\n role = 'menuitemcheckbox';\n }\n\n let labelId = useSlotId();\n let descriptionId = useSlotId();\n let keyboardId = useSlotId();\n\n let ariaProps = {\n 'aria-disabled': isDisabled,\n role,\n 'aria-label': props['aria-label'],\n 'aria-labelledby': labelId,\n 'aria-describedby': [descriptionId, keyboardId].filter(Boolean).join(' ') || undefined\n };\n\n if (state.selectionManager.selectionMode !== 'none') {\n ariaProps['aria-checked'] = isSelected;\n }\n\n if (isVirtualized) {\n ariaProps['aria-posinset'] = state.collection.getItem(key).index;\n ariaProps['aria-setsize'] = getItemCount(state.collection);\n }\n\n let onKeyDown = (e: KeyboardEvent) => {\n // Ignore repeating events, which may have started on the menu trigger before moving\n // focus to the menu item. We want to wait for a second complete key press sequence.\n if (e.repeat) {\n return;\n }\n\n switch (e.key) {\n case ' ':\n if (!isDisabled && state.selectionManager.selectionMode === 'none' && closeOnSelect !== false && onClose) {\n onClose();\n }\n break;\n case 'Enter':\n // The Enter key should always close on select, except if overridden.\n if (!isDisabled && closeOnSelect !== false && onClose) {\n onClose();\n }\n break;\n }\n };\n\n let onPressStart = (e: PressEvent) => {\n if (e.pointerType === 'keyboard' && onAction) {\n onAction(key);\n }\n };\n\n let onPressUp = (e: PressEvent) => {\n if (e.pointerType !== 'keyboard') {\n if (onAction) {\n onAction(key);\n }\n\n // Pressing a menu item should close by default in single selection mode but not multiple\n // selection mode, except if overridden by the closeOnSelect prop.\n if (onClose && (closeOnSelect ?? state.selectionManager.selectionMode !== 'multiple')) {\n onClose();\n }\n }\n };\n\n let {itemProps} = useSelectableItem({\n selectionManager: state.selectionManager,\n key,\n ref,\n shouldSelectOnPressUp: true\n });\n\n let {pressProps} = usePress(mergeProps({onPressStart, onPressUp, onKeyDown, isDisabled}, itemProps));\n let {hoverProps} = useHover({\n isDisabled,\n onHoverStart() {\n if (!isFocusVisible()) {\n state.selectionManager.setFocused(true);\n state.selectionManager.setFocusedKey(key);\n }\n }\n });\n\n return {\n menuItemProps: {\n ...ariaProps,\n ...mergeProps(pressProps, hoverProps)\n },\n labelProps: {\n id: labelId\n },\n descriptionProps: {\n id: descriptionId\n },\n keyboardShortcutProps: {\n id: keyboardId\n }\n };\n}\n","/*\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 {HTMLAttributes, ReactNode} from 'react';\nimport {useId} from '@react-aria/utils';\n\ninterface AriaMenuSectionProps {\n /** The heading for the section. */\n heading?: ReactNode,\n /** An accessibility label for the section. Required if `heading` is not present. */\n 'aria-label'?: string\n}\n\ninterface MenuSectionAria {\n /** Props for the wrapper list item. */\n itemProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the heading element, if any. */\n headingProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the group element. */\n groupProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a section in a menu.\n * See `useMenu` for more details about menus.\n * @param props - Props for the section.\n */\nexport function useMenuSection(props: AriaMenuSectionProps): MenuSectionAria {\n let {heading, 'aria-label': ariaLabel} = props;\n let headingId = useId();\n\n return {\n itemProps: {\n role: 'presentation'\n },\n headingProps: heading ? {\n // Techincally, menus cannot contain headings according to ARIA.\n // We hide the heading from assistive technology, and only use it\n // as a label for the nested group.\n id: headingId,\n 'aria-hidden': true\n } : {},\n groupProps: {\n role: 'group',\n 'aria-label': ariaLabel,\n 'aria-labelledby': heading ? headingId : undefined\n }\n };\n}\n"],"names":["useMenuTrigger","props","state","ref","type","isDisabled","menuTriggerId","useId","triggerProps","overlayProps","useOverlayTrigger","onKeyDown","e","isDefaultPrevented","defaultPrevented","current","key","preventDefault","toggle","menuTriggerProps","id","onPressStart","pointerType","onPress","menuProps","useMenu","shouldFocusWrap","otherProps","console","warn","domProps","filterDOMProps","labelable","listProps","useSelectableList","selectionManager","collection","disabledKeys","mergeProps","role","useMenuItem","isSelected","onClose","closeOnSelect","isVirtualized","onAction","selectionMode","labelId","useSlotId","descriptionId","keyboardId","ariaProps","filter","Boolean","join","undefined","getItem","index","getItemCount","repeat","onPressUp","itemProps","useSelectableItem","shouldSelectOnPressUp","pressProps","usePress","hoverProps","useHover","onHoverStart","isFocusVisible","setFocused","setFocusedKey","menuItemProps","labelProps","descriptionProps","keyboardShortcutProps","useMenuSection","heading","ariaLabel","headingId","headingProps","groupPro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;AAiBD","sources":["./packages/@react-aria/menu/src/useMenuTrigger.ts","./packages/@react-aria/menu/src/useMenu.ts","./packages/@react-aria/menu/src/useMenuItem.ts","./packages/@react-aria/menu/src/useMenuSection.ts"],"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 {AriaButtonProps} from '@react-types/button';\nimport {HTMLAttributes, RefObject} from 'react';\nimport {MenuTriggerState} from '@react-stately/menu';\nimport {useId} from '@react-aria/utils';\nimport {useOverlayTrigger} from '@react-aria/overlays';\n\ninterface MenuTriggerAriaProps {\n /** The type of menu that the menu trigger opens. */\n type?: 'menu' | 'listbox',\n /** Whether menu trigger is disabled. */\n isDisabled?: boolean\n}\n\ninterface MenuTriggerAria {\n /** Props for the menu trigger element. */\n menuTriggerProps: AriaButtonProps,\n\n /** Props for the menu. */\n menuProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a menu trigger.\n * @param props - Props for the menu trigger.\n * @param state - State for the menu trigger.\n */\nexport function useMenuTrigger(props: MenuTriggerAriaProps, state: MenuTriggerState, ref: RefObject<HTMLElement>): MenuTriggerAria {\n let {\n type = 'menu' as MenuTriggerAriaProps['type'],\n isDisabled\n } = props;\n\n let menuTriggerId = useId();\n let {triggerProps, overlayProps} = useOverlayTrigger({type}, state, ref);\n\n let onKeyDown = (e) => {\n if (isDisabled) {\n return;\n }\n\n if (ref && ref.current) {\n switch (e.key) {\n case 'ArrowDown':\n case 'Enter':\n case ' ':\n // Stop propagation, unless it would already be handled by useKeyboard.\n if (!('continuePropagation' in e)) {\n e.stopPropagation();\n }\n e.preventDefault();\n state.toggle('first');\n break;\n case 'ArrowUp':\n if (!('continuePropagation' in e)) {\n e.stopPropagation();\n }\n e.preventDefault();\n state.toggle('last');\n break;\n }\n }\n };\n\n return {\n menuTriggerProps: {\n ...triggerProps,\n id: menuTriggerId,\n onPressStart(e) {\n // For consistency with native, open the menu on mouse/key down, but touch up.\n if (e.pointerType !== 'touch' && e.pointerType !== 'keyboard') {\n // If opened with a screen reader, auto focus the first item.\n // Otherwise, the menu itself will be focused.\n state.toggle(e.pointerType === 'virtual' ? 'first' : null);\n }\n },\n onPress(e) {\n if (e.pointerType === 'touch') {\n state.toggle();\n }\n },\n onKeyDown\n },\n menuProps: {\n ...overlayProps,\n 'aria-labelledby': menuTriggerId\n }\n };\n}\n","/*\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 {AriaMenuProps} from '@react-types/menu';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {HTMLAttributes, RefObject} from 'react';\nimport {KeyboardDelegate} from '@react-types/shared';\nimport {TreeState} from '@react-stately/tree';\nimport {useSelectableList} from '@react-aria/selection';\n\ninterface MenuAria {\n /** Props for the menu element. */\n menuProps: HTMLAttributes<HTMLElement>\n}\n\ninterface AriaMenuOptions<T> extends AriaMenuProps<T> {\n /** Whether the menu uses virtual scrolling. */\n isVirtualized?: boolean,\n\n /**\n * An optional keyboard delegate implementation for type to select,\n * to override the default.\n */\n keyboardDelegate?: KeyboardDelegate\n}\n\n/**\n * Provides the behavior and accessibility implementation for a menu component.\n * A menu displays a list of actions or options that a user can choose.\n * @param props - Props for the menu.\n * @param state - State for the menu, as returned by `useListState`.\n */\nexport function useMenu<T>(props: AriaMenuOptions<T>, state: TreeState<T>, ref: RefObject<HTMLElement>): MenuAria {\n let {\n shouldFocusWrap = true,\n ...otherProps\n } = props;\n\n if (!props['aria-label'] && !props['aria-labelledby']) {\n console.warn('An aria-label or aria-labelledby prop is required for accessibility.');\n }\n\n let domProps = filterDOMProps(props, {labelable: true});\n let {listProps} = useSelectableList({\n ...otherProps,\n ref,\n selectionManager: state.selectionManager,\n collection: state.collection,\n disabledKeys: state.disabledKeys,\n shouldFocusWrap\n });\n\n return {\n menuProps: mergeProps(domProps, {\n role: 'menu',\n ...listProps\n })\n };\n}\n","/*\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 {getItemCount} from '@react-stately/collections';\nimport {HTMLAttributes, Key, RefObject} from 'react';\nimport {isFocusVisible, useHover, usePress} from '@react-aria/interactions';\nimport {mergeProps, useSlotId} from '@react-aria/utils';\nimport {PressEvent} from '@react-types/shared';\nimport {TreeState} from '@react-stately/tree';\nimport {useSelectableItem} from '@react-aria/selection';\n\ninterface MenuItemAria {\n /** Props for the menu item element. */\n menuItemProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the main text element inside the menu item. */\n labelProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the description text element inside the menu item, if any. */\n descriptionProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the keyboard shortcut text element inside the item, if any. */\n keyboardShortcutProps: HTMLAttributes<HTMLElement>\n}\n\ninterface AriaMenuItemProps {\n /** Whether the menu item is disabled. */\n isDisabled?: boolean,\n\n /** Whether the menu item is selected. */\n isSelected?: boolean,\n\n /** A screen reader only label for the menu item. */\n 'aria-label'?: string,\n\n /** The unique key for the menu item. */\n key?: Key,\n\n /** Handler that is called when the menu should close after selecting an item. */\n onClose?: () => void,\n\n /**\n * Whether the menu should close when the menu item is selected.\n * @default true\n */\n closeOnSelect?: boolean,\n\n /** Whether the menu item is contained in a virtual scrolling menu. */\n isVirtualized?: boolean,\n\n /** Handler that is called when the user activates the item. */\n onAction?: (key: Key) => void\n}\n\n/**\n * Provides the behavior and accessibility implementation for an item in a menu.\n * See `useMenu` for more details about menus.\n * @param props - Props for the item.\n * @param state - State for the menu, as returned by `useTreeState`.\n */\nexport function useMenuItem<T>(props: AriaMenuItemProps, state: TreeState<T>, ref: RefObject<HTMLElement>): MenuItemAria {\n let {\n isSelected,\n isDisabled,\n key,\n onClose,\n closeOnSelect,\n isVirtualized,\n onAction\n } = props;\n\n let role = 'menuitem';\n if (state.selectionManager.selectionMode === 'single') {\n role = 'menuitemradio';\n } else if (state.selectionManager.selectionMode === 'multiple') {\n role = 'menuitemcheckbox';\n }\n\n let labelId = useSlotId();\n let descriptionId = useSlotId();\n let keyboardId = useSlotId();\n\n let ariaProps = {\n 'aria-disabled': isDisabled,\n role,\n 'aria-label': props['aria-label'],\n 'aria-labelledby': labelId,\n 'aria-describedby': [descriptionId, keyboardId].filter(Boolean).join(' ') || undefined\n };\n\n if (state.selectionManager.selectionMode !== 'none') {\n ariaProps['aria-checked'] = isSelected;\n }\n\n if (isVirtualized) {\n ariaProps['aria-posinset'] = state.collection.getItem(key).index;\n ariaProps['aria-setsize'] = getItemCount(state.collection);\n }\n\n let onKeyDown = (e: KeyboardEvent) => {\n // Ignore repeating events, which may have started on the menu trigger before moving\n // focus to the menu item. We want to wait for a second complete key press sequence.\n if (e.repeat) {\n return;\n }\n\n switch (e.key) {\n case ' ':\n if (!isDisabled && state.selectionManager.selectionMode === 'none' && closeOnSelect !== false && onClose) {\n onClose();\n }\n break;\n case 'Enter':\n // The Enter key should always close on select, except if overridden.\n if (!isDisabled && closeOnSelect !== false && onClose) {\n onClose();\n }\n break;\n }\n };\n\n let onPressStart = (e: PressEvent) => {\n if (e.pointerType === 'keyboard' && onAction) {\n onAction(key);\n }\n };\n\n let onPressUp = (e: PressEvent) => {\n if (e.pointerType !== 'keyboard') {\n if (onAction) {\n onAction(key);\n }\n\n // Pressing a menu item should close by default in single selection mode but not multiple\n // selection mode, except if overridden by the closeOnSelect prop.\n if (onClose && (closeOnSelect ?? state.selectionManager.selectionMode !== 'multiple')) {\n onClose();\n }\n }\n };\n\n let {itemProps} = useSelectableItem({\n selectionManager: state.selectionManager,\n key,\n ref,\n shouldSelectOnPressUp: true\n });\n\n let {pressProps} = usePress({onPressStart, onPressUp, isDisabled});\n let {hoverProps} = useHover({\n isDisabled,\n onHoverStart() {\n if (!isFocusVisible()) {\n state.selectionManager.setFocused(true);\n state.selectionManager.setFocusedKey(key);\n }\n }\n });\n\n return {\n menuItemProps: {\n ...ariaProps,\n ...mergeProps(itemProps, pressProps, hoverProps, {onKeyDown})\n },\n labelProps: {\n id: labelId\n },\n descriptionProps: {\n id: descriptionId\n },\n keyboardShortcutProps: {\n id: keyboardId\n }\n };\n}\n","/*\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 {HTMLAttributes, ReactNode} from 'react';\nimport {useId} from '@react-aria/utils';\n\ninterface AriaMenuSectionProps {\n /** The heading for the section. */\n heading?: ReactNode,\n /** An accessibility label for the section. Required if `heading` is not present. */\n 'aria-label'?: string\n}\n\ninterface MenuSectionAria {\n /** Props for the wrapper list item. */\n itemProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the heading element, if any. */\n headingProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the group element. */\n groupProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a section in a menu.\n * See `useMenu` for more details about menus.\n * @param props - Props for the section.\n */\nexport function useMenuSection(props: AriaMenuSectionProps): MenuSectionAria {\n let {heading, 'aria-label': ariaLabel} = props;\n let headingId = useId();\n\n return {\n itemProps: {\n role: 'presentation'\n },\n headingProps: heading ? {\n // Techincally, menus cannot contain headings according to ARIA.\n // We hide the heading from assistive technology, and only use it\n // as a label for the nested group.\n id: headingId,\n 'aria-hidden': true\n } : {},\n groupProps: {\n role: 'group',\n 'aria-label': ariaLabel,\n 'aria-labelledby': heading ? headingId : undefined\n }\n };\n}\n"],"names":["useMenuTrigger","props","state","ref","type","isDisabled","menuTriggerId","useId","triggerProps","overlayProps","useOverlayTrigger","onKeyDown","e","current","key","stopPropagation","preventDefault","toggle","menuTriggerProps","id","onPressStart","pointerType","onPress","menuProps","useMenu","shouldFocusWrap","otherProps","console","warn","domProps","filterDOMProps","labelable","listProps","useSelectableList","selectionManager","collection","disabledKeys","mergeProps","role","useMenuItem","isSelected","onClose","closeOnSelect","isVirtualized","onAction","selectionMode","labelId","useSlotId","descriptionId","keyboardId","ariaProps","filter","Boolean","join","undefined","getItem","index","getItemCount","repeat","onPressUp","itemProps","useSelectableItem","shouldSelectOnPressUp","pressProps","usePress","hoverProps","useHover","onHoverStart","isFocusVisible","setFocused","setFocusedKey","menuItemProps","labelProps","descriptionProps","keyboardShortcutProps","useMenuSection","heading","ariaLabel","headingId","headingProps","groupProps"],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"A;A;A;A;A;A;AAkBA;IACE,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,wCAA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2EAA2E;IAC3E,gBAAgB,EAAE,eAAe,WAAW,CAAC,CAAC;IAE9C,4EAA4E;IAC5E,qBAAqB,EAAE,eAAe,WAAW,CAAC,CAAA;CACnD;AAED;IACE,yCAAyC;IACzC,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB,yCAAyC;IACzC,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB,oDAAoD;IACpD,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,wCAAwC;IACxC,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV,iFAAiF;IACjF,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IAErB;A;A;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,sEAAsE;IACtE,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAA;CAC9B;AAED;A;A;A;A;GAKG;AACH,4BAA4B,CAAC,EAAE,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,WAAW,CAAC,GAAG,YAAY,CAkHvH;ACxKD;IACE,mCAAmC;IACnC,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,oFAAoF;IACpF,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED;IACE,uCAAuC;IACvC,SAAS,EAAE,eAAe,WAAW,CAAC,CAAC;IAEvC,6CAA6C;IAC7C,YAAY,EAAE,eAAe,WAAW,CAAC,CAAC;IAE1C,mCAAmC;IACnC,UAAU,EAAE,eAAe,WAAW,CAAC,CAAA;CACxC;AAED;A;A;A;GAIG;AACH,+BAA+B,KAAK,EAAE,oBAAoB,GAAG,eAAe,CAqB3E","sources":["./packages/@react-aria/menu/src/packages/@react-aria/menu/src/useMenuTrigger.ts","./packages/@react-aria/menu/src/packages/@react-aria/menu/src/useMenu.ts","./packages/@react-aria/menu/src/packages/@react-aria/menu/src/useMenuItem.ts","./packages/@react-aria/menu/src/packages/@react-aria/menu/src/useMenuSection.ts","./packages/@react-aria/menu/src/packages/@react-aria/menu/src/index.ts"],"sourcesContent":[null,null,null,null,null],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/menu",
|
|
3
|
-
"version": "3.2.4-nightly.
|
|
3
|
+
"version": "3.2.4-nightly.2967+252940a26",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -18,16 +18,16 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.6.2",
|
|
21
|
-
"@react-aria/interactions": "3.0.0-nightly.
|
|
22
|
-
"@react-aria/overlays": "3.0.0-nightly.
|
|
23
|
-
"@react-aria/selection": "3.0.0-nightly.
|
|
24
|
-
"@react-aria/utils": "3.0.0-nightly.
|
|
25
|
-
"@react-stately/collections": "3.0.0-nightly.
|
|
26
|
-
"@react-stately/menu": "3.2.4-nightly.
|
|
27
|
-
"@react-stately/tree": "3.0.0-nightly.
|
|
28
|
-
"@react-types/button": "3.4.2-nightly.
|
|
29
|
-
"@react-types/menu": "3.4.2-nightly.
|
|
30
|
-
"@react-types/shared": "3.0.0-nightly.
|
|
21
|
+
"@react-aria/interactions": "3.0.0-nightly.1281+252940a26",
|
|
22
|
+
"@react-aria/overlays": "3.0.0-nightly.1281+252940a26",
|
|
23
|
+
"@react-aria/selection": "3.0.0-nightly.1281+252940a26",
|
|
24
|
+
"@react-aria/utils": "3.0.0-nightly.1281+252940a26",
|
|
25
|
+
"@react-stately/collections": "3.0.0-nightly.1281+252940a26",
|
|
26
|
+
"@react-stately/menu": "3.2.4-nightly.2967+252940a26",
|
|
27
|
+
"@react-stately/tree": "3.0.0-nightly.1281+252940a26",
|
|
28
|
+
"@react-types/button": "3.4.2-nightly.2967+252940a26",
|
|
29
|
+
"@react-types/menu": "3.4.2-nightly.2967+252940a26",
|
|
30
|
+
"@react-types/shared": "3.0.0-nightly.1281+252940a26"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"react": "^16.8.0 || ^17.0.0-rc.1",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "252940a267857896b75c988a5cc0ec199e740fcb"
|
|
40
40
|
}
|
package/src/useMenuItem.ts
CHANGED
|
@@ -155,7 +155,7 @@ export function useMenuItem<T>(props: AriaMenuItemProps, state: TreeState<T>, re
|
|
|
155
155
|
shouldSelectOnPressUp: true
|
|
156
156
|
});
|
|
157
157
|
|
|
158
|
-
let {pressProps} = usePress(
|
|
158
|
+
let {pressProps} = usePress({onPressStart, onPressUp, isDisabled});
|
|
159
159
|
let {hoverProps} = useHover({
|
|
160
160
|
isDisabled,
|
|
161
161
|
onHoverStart() {
|
|
@@ -169,7 +169,7 @@ export function useMenuItem<T>(props: AriaMenuItemProps, state: TreeState<T>, re
|
|
|
169
169
|
return {
|
|
170
170
|
menuItemProps: {
|
|
171
171
|
...ariaProps,
|
|
172
|
-
...mergeProps(pressProps, hoverProps)
|
|
172
|
+
...mergeProps(itemProps, pressProps, hoverProps, {onKeyDown})
|
|
173
173
|
},
|
|
174
174
|
labelProps: {
|
|
175
175
|
id: labelId
|
package/src/useMenuTrigger.ts
CHANGED
|
@@ -46,7 +46,7 @@ export function useMenuTrigger(props: MenuTriggerAriaProps, state: MenuTriggerSt
|
|
|
46
46
|
let {triggerProps, overlayProps} = useOverlayTrigger({type}, state, ref);
|
|
47
47
|
|
|
48
48
|
let onKeyDown = (e) => {
|
|
49
|
-
if (
|
|
49
|
+
if (isDisabled) {
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
52
|
|
|
@@ -55,10 +55,17 @@ export function useMenuTrigger(props: MenuTriggerAriaProps, state: MenuTriggerSt
|
|
|
55
55
|
case 'ArrowDown':
|
|
56
56
|
case 'Enter':
|
|
57
57
|
case ' ':
|
|
58
|
+
// Stop propagation, unless it would already be handled by useKeyboard.
|
|
59
|
+
if (!('continuePropagation' in e)) {
|
|
60
|
+
e.stopPropagation();
|
|
61
|
+
}
|
|
58
62
|
e.preventDefault();
|
|
59
63
|
state.toggle('first');
|
|
60
64
|
break;
|
|
61
65
|
case 'ArrowUp':
|
|
66
|
+
if (!('continuePropagation' in e)) {
|
|
67
|
+
e.stopPropagation();
|
|
68
|
+
}
|
|
62
69
|
e.preventDefault();
|
|
63
70
|
state.toggle('last');
|
|
64
71
|
break;
|