@react-aria/menu 3.2.4-nightly.2976 → 3.2.4-nightly.2995
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 +2 -2
- package/dist/main.js.map +1 -1
- package/dist/module.js +2 -2
- package/dist/module.js.map +1 -1
- package/package.json +12 -12
- package/src/useMenuTrigger.ts +2 -2
package/dist/main.js
CHANGED
|
@@ -87,7 +87,7 @@ function useMenuTrigger(props, state, ref) {
|
|
|
87
87
|
|
|
88
88
|
onPressStart(e) {
|
|
89
89
|
// For consistency with native, open the menu on mouse/key down, but touch up.
|
|
90
|
-
if (e.pointerType !== 'touch' && e.pointerType !== 'keyboard') {
|
|
90
|
+
if (e.pointerType !== 'touch' && e.pointerType !== 'keyboard' && !isDisabled) {
|
|
91
91
|
// If opened with a screen reader, auto focus the first item.
|
|
92
92
|
// Otherwise, the menu itself will be focused.
|
|
93
93
|
state.toggle(e.pointerType === 'virtual' ? 'first' : null);
|
|
@@ -95,7 +95,7 @@ function useMenuTrigger(props, state, ref) {
|
|
|
95
95
|
},
|
|
96
96
|
|
|
97
97
|
onPress(e) {
|
|
98
|
-
if (e.pointerType === 'touch') {
|
|
98
|
+
if (e.pointerType === 'touch' && !isDisabled) {
|
|
99
99
|
state.toggle();
|
|
100
100
|
}
|
|
101
101
|
},
|
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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C,gBAAN,CAAuBmC,UAAvB,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"}
|
|
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,QAAIP,UAAJ,EAAgB;AACd;AACD;;AAED,QAAIF,GAAG,IAAIA,GAAG,CAACU,OAAf,EAAwB;AACtB,cAAQD,CAAC,CAACE,GAAV;AACE,aAAK,WAAL;AACA,aAAK,OAAL;AACA,aAAK,GAAL;AACE;AACA,cAAI,EAAE,yBAAyBF,CAA3B,CAAJ,EAAmC;AACjCA,YAAAA,CAAC,CAACG,eAAF;AACD;;AACDH,UAAAA,CAAC,CAACI,cAAF;AACAd,UAAAA,KAAK,CAACe,MAAN,CAAa,OAAb;AACA;;AACF,aAAK,SAAL;AACE,cAAI,EAAE,yBAAyBL,CAA3B,CAAJ,EAAmC;AACjCA,YAAAA,CAAC,CAACG,eAAF;AACD;;AACDH,UAAAA,CAAC,CAACI,cAAF;AACAd,UA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,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' && !isDisabled) {\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' && !isDisabled) {\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
|
@@ -61,7 +61,7 @@ export function useMenuTrigger(props, state, ref) {
|
|
|
61
61
|
|
|
62
62
|
onPressStart(e) {
|
|
63
63
|
// For consistency with native, open the menu on mouse/key down, but touch up.
|
|
64
|
-
if (e.pointerType !== 'touch' && e.pointerType !== 'keyboard') {
|
|
64
|
+
if (e.pointerType !== 'touch' && e.pointerType !== 'keyboard' && !isDisabled) {
|
|
65
65
|
// If opened with a screen reader, auto focus the first item.
|
|
66
66
|
// Otherwise, the menu itself will be focused.
|
|
67
67
|
state.toggle(e.pointerType === 'virtual' ? 'first' : null);
|
|
@@ -69,7 +69,7 @@ export function useMenuTrigger(props, state, ref) {
|
|
|
69
69
|
},
|
|
70
70
|
|
|
71
71
|
onPress(e) {
|
|
72
|
-
if (e.pointerType === 'touch') {
|
|
72
|
+
if (e.pointerType === 'touch' && !isDisabled) {
|
|
73
73
|
state.toggle();
|
|
74
74
|
}
|
|
75
75
|
},
|
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,QAAIP,UAAJ,EAAgB;AACd;AACD;;AAED,QAAIF,GAAG,IAAIA,GAAG,CAACU,OAAf,EAAwB;AACtB,cAAQD,CAAC,CAACE,GAAV;AACE,aAAK,WAAL;AACA,aAAK,OAAL;AACA,aAAK,GAAL;AACE;AACA,cAAI,EAAE,yBAAyBF,CAA3B,CAAJ,EAAmC;AACjCA,YAAAA,CAAC,CAACG,eAAF;AACD;;AACDH,UAAAA,CAAC,CAACI,cAAF;AACAd,UAAAA,KAAK,CAACe,MAAN,CAAa,OAAb;AACA;;AACF,aAAK,SAAL;AACE,cAAI,EAAE,yBAAyBL,CAA3B,CAAJ,EAAmC;AACjCA,YAAAA,CAAC,CAACG,eAAF;AACD;;AACDH,UAAAA,CAAC,CAACI,cAAF;AACAd,UAAAA,KAAK,CAACe,MAAN,CAAa,MAAb;AACA;AAjBJ;AAmBD;AACF,GA1BD;;AA4BA,SAAO;AACLC,IAAAA,gBAAgB,qCACXV,YADW;AAEdW,MAAAA,EAAE,EAAEb,aAFU;;AAGdc,MAAA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H,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 (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"}
|
|
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;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 (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' && !isDisabled) {\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' && !isDisabled) {\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/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.2995+c02ede9cc",
|
|
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.1309+c02ede9cc",
|
|
22
|
+
"@react-aria/overlays": "3.0.0-nightly.1309+c02ede9cc",
|
|
23
|
+
"@react-aria/selection": "3.0.0-nightly.1309+c02ede9cc",
|
|
24
|
+
"@react-aria/utils": "3.0.0-nightly.1309+c02ede9cc",
|
|
25
|
+
"@react-stately/collections": "3.0.0-nightly.1309+c02ede9cc",
|
|
26
|
+
"@react-stately/menu": "3.2.4-nightly.2995+c02ede9cc",
|
|
27
|
+
"@react-stately/tree": "3.0.0-nightly.1309+c02ede9cc",
|
|
28
|
+
"@react-types/button": "3.4.2-nightly.2995+c02ede9cc",
|
|
29
|
+
"@react-types/menu": "3.4.2-nightly.2995+c02ede9cc",
|
|
30
|
+
"@react-types/shared": "3.0.0-nightly.1309+c02ede9cc"
|
|
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": "c02ede9cc6204ac734379d93b34593f77e32c46d"
|
|
40
40
|
}
|
package/src/useMenuTrigger.ts
CHANGED
|
@@ -79,14 +79,14 @@ export function useMenuTrigger(props: MenuTriggerAriaProps, state: MenuTriggerSt
|
|
|
79
79
|
id: menuTriggerId,
|
|
80
80
|
onPressStart(e) {
|
|
81
81
|
// For consistency with native, open the menu on mouse/key down, but touch up.
|
|
82
|
-
if (e.pointerType !== 'touch' && e.pointerType !== 'keyboard') {
|
|
82
|
+
if (e.pointerType !== 'touch' && e.pointerType !== 'keyboard' && !isDisabled) {
|
|
83
83
|
// If opened with a screen reader, auto focus the first item.
|
|
84
84
|
// Otherwise, the menu itself will be focused.
|
|
85
85
|
state.toggle(e.pointerType === 'virtual' ? 'first' : null);
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
88
|
onPress(e) {
|
|
89
|
-
if (e.pointerType === 'touch') {
|
|
89
|
+
if (e.pointerType === 'touch' && !isDisabled) {
|
|
90
90
|
state.toggle();
|
|
91
91
|
}
|
|
92
92
|
},
|