@react-aria/radio 3.1.2 → 3.1.6
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 +1 -5
- package/dist/main.js.map +1 -1
- package/dist/module.js +1 -5
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +1 -11
- package/dist/types.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/useRadio.ts +3 -17
package/dist/main.js
CHANGED
|
@@ -51,13 +51,11 @@ const $d9900fa75ce48f638bc47fd54695f66$export$radioGroupNames = new WeakMap();
|
|
|
51
51
|
function useRadio(props, state, ref) {
|
|
52
52
|
let {
|
|
53
53
|
value,
|
|
54
|
-
isRequired,
|
|
55
|
-
isReadOnly,
|
|
56
|
-
isDisabled,
|
|
57
54
|
children,
|
|
58
55
|
'aria-label': ariaLabel,
|
|
59
56
|
'aria-labelledby': ariaLabelledby
|
|
60
57
|
} = props;
|
|
58
|
+
const isDisabled = props.isDisabled || state.isDisabled;
|
|
61
59
|
let hasChildren = children != null;
|
|
62
60
|
let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;
|
|
63
61
|
|
|
@@ -98,8 +96,6 @@ function useRadio(props, state, ref) {
|
|
|
98
96
|
name: $d9900fa75ce48f638bc47fd54695f66$export$radioGroupNames.get(state),
|
|
99
97
|
tabIndex,
|
|
100
98
|
disabled: isDisabled,
|
|
101
|
-
readOnly: isReadOnly,
|
|
102
|
-
required: isRequired,
|
|
103
99
|
checked,
|
|
104
100
|
value,
|
|
105
101
|
onChange
|
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;;ACFD;;;;;;;;;;;AAcO,MAAMG,uDAAe,GAAG,IA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GL,MAAM,CAACU,SAAP,EAAX;AACD;AACF;;AACD,QAAIL,QAAJ,EAAc;AACZ;AACAA,MAAAA,QAAQ,CAACM,KAAT;AACAnE,MAAAA,KAAK,CAACkB,gBAAN,CAAuB2C,QAAQ,CAAC3D,KAAhC;AACD;AACF,GA/CD;;AAiDA,MAAIkE,SAAS,GAAGC,KAAK,CAAClC,IAAD,CAArB;AACA,0DAAgBmC,GAAhB,CAAoBtE,KAApB,EAA2BoE,SAA3B;AAEA,SAAO;AACLG,IAAAA,eAAe,EAAEhD,UAAU,CAACI,QAAD;AACzB;AACA6C,MAAAA,IAAI,EAAE,YAFmB;AAGzBpB,MAAAA,SAHyB;AAIzB,sBAAgBX,eAAe,KAAK,SAApB,IAAiCT,SAJxB;AAKzB,2BAAqBjC,KAAK,CAAC,mBAAD,CALD;AAMzB,uBAAiBK,UAAU,IAAI4B,SANN;AAOzB,uBAAiB7B,UAAU,IAAI6B,SAPN;AAQzB,uBAAiB3B,UAAU,IAAI2B,SARN;AASzB,0BAAoBU;AATK,OAUtBI,UAVsB,EAWtBG,gBAXsB,EADtB;AAcLJ,IAAAA;AAdK,GAAP;AAgBD","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/@react-aria/radio/src/utils.ts","./packages/@react-aria/radio/src/useRadio.ts","./packages/@react-aria/radio/src/useRadioGroup.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 {RadioGroupState} from '@react-stately/radio';\n\nexport const radioGroupNames = new WeakMap<RadioGroupState, string>();\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 {AriaRadioProps} from '@react-types/radio';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {InputHTMLAttributes, RefObject} from 'react';\nimport {radioGroupNames} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useFocusable} from '@react-aria/focus';\nimport {usePress} from '@react-aria/interactions';\n\ninterface RadioAriaProps extends AriaRadioProps {\n /**\n * Whether the Radio is required. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/required).\n */\n isRequired?: boolean,\n /**\n * Whether the Radio can be interacted with but cannot have its selection state changed.\n */\n isReadOnly?: boolean\n}\n\ninterface RadioAria {\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for an individual\n * radio button in a radio group.\n * @param props - Props for the radio.\n * @param state - State for the radio group, as returned by `useRadioGroupState`.\n * @param ref - Ref to the HTML input element.\n */\nexport function useRadio(props: RadioAriaProps, state: RadioGroupState, ref: RefObject<HTMLElement>): RadioAria {\n let {\n value,\n isRequired,\n isReadOnly,\n isDisabled,\n children,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledby\n } = props;\n\n let hasChildren = children != null;\n let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;\n if (!hasChildren && !hasAriaLabel) {\n console.warn('If you do not provide children, you must specify an aria-label for accessibility');\n }\n\n let checked = state.selectedValue === value;\n\n let onChange = (e) => {\n e.stopPropagation();\n state.setSelectedValue(value);\n };\n\n let {pressProps} = usePress({\n isDisabled\n });\n\n let {focusableProps} = useFocusable(mergeProps(props, {\n onFocus: () => state.setLastFocusedValue(value)\n }), ref);\n let interactions = mergeProps(pressProps, focusableProps);\n let domProps = filterDOMProps(props, {labelable: true});\n let tabIndex = state.lastFocusedValue === value || state.lastFocusedValue == null ? 0 : -1;\n if (isDisabled) {\n tabIndex = undefined;\n }\n\n return {\n inputProps: mergeProps(domProps, {\n ...interactions,\n type: 'radio',\n name: radioGroupNames.get(state),\n tabIndex,\n disabled: isDisabled,\n readOnly: isReadOnly,\n required: isRequired,\n checked,\n value,\n onChange\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 {AriaRadioGroupProps} from '@react-types/radio';\nimport {filterDOMProps, mergeProps, useId} from '@react-aria/utils';\nimport {getFocusableTreeWalker} from '@react-aria/focus';\nimport {HTMLAttributes} from 'react';\nimport {radioGroupNames} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useFocusWithin} from '@react-aria/interactions';\nimport {useLabel} from '@react-aria/label';\nimport {useLocale} from '@react-aria/i18n';\n\ninterface RadioGroupAria {\n /** Props for the radio group wrapper element. */\n radioGroupProps: HTMLAttributes<HTMLElement>,\n /** Props for the radio group's visible label (if any). */\n labelProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a radio group component.\n * Radio groups allow users to select a single item from a list of mutually exclusive options.\n * @param props - Props for the radio group.\n * @param state - State for the radio group, as returned by `useRadioGroupState`.\n */\nexport function useRadioGroup(props: AriaRadioGroupProps, state: RadioGroupState): RadioGroupAria {\n let {\n name,\n validationState,\n isReadOnly,\n isRequired,\n isDisabled,\n orientation = 'vertical'\n } = props;\n let {direction} = useLocale();\n\n let {labelProps, fieldProps} = useLabel({\n ...props,\n // Radio group is not an HTML input element so it\n // shouldn't be labeled by a <label> element.\n labelElementType: 'span'\n });\n\n let domProps = filterDOMProps(props, {labelable: true});\n\n // When the radio group loses focus, reset the focusable radio to null if\n // there is no selection. This allows tabbing into the group from either\n // direction to go to the first or last radio.\n let {focusWithinProps} = useFocusWithin({\n onBlurWithin() {\n if (!state.selectedValue) {\n state.setLastFocusedValue(null);\n }\n }\n });\n\n let onKeyDown = (e) => {\n let nextDir;\n switch (e.key) {\n case 'ArrowRight':\n if (direction === 'rtl' && orientation !== 'vertical') {\n nextDir = 'prev';\n } else {\n nextDir = 'next';\n }\n break;\n case 'ArrowLeft':\n if (direction === 'rtl' && orientation !== 'vertical') {\n nextDir = 'next';\n } else {\n nextDir = 'prev';\n }\n break;\n case 'ArrowDown':\n nextDir = 'next';\n break;\n case 'ArrowUp':\n nextDir = 'prev';\n break;\n default:\n return;\n }\n e.preventDefault();\n let walker = getFocusableTreeWalker(e.currentTarget, {from: e.target});\n let nextElem;\n if (nextDir === 'next') {\n nextElem = walker.nextNode();\n if (!nextElem) {\n walker.currentNode = e.currentTarget;\n nextElem = walker.firstChild();\n }\n } else {\n nextElem = walker.previousNode();\n if (!nextElem) {\n walker.currentNode = e.currentTarget;\n nextElem = walker.lastChild();\n }\n }\n if (nextElem) {\n // Call focus on nextElem so that keyboard navigation scrolls the radio into view\n nextElem.focus();\n state.setSelectedValue(nextElem.value);\n }\n };\n\n let groupName = useId(name);\n radioGroupNames.set(state, groupName);\n\n return {\n radioGroupProps: mergeProps(domProps, {\n // https://www.w3.org/TR/wai-aria-1.2/#radiogroup\n role: 'radiogroup',\n onKeyDown,\n 'aria-invalid': validationState === 'invalid' || undefined,\n 'aria-errormessage': props['aria-errormessage'],\n 'aria-readonly': isReadOnly || undefined,\n 'aria-required': isRequired || undefined,\n 'aria-disabled': isDisabled || undefined,\n 'aria-orientation': orientation,\n ...fieldProps,\n ...focusWithinProps\n }),\n labelProps\n };\n}\n"],"names":["$parcel$interopDefault","a","__esModule","default","radioGroupNames","WeakMap","useRadio","props","state","ref","value","isRequired","isReadOnly","isDisabled","children","ariaLabel","ariaLabelledby","hasChildren","hasAriaLabel","console","warn","checked","selectedValue","onChange","e","stopPropagation","setSelectedValue","pressProps","usePress","focusableProps","useFocusable","mergeProps","onFocus","setLastFocusedValue","interactions","domProps","filterDOMProps","labelable","tabIndex","lastFocusedValue","undefined","inputProps","type","name","get","disabled","readOnly","required","useRadioGroup","validationState","orientation","direction","useLocale","labelProps","fieldProps","useLabel","labelElementType","focusWithinProps","useFocusWithin","onBlurWithin","onKeyDown","nextDir","key","preventDefault","walker","getFocusableTreeWalker","currentTarget","from","target","nextElem","nextNode","currentNode","firstChild","previousNode","lastChild","focus","groupName","useId","set","radioGroupProps","role"],"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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QAAQ,GAAGL,MAAM,CAACU,SAAP,EAAX;AACD;AACF;;AACD,QAAIL,QAAJ,EAAc;AACZ;AACAA,MAAAA,QAAQ,CAACM,KAAT;AACAjE,MAAAA,KAAK,CAACgB,gBAAN,CAAuB2C,QAAQ,CAACzD,KAAhC;AACD;AACF,GA/CD;;AAiDA,MAAIgE,SAAS,GAAGC,KAAK,CAAClC,IAAD,CAArB;AACA,0DAAgBmC,GAAhB,CAAoBpE,KAApB,EAA2BkE,SAA3B;AAEA,SAAO;AACLG,IAAAA,eAAe,EAAEhD,UAAU,CAACI,QAAD;AACzB;AACA6C,MAAAA,IAAI,EAAE,YAFmB;AAGzBpB,MAAAA,SAHyB;AAIzB,sBAAgBb,eAAe,KAAK,SAApB,IAAiCP,SAJxB;AAKzB,2BAAqB/B,KAAK,CAAC,mBAAD,CALD;AAMzB,uBAAiBuC,UAAU,IAAIR,SANN;AAOzB,uBAAiBS,UAAU,IAAIT,SAPN;AAQzB,uBAAiBxB,UAAU,IAAIwB,SARN;AASzB,0BAAoBU;AATK,OAUtBI,UAVsB,EAWtBG,gBAXsB,EADtB;AAcLJ,IAAAA;AAdK,GAAP;AAgBD","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/@react-aria/radio/src/utils.ts","./packages/@react-aria/radio/src/useRadio.ts","./packages/@react-aria/radio/src/useRadioGroup.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 {RadioGroupState} from '@react-stately/radio';\n\nexport const radioGroupNames = new WeakMap<RadioGroupState, string>();\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 {AriaRadioProps} from '@react-types/radio';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {InputHTMLAttributes, RefObject} from 'react';\nimport {radioGroupNames} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useFocusable} from '@react-aria/focus';\nimport {usePress} from '@react-aria/interactions';\n\ninterface RadioAria {\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for an individual\n * radio button in a radio group.\n * @param props - Props for the radio.\n * @param state - State for the radio group, as returned by `useRadioGroupState`.\n * @param ref - Ref to the HTML input element.\n */\nexport function useRadio(props: AriaRadioProps, state: RadioGroupState, ref: RefObject<HTMLElement>): RadioAria {\n let {\n value,\n children,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledby\n } = props;\n\n const isDisabled = props.isDisabled || state.isDisabled;\n\n let hasChildren = children != null;\n let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;\n if (!hasChildren && !hasAriaLabel) {\n console.warn('If you do not provide children, you must specify an aria-label for accessibility');\n }\n\n let checked = state.selectedValue === value;\n\n let onChange = (e) => {\n e.stopPropagation();\n state.setSelectedValue(value);\n };\n\n let {pressProps} = usePress({\n isDisabled\n });\n\n let {focusableProps} = useFocusable(mergeProps(props, {\n onFocus: () => state.setLastFocusedValue(value)\n }), ref);\n let interactions = mergeProps(pressProps, focusableProps);\n let domProps = filterDOMProps(props, {labelable: true});\n let tabIndex = state.lastFocusedValue === value || state.lastFocusedValue == null ? 0 : -1;\n if (isDisabled) {\n tabIndex = undefined;\n }\n\n return {\n inputProps: mergeProps(domProps, {\n ...interactions,\n type: 'radio',\n name: radioGroupNames.get(state),\n tabIndex,\n disabled: isDisabled,\n checked,\n value,\n onChange\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 {AriaRadioGroupProps} from '@react-types/radio';\nimport {filterDOMProps, mergeProps, useId} from '@react-aria/utils';\nimport {getFocusableTreeWalker} from '@react-aria/focus';\nimport {HTMLAttributes} from 'react';\nimport {radioGroupNames} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useFocusWithin} from '@react-aria/interactions';\nimport {useLabel} from '@react-aria/label';\nimport {useLocale} from '@react-aria/i18n';\n\ninterface RadioGroupAria {\n /** Props for the radio group wrapper element. */\n radioGroupProps: HTMLAttributes<HTMLElement>,\n /** Props for the radio group's visible label (if any). */\n labelProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a radio group component.\n * Radio groups allow users to select a single item from a list of mutually exclusive options.\n * @param props - Props for the radio group.\n * @param state - State for the radio group, as returned by `useRadioGroupState`.\n */\nexport function useRadioGroup(props: AriaRadioGroupProps, state: RadioGroupState): RadioGroupAria {\n let {\n name,\n validationState,\n isReadOnly,\n isRequired,\n isDisabled,\n orientation = 'vertical'\n } = props;\n let {direction} = useLocale();\n\n let {labelProps, fieldProps} = useLabel({\n ...props,\n // Radio group is not an HTML input element so it\n // shouldn't be labeled by a <label> element.\n labelElementType: 'span'\n });\n\n let domProps = filterDOMProps(props, {labelable: true});\n\n // When the radio group loses focus, reset the focusable radio to null if\n // there is no selection. This allows tabbing into the group from either\n // direction to go to the first or last radio.\n let {focusWithinProps} = useFocusWithin({\n onBlurWithin() {\n if (!state.selectedValue) {\n state.setLastFocusedValue(null);\n }\n }\n });\n\n let onKeyDown = (e) => {\n let nextDir;\n switch (e.key) {\n case 'ArrowRight':\n if (direction === 'rtl' && orientation !== 'vertical') {\n nextDir = 'prev';\n } else {\n nextDir = 'next';\n }\n break;\n case 'ArrowLeft':\n if (direction === 'rtl' && orientation !== 'vertical') {\n nextDir = 'next';\n } else {\n nextDir = 'prev';\n }\n break;\n case 'ArrowDown':\n nextDir = 'next';\n break;\n case 'ArrowUp':\n nextDir = 'prev';\n break;\n default:\n return;\n }\n e.preventDefault();\n let walker = getFocusableTreeWalker(e.currentTarget, {from: e.target});\n let nextElem;\n if (nextDir === 'next') {\n nextElem = walker.nextNode();\n if (!nextElem) {\n walker.currentNode = e.currentTarget;\n nextElem = walker.firstChild();\n }\n } else {\n nextElem = walker.previousNode();\n if (!nextElem) {\n walker.currentNode = e.currentTarget;\n nextElem = walker.lastChild();\n }\n }\n if (nextElem) {\n // Call focus on nextElem so that keyboard navigation scrolls the radio into view\n nextElem.focus();\n state.setSelectedValue(nextElem.value);\n }\n };\n\n let groupName = useId(name);\n radioGroupNames.set(state, groupName);\n\n return {\n radioGroupProps: mergeProps(domProps, {\n // https://www.w3.org/TR/wai-aria-1.2/#radiogroup\n role: 'radiogroup',\n onKeyDown,\n 'aria-invalid': validationState === 'invalid' || undefined,\n 'aria-errormessage': props['aria-errormessage'],\n 'aria-readonly': isReadOnly || undefined,\n 'aria-required': isRequired || undefined,\n 'aria-disabled': isDisabled || undefined,\n 'aria-orientation': orientation,\n ...fieldProps,\n ...focusWithinProps\n }),\n labelProps\n };\n}\n"],"names":["$parcel$interopDefault","a","__esModule","default","radioGroupNames","WeakMap","useRadio","props","state","ref","value","children","ariaLabel","ariaLabelledby","isDisabled","hasChildren","hasAriaLabel","console","warn","checked","selectedValue","onChange","e","stopPropagation","setSelectedValue","pressProps","usePress","focusableProps","useFocusable","mergeProps","onFocus","setLastFocusedValue","interactions","domProps","filterDOMProps","labelable","tabIndex","lastFocusedValue","undefined","inputProps","type","name","get","disabled","useRadioGroup","validationState","isReadOnly","isRequired","orientation","direction","useLocale","labelProps","fieldProps","useLabel","labelElementType","focusWithinProps","useFocusWithin","onBlurWithin","onKeyDown","nextDir","key","preventDefault","walker","getFocusableTreeWalker","currentTarget","from","target","nextElem","nextNode","currentNode","firstChild","previousNode","lastChild","focus","groupName","useId","set","radioGroupProps","role"],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -28,13 +28,11 @@ const $a7d0e5df3871fb1bfdb437cffdabab2a$export$radioGroupNames = new WeakMap();
|
|
|
28
28
|
export function useRadio(props, state, ref) {
|
|
29
29
|
let {
|
|
30
30
|
value,
|
|
31
|
-
isRequired,
|
|
32
|
-
isReadOnly,
|
|
33
|
-
isDisabled,
|
|
34
31
|
children,
|
|
35
32
|
'aria-label': ariaLabel,
|
|
36
33
|
'aria-labelledby': ariaLabelledby
|
|
37
34
|
} = props;
|
|
35
|
+
const isDisabled = props.isDisabled || state.isDisabled;
|
|
38
36
|
let hasChildren = children != null;
|
|
39
37
|
let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;
|
|
40
38
|
|
|
@@ -75,8 +73,6 @@ export function useRadio(props, state, ref) {
|
|
|
75
73
|
name: $a7d0e5df3871fb1bfdb437cffdabab2a$export$radioGroupNames.get(state),
|
|
76
74
|
tabIndex,
|
|
77
75
|
disabled: isDisabled,
|
|
78
|
-
readOnly: isReadOnly,
|
|
79
|
-
required: isRequired,
|
|
80
76
|
checked,
|
|
81
77
|
value,
|
|
82
78
|
onChange
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;AAAA;;;;;;;;;;;AAcO,MAAMA,wDAAe,GAAG,IAAIC,OAAJ,EAAxB;;ACsBP;;;;;;;OAOO,SAASC,QAAT,CAAkBC,KAAlB,EAAyCC,KAAzC,EAAiEC,GAAjE,EAAyG;AAC9G,MAAI;AACFC,IAAAA,KADE;AAEFC,IAAAA,UAFE;AAGFC,IAAAA,UAHE;AAIFC,IAAAA,UAJE;AAKFC,IAAAA,QALE;AAMF,kBAAcC,SANZ;AAOF,uBAAmBC;AAPjB,MAQAT,KARJ;AAUA,MAAIU,WAAW,GAAGH,QAAQ,IAAI,IAA9B;AACA,MAAII,YAAY,GAAGH,SAAS,IAAI,IAAb,IAAqBC,cAAc,IAAI,IAA1D;;AACA,MAAI,CAACC,WAAD,IAAgB,CAACC,YAArB,EAAmC;AACjCC,IAAAA,OAAO,CAACC,IAAR,CAAa,kFAAb;AACD;;AAED,MAAIC,OAAO,GAAGb,KAAK,CAACc,aAAN,KAAwBZ,KAAtC;;AAEA,MAAIa,QAAQ,GAAIC,CAAD,IAAO;AACpBA,IAAAA,CAAC,CAACC,eAAF;AACAjB,IAAAA,KAAK,CAACkB,gBAAN,CAAuBhB,KAAvB;AACD,GAHD;;AAKA,MAAI;AAACiB,IAAAA;AAAD,MAAeC,QAAQ,CAAC;AAC1Bf,IAAAA;AAD0B,GAAD,CAA3B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aria/radio/src/useRadioGroup.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 {RadioGroupState} from '@react-stately/radio';\n\nexport const radioGroupNames = new WeakMap<RadioGroupState, string>();\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 {AriaRadioProps} from '@react-types/radio';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {InputHTMLAttributes, RefObject} from 'react';\nimport {radioGroupNames} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useFocusable} from '@react-aria/focus';\nimport {usePress} from '@react-aria/interactions';\n\ninterface RadioAriaProps extends AriaRadioProps {\n /**\n * Whether the Radio is required. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/required).\n */\n isRequired?: boolean,\n /**\n * Whether the Radio can be interacted with but cannot have its selection state changed.\n */\n isReadOnly?: boolean\n}\n\ninterface RadioAria {\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for an individual\n * radio button in a radio group.\n * @param props - Props for the radio.\n * @param state - State for the radio group, as returned by `useRadioGroupState`.\n * @param ref - Ref to the HTML input element.\n */\nexport function useRadio(props: RadioAriaProps, state: RadioGroupState, ref: RefObject<HTMLElement>): RadioAria {\n let {\n value,\n isRequired,\n isReadOnly,\n isDisabled,\n children,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledby\n } = props;\n\n let hasChildren = children != null;\n let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;\n if (!hasChildren && !hasAriaLabel) {\n console.warn('If you do not provide children, you must specify an aria-label for accessibility');\n }\n\n let checked = state.selectedValue === value;\n\n let onChange = (e) => {\n e.stopPropagation();\n state.setSelectedValue(value);\n };\n\n let {pressProps} = usePress({\n isDisabled\n });\n\n let {focusableProps} = useFocusable(mergeProps(props, {\n onFocus: () => state.setLastFocusedValue(value)\n }), ref);\n let interactions = mergeProps(pressProps, focusableProps);\n let domProps = filterDOMProps(props, {labelable: true});\n let tabIndex = state.lastFocusedValue === value || state.lastFocusedValue == null ? 0 : -1;\n if (isDisabled) {\n tabIndex = undefined;\n }\n\n return {\n inputProps: mergeProps(domProps, {\n ...interactions,\n type: 'radio',\n name: radioGroupNames.get(state),\n tabIndex,\n disabled: isDisabled,\n readOnly: isReadOnly,\n required: isRequired,\n checked,\n value,\n onChange\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 {AriaRadioGroupProps} from '@react-types/radio';\nimport {filterDOMProps, mergeProps, useId} from '@react-aria/utils';\nimport {getFocusableTreeWalker} from '@react-aria/focus';\nimport {HTMLAttributes} from 'react';\nimport {radioGroupNames} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useFocusWithin} from '@react-aria/interactions';\nimport {useLabel} from '@react-aria/label';\nimport {useLocale} from '@react-aria/i18n';\n\ninterface RadioGroupAria {\n /** Props for the radio group wrapper element. */\n radioGroupProps: HTMLAttributes<HTMLElement>,\n /** Props for the radio group's visible label (if any). */\n labelProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a radio group component.\n * Radio groups allow users to select a single item from a list of mutually exclusive options.\n * @param props - Props for the radio group.\n * @param state - State for the radio group, as returned by `useRadioGroupState`.\n */\nexport function useRadioGroup(props: AriaRadioGroupProps, state: RadioGroupState): RadioGroupAria {\n let {\n name,\n validationState,\n isReadOnly,\n isRequired,\n isDisabled,\n orientation = 'vertical'\n } = props;\n let {direction} = useLocale();\n\n let {labelProps, fieldProps} = useLabel({\n ...props,\n // Radio group is not an HTML input element so it\n // shouldn't be labeled by a <label> element.\n labelElementType: 'span'\n });\n\n let domProps = filterDOMProps(props, {labelable: true});\n\n // When the radio group loses focus, reset the focusable radio to null if\n // there is no selection. This allows tabbing into the group from either\n // direction to go to the first or last radio.\n let {focusWithinProps} = useFocusWithin({\n onBlurWithin() {\n if (!state.selectedValue) {\n state.setLastFocusedValue(null);\n }\n }\n });\n\n let onKeyDown = (e) => {\n let nextDir;\n switch (e.key) {\n case 'ArrowRight':\n if (direction === 'rtl' && orientation !== 'vertical') {\n nextDir = 'prev';\n } else {\n nextDir = 'next';\n }\n break;\n case 'ArrowLeft':\n if (direction === 'rtl' && orientation !== 'vertical') {\n nextDir = 'next';\n } else {\n nextDir = 'prev';\n }\n break;\n case 'ArrowDown':\n nextDir = 'next';\n break;\n case 'ArrowUp':\n nextDir = 'prev';\n break;\n default:\n return;\n }\n e.preventDefault();\n let walker = getFocusableTreeWalker(e.currentTarget, {from: e.target});\n let nextElem;\n if (nextDir === 'next') {\n nextElem = walker.nextNode();\n if (!nextElem) {\n walker.currentNode = e.currentTarget;\n nextElem = walker.firstChild();\n }\n } else {\n nextElem = walker.previousNode();\n if (!nextElem) {\n walker.currentNode = e.currentTarget;\n nextElem = walker.lastChild();\n }\n }\n if (nextElem) {\n // Call focus on nextElem so that keyboard navigation scrolls the radio into view\n nextElem.focus();\n state.setSelectedValue(nextElem.value);\n }\n };\n\n let groupName = useId(name);\n radioGroupNames.set(state, groupName);\n\n return {\n radioGroupProps: mergeProps(domProps, {\n // https://www.w3.org/TR/wai-aria-1.2/#radiogroup\n role: 'radiogroup',\n onKeyDown,\n 'aria-invalid': validationState === 'invalid' || undefined,\n 'aria-errormessage': props['aria-errormessage'],\n 'aria-readonly': isReadOnly || undefined,\n 'aria-required': isRequired || undefined,\n 'aria-disabled': isDisabled || undefined,\n 'aria-orientation': orientation,\n ...fieldProps,\n ...focusWithinProps\n }),\n labelProps\n };\n}\n"],"names":["radioGroupNames","WeakMap","useRadio","props","state","ref","value","isRequired","isReadOnly","isDisabled","children","ariaLabel","ariaLabelledby","hasChildren","hasAriaLabel","console","warn","checked","selectedValue","onChange","e","stopPropagation","setSelectedValue","pressProps","usePress","focusableProps","useFocusable","mergeProps","onFocus","setLastFocusedValue","interactions","domProps","filterDOMProps","labelable","tabIndex","lastFocusedValue","undefined","inputProps","type","name","get","disabled","readOnly","required","useRadioGroup","validationState","orientation","direction","useLocale","labelProps","fieldProps","useLabel","labelElementType","focusWithinProps","useFocusWithin","onBlurWithin","onKeyDown","nextDir","key","preventDefault","walker","getFocusableTreeWalker","currentTarget","from","target","nextElem","nextNode","currentNode","firstChild","previousNode","lastChild","focus","groupName","useId","set","radioGroupProps","role"],"version":3,"file":"module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;AAAA;;;;;;;;;;;AAcO,MAAMA,wDAAe,GAAG,IAAIC,OAAJ,EAAxB;;ACWP;;;;;;;OAOO,SAASC,QAAT,CAAkBC,KAAlB,EAAyCC,KAAzC,EAAiEC,GAAjE,EAAyG;AAC9G,MAAI;AACFC,IAAAA,KADE;AAEFC,IAAAA,QAFE;AAGF,kBAAcC,SAHZ;AAIF,uB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AgBmC,GAAhB,CAAoBpE,KAApB,EAA2BkE,SAA3B;AAEA,SAAO;AACLG,IAAAA,eAAe,EAAEhD,UAAU,CAACI,QAAD;AACzB;AACA6C,MAAAA,IAAI,EAAE,YAFmB;AAGzBpB,MAAAA,SAHyB;AAIzB,sBAAgBb,eAAe,KAAK,SAApB,IAAiCP,SAJxB;AAKzB,2BAAqB/B,KAAK,CAAC,mBAAD,CALD;AAMzB,uBAAiBuC,UAAU,IAAIR,SANN;AAOzB,uBAAiBS,UAAU,IAAIT,SAPN;AAQzB,uBAAiBxB,UAAU,IAAIwB,SARN;AASzB,0BAAoBU;AATK,OAUtBI,UAVsB,EAWtBG,gBAXsB,EADtB;AAcLJ,IAAAA;AAdK,GAAP;AAgBD","sources":["./packages/@react-aria/radio/src/utils.ts","./packages/@react-aria/radio/src/useRadio.ts","./packages/@react-aria/radio/src/useRadioGroup.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 {RadioGroupState} from '@react-stately/radio';\n\nexport const radioGroupNames = new WeakMap<RadioGroupState, string>();\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 {AriaRadioProps} from '@react-types/radio';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {InputHTMLAttributes, RefObject} from 'react';\nimport {radioGroupNames} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useFocusable} from '@react-aria/focus';\nimport {usePress} from '@react-aria/interactions';\n\ninterface RadioAria {\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for an individual\n * radio button in a radio group.\n * @param props - Props for the radio.\n * @param state - State for the radio group, as returned by `useRadioGroupState`.\n * @param ref - Ref to the HTML input element.\n */\nexport function useRadio(props: AriaRadioProps, state: RadioGroupState, ref: RefObject<HTMLElement>): RadioAria {\n let {\n value,\n children,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledby\n } = props;\n\n const isDisabled = props.isDisabled || state.isDisabled;\n\n let hasChildren = children != null;\n let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;\n if (!hasChildren && !hasAriaLabel) {\n console.warn('If you do not provide children, you must specify an aria-label for accessibility');\n }\n\n let checked = state.selectedValue === value;\n\n let onChange = (e) => {\n e.stopPropagation();\n state.setSelectedValue(value);\n };\n\n let {pressProps} = usePress({\n isDisabled\n });\n\n let {focusableProps} = useFocusable(mergeProps(props, {\n onFocus: () => state.setLastFocusedValue(value)\n }), ref);\n let interactions = mergeProps(pressProps, focusableProps);\n let domProps = filterDOMProps(props, {labelable: true});\n let tabIndex = state.lastFocusedValue === value || state.lastFocusedValue == null ? 0 : -1;\n if (isDisabled) {\n tabIndex = undefined;\n }\n\n return {\n inputProps: mergeProps(domProps, {\n ...interactions,\n type: 'radio',\n name: radioGroupNames.get(state),\n tabIndex,\n disabled: isDisabled,\n checked,\n value,\n onChange\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 {AriaRadioGroupProps} from '@react-types/radio';\nimport {filterDOMProps, mergeProps, useId} from '@react-aria/utils';\nimport {getFocusableTreeWalker} from '@react-aria/focus';\nimport {HTMLAttributes} from 'react';\nimport {radioGroupNames} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useFocusWithin} from '@react-aria/interactions';\nimport {useLabel} from '@react-aria/label';\nimport {useLocale} from '@react-aria/i18n';\n\ninterface RadioGroupAria {\n /** Props for the radio group wrapper element. */\n radioGroupProps: HTMLAttributes<HTMLElement>,\n /** Props for the radio group's visible label (if any). */\n labelProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a radio group component.\n * Radio groups allow users to select a single item from a list of mutually exclusive options.\n * @param props - Props for the radio group.\n * @param state - State for the radio group, as returned by `useRadioGroupState`.\n */\nexport function useRadioGroup(props: AriaRadioGroupProps, state: RadioGroupState): RadioGroupAria {\n let {\n name,\n validationState,\n isReadOnly,\n isRequired,\n isDisabled,\n orientation = 'vertical'\n } = props;\n let {direction} = useLocale();\n\n let {labelProps, fieldProps} = useLabel({\n ...props,\n // Radio group is not an HTML input element so it\n // shouldn't be labeled by a <label> element.\n labelElementType: 'span'\n });\n\n let domProps = filterDOMProps(props, {labelable: true});\n\n // When the radio group loses focus, reset the focusable radio to null if\n // there is no selection. This allows tabbing into the group from either\n // direction to go to the first or last radio.\n let {focusWithinProps} = useFocusWithin({\n onBlurWithin() {\n if (!state.selectedValue) {\n state.setLastFocusedValue(null);\n }\n }\n });\n\n let onKeyDown = (e) => {\n let nextDir;\n switch (e.key) {\n case 'ArrowRight':\n if (direction === 'rtl' && orientation !== 'vertical') {\n nextDir = 'prev';\n } else {\n nextDir = 'next';\n }\n break;\n case 'ArrowLeft':\n if (direction === 'rtl' && orientation !== 'vertical') {\n nextDir = 'next';\n } else {\n nextDir = 'prev';\n }\n break;\n case 'ArrowDown':\n nextDir = 'next';\n break;\n case 'ArrowUp':\n nextDir = 'prev';\n break;\n default:\n return;\n }\n e.preventDefault();\n let walker = getFocusableTreeWalker(e.currentTarget, {from: e.target});\n let nextElem;\n if (nextDir === 'next') {\n nextElem = walker.nextNode();\n if (!nextElem) {\n walker.currentNode = e.currentTarget;\n nextElem = walker.firstChild();\n }\n } else {\n nextElem = walker.previousNode();\n if (!nextElem) {\n walker.currentNode = e.currentTarget;\n nextElem = walker.lastChild();\n }\n }\n if (nextElem) {\n // Call focus on nextElem so that keyboard navigation scrolls the radio into view\n nextElem.focus();\n state.setSelectedValue(nextElem.value);\n }\n };\n\n let groupName = useId(name);\n radioGroupNames.set(state, groupName);\n\n return {\n radioGroupProps: mergeProps(domProps, {\n // https://www.w3.org/TR/wai-aria-1.2/#radiogroup\n role: 'radiogroup',\n onKeyDown,\n 'aria-invalid': validationState === 'invalid' || undefined,\n 'aria-errormessage': props['aria-errormessage'],\n 'aria-readonly': isReadOnly || undefined,\n 'aria-required': isRequired || undefined,\n 'aria-disabled': isDisabled || undefined,\n 'aria-orientation': orientation,\n ...fieldProps,\n ...focusWithinProps\n }),\n labelProps\n };\n}\n"],"names":["radioGroupNames","WeakMap","useRadio","props","state","ref","value","children","ariaLabel","ariaLabelledby","isDisabled","hasChildren","hasAriaLabel","console","warn","checked","selectedValue","onChange","e","stopPropagation","setSelectedValue","pressProps","usePress","focusableProps","useFocusable","mergeProps","onFocus","setLastFocusedValue","interactions","domProps","filterDOMProps","labelable","tabIndex","lastFocusedValue","undefined","inputProps","type","name","get","disabled","useRadioGroup","validationState","isReadOnly","isRequired","orientation","direction","useLocale","labelProps","fieldProps","useLabel","labelElementType","focusWithinProps","useFocusWithin","onBlurWithin","onKeyDown","nextDir","key","preventDefault","walker","getFocusableTreeWalker","currentTarget","from","target","nextElem","nextNode","currentNode","firstChild","previousNode","lastChild","focus","groupName","useId","set","radioGroupProps","role"],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
import { AriaRadioProps, AriaRadioGroupProps } from "@react-types/radio";
|
|
2
2
|
import { InputHTMLAttributes, RefObject, HTMLAttributes } from "react";
|
|
3
3
|
import { RadioGroupState } from "@react-stately/radio";
|
|
4
|
-
interface RadioAriaProps extends AriaRadioProps {
|
|
5
|
-
/**
|
|
6
|
-
* Whether the Radio is required. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/required).
|
|
7
|
-
*/
|
|
8
|
-
isRequired?: boolean;
|
|
9
|
-
/**
|
|
10
|
-
* Whether the Radio can be interacted with but cannot have its selection state changed.
|
|
11
|
-
*/
|
|
12
|
-
isReadOnly?: boolean;
|
|
13
|
-
}
|
|
14
4
|
interface RadioAria {
|
|
15
5
|
/** Props for the input element. */
|
|
16
6
|
inputProps: InputHTMLAttributes<HTMLElement>;
|
|
@@ -22,7 +12,7 @@ interface RadioAria {
|
|
|
22
12
|
* @param state - State for the radio group, as returned by `useRadioGroupState`.
|
|
23
13
|
* @param ref - Ref to the HTML input element.
|
|
24
14
|
*/
|
|
25
|
-
export function useRadio(props:
|
|
15
|
+
export function useRadio(props: AriaRadioProps, state: RadioGroupState, ref: RefObject<HTMLElement>): RadioAria;
|
|
26
16
|
interface RadioGroupAria {
|
|
27
17
|
/** Props for the radio group wrapper element. */
|
|
28
18
|
radioGroupProps: HTMLAttributes<HTMLElement>;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"A;A;A;ACoBA
|
|
1
|
+
{"mappings":"A;A;A;ACoBA;IACE,mCAAmC;IACnC,UAAU,EAAE,oBAAoB,WAAW,CAAC,CAAA;CAC7C;AAED;A;A;A;A;A;GAMG;AACH,yBAAyB,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,UAAU,WAAW,CAAC,GAAG,SAAS,CAiD9G;AC3DD;IACE,iDAAiD;IACjD,eAAe,EAAE,eAAe,WAAW,CAAC,CAAC;IAC7C,0DAA0D;IAC1D,UAAU,EAAE,eAAe,WAAW,CAAC,CAAA;CACxC;AAED;A;A;A;A;GAKG;AACH,8BAA8B,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,eAAe,GAAG,cAAc,CAmGhG","sources":["./packages/@react-aria/radio/src/packages/@react-aria/radio/src/utils.ts","./packages/@react-aria/radio/src/packages/@react-aria/radio/src/useRadio.ts","./packages/@react-aria/radio/src/packages/@react-aria/radio/src/useRadioGroup.ts","./packages/@react-aria/radio/src/packages/@react-aria/radio/src/index.ts"],"sourcesContent":[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/radio",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.6",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.6.2",
|
|
21
|
-
"@react-aria/focus": "^3.
|
|
22
|
-
"@react-aria/i18n": "^3.
|
|
23
|
-
"@react-aria/interactions": "^3.
|
|
24
|
-
"@react-aria/label": "^3.
|
|
25
|
-
"@react-aria/utils": "^3.
|
|
26
|
-
"@react-stately/radio": "^3.2
|
|
27
|
-
"@react-types/radio": "^3.1.
|
|
21
|
+
"@react-aria/focus": "^3.4.1",
|
|
22
|
+
"@react-aria/i18n": "^3.3.3",
|
|
23
|
+
"@react-aria/interactions": "^3.7.0",
|
|
24
|
+
"@react-aria/label": "^3.2.1",
|
|
25
|
+
"@react-aria/utils": "^3.10.0",
|
|
26
|
+
"@react-stately/radio": "^3.3.2",
|
|
27
|
+
"@react-types/radio": "^3.1.2"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"react": "^16.8.0 || ^17.0.0-rc.1"
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "896eabe5521a0349a675c4773ed7629addd4b8c4"
|
|
36
36
|
}
|
package/src/useRadio.ts
CHANGED
|
@@ -18,17 +18,6 @@ import {RadioGroupState} from '@react-stately/radio';
|
|
|
18
18
|
import {useFocusable} from '@react-aria/focus';
|
|
19
19
|
import {usePress} from '@react-aria/interactions';
|
|
20
20
|
|
|
21
|
-
interface RadioAriaProps extends AriaRadioProps {
|
|
22
|
-
/**
|
|
23
|
-
* Whether the Radio is required. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/required).
|
|
24
|
-
*/
|
|
25
|
-
isRequired?: boolean,
|
|
26
|
-
/**
|
|
27
|
-
* Whether the Radio can be interacted with but cannot have its selection state changed.
|
|
28
|
-
*/
|
|
29
|
-
isReadOnly?: boolean
|
|
30
|
-
}
|
|
31
|
-
|
|
32
21
|
interface RadioAria {
|
|
33
22
|
/** Props for the input element. */
|
|
34
23
|
inputProps: InputHTMLAttributes<HTMLElement>
|
|
@@ -41,17 +30,16 @@ interface RadioAria {
|
|
|
41
30
|
* @param state - State for the radio group, as returned by `useRadioGroupState`.
|
|
42
31
|
* @param ref - Ref to the HTML input element.
|
|
43
32
|
*/
|
|
44
|
-
export function useRadio(props:
|
|
33
|
+
export function useRadio(props: AriaRadioProps, state: RadioGroupState, ref: RefObject<HTMLElement>): RadioAria {
|
|
45
34
|
let {
|
|
46
35
|
value,
|
|
47
|
-
isRequired,
|
|
48
|
-
isReadOnly,
|
|
49
|
-
isDisabled,
|
|
50
36
|
children,
|
|
51
37
|
'aria-label': ariaLabel,
|
|
52
38
|
'aria-labelledby': ariaLabelledby
|
|
53
39
|
} = props;
|
|
54
40
|
|
|
41
|
+
const isDisabled = props.isDisabled || state.isDisabled;
|
|
42
|
+
|
|
55
43
|
let hasChildren = children != null;
|
|
56
44
|
let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;
|
|
57
45
|
if (!hasChildren && !hasAriaLabel) {
|
|
@@ -86,8 +74,6 @@ export function useRadio(props: RadioAriaProps, state: RadioGroupState, ref: Ref
|
|
|
86
74
|
name: radioGroupNames.get(state),
|
|
87
75
|
tabIndex,
|
|
88
76
|
disabled: isDisabled,
|
|
89
|
-
readOnly: isReadOnly,
|
|
90
|
-
required: isRequired,
|
|
91
77
|
checked,
|
|
92
78
|
value,
|
|
93
79
|
onChange
|