@react-aria/radio 3.10.2 → 3.10.3

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/module.js CHANGED
@@ -1,21 +1,7 @@
1
- import {mergeProps as $4vDl6$mergeProps, filterDOMProps as $4vDl6$filterDOMProps, useFormReset as $4vDl6$useFormReset, useId as $4vDl6$useId} from "@react-aria/utils";
2
- import {useFocusable as $4vDl6$useFocusable, getFocusableTreeWalker as $4vDl6$getFocusableTreeWalker} from "@react-aria/focus";
3
- import {useFormValidation as $4vDl6$useFormValidation} from "@react-aria/form";
4
- import {usePress as $4vDl6$usePress, useFocusWithin as $4vDl6$useFocusWithin} from "@react-aria/interactions";
5
- import {useField as $4vDl6$useField} from "@react-aria/label";
6
- import {useLocale as $4vDl6$useLocale} from "@react-aria/i18n";
1
+ import {useRadio as $0d5c49892c1215da$export$37b0961d2f4751e2} from "./useRadio.module.js";
2
+ import {useRadioGroup as $430f30ed08ec25fa$export$62b9571f283ff5c2} from "./useRadioGroup.module.js";
7
3
 
8
4
  /*
9
- * Copyright 2020 Adobe. All rights reserved.
10
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
11
- * you may not use this file except in compliance with the License. You may obtain a copy
12
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
13
- *
14
- * Unless required by applicable law or agreed to in writing, software distributed under
15
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
16
- * OF ANY KIND, either express or implied. See the License for the specific language
17
- * governing permissions and limitations under the License.
18
- */ /*
19
5
  * Copyright 2020 Adobe. All rights reserved.
20
6
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
21
7
  * you may not use this file except in compliance with the License. You may obtain a copy
@@ -26,204 +12,6 @@ import {useLocale as $4vDl6$useLocale} from "@react-aria/i18n";
26
12
  * OF ANY KIND, either express or implied. See the License for the specific language
27
13
  * governing permissions and limitations under the License.
28
14
  */
29
- /*
30
- * Copyright 2020 Adobe. All rights reserved.
31
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
32
- * you may not use this file except in compliance with the License. You may obtain a copy
33
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
34
- *
35
- * Unless required by applicable law or agreed to in writing, software distributed under
36
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
37
- * OF ANY KIND, either express or implied. See the License for the specific language
38
- * governing permissions and limitations under the License.
39
- */ const $884aeceb3d67f00f$export$37b65e5b5444d35c = new WeakMap();
40
-
41
-
42
-
43
-
44
-
45
- function $0d5c49892c1215da$export$37b0961d2f4751e2(props, state, ref) {
46
- let { value: value, children: children, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby } = props;
47
- const isDisabled = props.isDisabled || state.isDisabled;
48
- let hasChildren = children != null;
49
- let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;
50
- if (!hasChildren && !hasAriaLabel) console.warn("If you do not provide children, you must specify an aria-label for accessibility");
51
- let checked = state.selectedValue === value;
52
- let onChange = (e)=>{
53
- e.stopPropagation();
54
- state.setSelectedValue(value);
55
- };
56
- let { pressProps: pressProps, isPressed: isPressed } = (0, $4vDl6$usePress)({
57
- isDisabled: isDisabled
58
- });
59
- // iOS does not toggle radios if you drag off and back onto the label, so handle it ourselves.
60
- let { pressProps: labelProps, isPressed: isLabelPressed } = (0, $4vDl6$usePress)({
61
- isDisabled: isDisabled,
62
- onPress () {
63
- state.setSelectedValue(value);
64
- }
65
- });
66
- let { focusableProps: focusableProps } = (0, $4vDl6$useFocusable)((0, $4vDl6$mergeProps)(props, {
67
- onFocus: ()=>state.setLastFocusedValue(value)
68
- }), ref);
69
- let interactions = (0, $4vDl6$mergeProps)(pressProps, focusableProps);
70
- let domProps = (0, $4vDl6$filterDOMProps)(props, {
71
- labelable: true
72
- });
73
- let tabIndex = -1;
74
- if (state.selectedValue != null) {
75
- if (state.selectedValue === value) tabIndex = 0;
76
- } else if (state.lastFocusedValue === value || state.lastFocusedValue == null) tabIndex = 0;
77
- if (isDisabled) tabIndex = undefined;
78
- let { name: name, descriptionId: descriptionId, errorMessageId: errorMessageId, validationBehavior: validationBehavior } = (0, $884aeceb3d67f00f$export$37b65e5b5444d35c).get(state);
79
- (0, $4vDl6$useFormReset)(ref, state.selectedValue, state.setSelectedValue);
80
- (0, $4vDl6$useFormValidation)({
81
- validationBehavior: validationBehavior
82
- }, state, ref);
83
- return {
84
- labelProps: (0, $4vDl6$mergeProps)(labelProps, {
85
- onClick: (e)=>e.preventDefault()
86
- }),
87
- inputProps: (0, $4vDl6$mergeProps)(domProps, {
88
- ...interactions,
89
- type: "radio",
90
- name: name,
91
- tabIndex: tabIndex,
92
- disabled: isDisabled,
93
- required: state.isRequired && validationBehavior === "native",
94
- checked: checked,
95
- value: value,
96
- onChange: onChange,
97
- "aria-describedby": [
98
- props["aria-describedby"],
99
- state.isInvalid ? errorMessageId : null,
100
- descriptionId
101
- ].filter(Boolean).join(" ") || undefined
102
- }),
103
- isDisabled: isDisabled,
104
- isSelected: checked,
105
- isPressed: isPressed || isLabelPressed
106
- };
107
- }
108
-
109
-
110
- /*
111
- * Copyright 2020 Adobe. All rights reserved.
112
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
113
- * you may not use this file except in compliance with the License. You may obtain a copy
114
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
115
- *
116
- * Unless required by applicable law or agreed to in writing, software distributed under
117
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
118
- * OF ANY KIND, either express or implied. See the License for the specific language
119
- * governing permissions and limitations under the License.
120
- */
121
-
122
-
123
-
124
-
125
-
126
- function $430f30ed08ec25fa$export$62b9571f283ff5c2(props, state) {
127
- let { name: name, isReadOnly: isReadOnly, isRequired: isRequired, isDisabled: isDisabled, orientation: orientation = "vertical", validationBehavior: validationBehavior = "aria" } = props;
128
- let { direction: direction } = (0, $4vDl6$useLocale)();
129
- let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
130
- let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $4vDl6$useField)({
131
- ...props,
132
- // Radio group is not an HTML input element so it
133
- // shouldn't be labeled by a <label> element.
134
- labelElementType: "span",
135
- isInvalid: state.isInvalid,
136
- errorMessage: props.errorMessage || validationErrors
137
- });
138
- let domProps = (0, $4vDl6$filterDOMProps)(props, {
139
- labelable: true
140
- });
141
- // When the radio group loses focus, reset the focusable radio to null if
142
- // there is no selection. This allows tabbing into the group from either
143
- // direction to go to the first or last radio.
144
- let { focusWithinProps: focusWithinProps } = (0, $4vDl6$useFocusWithin)({
145
- onBlurWithin (e) {
146
- var _props_onBlur;
147
- (_props_onBlur = props.onBlur) === null || _props_onBlur === void 0 ? void 0 : _props_onBlur.call(props, e);
148
- if (!state.selectedValue) state.setLastFocusedValue(null);
149
- },
150
- onFocusWithin: props.onFocus,
151
- onFocusWithinChange: props.onFocusChange
152
- });
153
- let onKeyDown = (e)=>{
154
- let nextDir;
155
- switch(e.key){
156
- case "ArrowRight":
157
- if (direction === "rtl" && orientation !== "vertical") nextDir = "prev";
158
- else nextDir = "next";
159
- break;
160
- case "ArrowLeft":
161
- if (direction === "rtl" && orientation !== "vertical") nextDir = "next";
162
- else nextDir = "prev";
163
- break;
164
- case "ArrowDown":
165
- nextDir = "next";
166
- break;
167
- case "ArrowUp":
168
- nextDir = "prev";
169
- break;
170
- default:
171
- return;
172
- }
173
- e.preventDefault();
174
- let walker = (0, $4vDl6$getFocusableTreeWalker)(e.currentTarget, {
175
- from: e.target
176
- });
177
- let nextElem;
178
- if (nextDir === "next") {
179
- nextElem = walker.nextNode();
180
- if (!nextElem) {
181
- walker.currentNode = e.currentTarget;
182
- nextElem = walker.firstChild();
183
- }
184
- } else {
185
- nextElem = walker.previousNode();
186
- if (!nextElem) {
187
- walker.currentNode = e.currentTarget;
188
- nextElem = walker.lastChild();
189
- }
190
- }
191
- if (nextElem) {
192
- // Call focus on nextElem so that keyboard navigation scrolls the radio into view
193
- nextElem.focus();
194
- state.setSelectedValue(nextElem.value);
195
- }
196
- };
197
- let groupName = (0, $4vDl6$useId)(name);
198
- (0, $884aeceb3d67f00f$export$37b65e5b5444d35c).set(state, {
199
- name: groupName,
200
- descriptionId: descriptionProps.id,
201
- errorMessageId: errorMessageProps.id,
202
- validationBehavior: validationBehavior
203
- });
204
- return {
205
- radioGroupProps: (0, $4vDl6$mergeProps)(domProps, {
206
- // https://www.w3.org/TR/wai-aria-1.2/#radiogroup
207
- role: "radiogroup",
208
- onKeyDown: onKeyDown,
209
- "aria-invalid": state.isInvalid || undefined,
210
- "aria-errormessage": props["aria-errormessage"],
211
- "aria-readonly": isReadOnly || undefined,
212
- "aria-required": isRequired || undefined,
213
- "aria-disabled": isDisabled || undefined,
214
- "aria-orientation": orientation,
215
- ...fieldProps,
216
- ...focusWithinProps
217
- }),
218
- labelProps: labelProps,
219
- descriptionProps: descriptionProps,
220
- errorMessageProps: errorMessageProps,
221
- isInvalid: isInvalid,
222
- validationErrors: validationErrors,
223
- validationDetails: validationDetails
224
- };
225
- }
226
-
227
15
 
228
16
 
229
17
 
@@ -1 +1 @@
1
- {"mappings":";;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;ACVD;;;;;;;;;;CAUC,GAWM,MAAM,4CAAiB,IAAI;;;;;;ADoB3B,SAAS,0CAAS,KAAqB,EAAE,KAAsB,EAAE,GAAgC;IACtG,IAAI,SACF,KAAK,YACL,QAAQ,EACR,cAAc,SAAS,EACvB,mBAAmB,cAAc,EAClC,GAAG;IAEJ,MAAM,aAAa,MAAM,UAAU,IAAI,MAAM,UAAU;IAEvD,IAAI,cAAc,YAAY;IAC9B,IAAI,eAAe,aAAa,QAAQ,kBAAkB;IAC1D,IAAI,CAAC,eAAe,CAAC,cACnB,QAAQ,IAAI,CAAC;IAGf,IAAI,UAAU,MAAM,aAAa,KAAK;IAEtC,IAAI,WAA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EV,UAAU;gBAEZ;YACF,KAAK;gBACH,IAAI,cAAc,SAAS,gBAAgB,YACzC,UAAU;qBAEV,UAAU;gBAEZ;YACF,KAAK;gBACH,UAAU;gBACV;YACF,KAAK;gBACH,UAAU;gBACV;YACF;gBACE;QACJ;QACA,EAAE,cAAc;QAChB,IAAI,SAAS,CAAA,GAAA,6BAAqB,EAAE,EAAE,aAAa,EAAE;YAAC,MAAM,EAAE,MAAM;QAAA;QACpE,IAAI;QACJ,IAAI,YAAY,QAAQ;YACtB,WAAW,OAAO,QAAQ;YAC1B,IAAI,CAAC,UAAU;gBACb,OAAO,WAAW,GAAG,EAAE,aAAa;gBACpC,WAAW,OAAO,UAAU;YAC9B;QACF,OAAO;YACL,WAAW,OAAO,YAAY;YAC9B,IAAI,CAAC,UAAU;gBACb,OAAO,WAAW,GAAG,EAAE,aAAa;gBACpC,WAAW,OAAO,SAAS;YAC7B;QACF;QACA,IAAI,UAAU;YACZ,iFAAiF;YACjF,SAAS,KAAK;YACd,MAAM,gBAAgB,CAAC,SAAS,KAAK;QACvC;IACF;IAEA,IAAI,YAAY,CAAA,GAAA,YAAI,EAAE;IACtB,CAAA,GAAA,yCAAa,EAAE,GAAG,CAAC,OAAO;QACxB,MAAM;QACN,eAAe,iBAAiB,EAAE;QAClC,gBAAgB,kBAAkB,EAAE;4BACpC;IACF;IAEA,OAAO;QACL,iBAAiB,CAAA,GAAA,iBAAS,EAAE,UAAU;YACpC,iDAAiD;YACjD,MAAM;uBACN;YACA,gBAAgB,MAAM,SAAS,IAAI;YACnC,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,iBAAiB,cAAc;YAC/B,iBAAiB,cAAc;YAC/B,iBAAiB,cAAc;YAC/B,oBAAoB;YACpB,GAAG,UAAU;YACb,GAAG,gBAAgB;QACrB;oBACA;0BACA;2BACA;mBACA;0BACA;2BACA;IACF;AACF;","sources":["packages/@react-aria/radio/src/index.ts","packages/@react-aria/radio/src/useRadio.ts","packages/@react-aria/radio/src/utils.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 */\nexport {useRadio} from './useRadio';\nexport {useRadioGroup} from './useRadioGroup';\nexport type {AriaRadioGroupProps, AriaRadioProps} from '@react-types/radio';\nexport type {Orientation} from '@react-types/shared';\nexport type {RadioAria} from './useRadio';\nexport type {RadioGroupAria} from './useRadioGroup';\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, useFormReset} from '@react-aria/utils';\nimport {InputHTMLAttributes, LabelHTMLAttributes, RefObject} from 'react';\nimport {radioGroupData} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useFocusable} from '@react-aria/focus';\nimport {useFormValidation} from '@react-aria/form';\nimport {usePress} from '@react-aria/interactions';\n\nexport interface RadioAria {\n /** Props for the label wrapper element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>,\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Whether the radio is disabled. */\n isDisabled: boolean,\n /** Whether the radio is currently selected. */\n isSelected: boolean,\n /** Whether the radio is in a pressed state. */\n isPressed: boolean\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<HTMLInputElement>): 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, isPressed} = usePress({\n isDisabled\n });\n\n // iOS does not toggle radios if you drag off and back onto the label, so handle it ourselves.\n let {pressProps: labelProps, isPressed: isLabelPressed} = usePress({\n isDisabled,\n onPress() {\n state.setSelectedValue(value);\n }\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: number | undefined = -1;\n if (state.selectedValue != null) {\n if (state.selectedValue === value) {\n tabIndex = 0;\n }\n } else if (state.lastFocusedValue === value || state.lastFocusedValue == null) {\n tabIndex = 0;\n }\n if (isDisabled) {\n tabIndex = undefined;\n }\n\n let {name, descriptionId, errorMessageId, validationBehavior} = radioGroupData.get(state)!;\n useFormReset(ref, state.selectedValue, state.setSelectedValue);\n useFormValidation({validationBehavior}, state, ref);\n\n return {\n labelProps: mergeProps(labelProps, {onClick: e => e.preventDefault()}),\n inputProps: mergeProps(domProps, {\n ...interactions,\n type: 'radio',\n name,\n tabIndex,\n disabled: isDisabled,\n required: state.isRequired && validationBehavior === 'native',\n checked,\n value,\n onChange,\n 'aria-describedby': [\n props['aria-describedby'],\n state.isInvalid ? errorMessageId : null,\n descriptionId\n ].filter(Boolean).join(' ') || undefined\n }),\n isDisabled,\n isSelected: checked,\n isPressed: isPressed || isLabelPressed\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 {RadioGroupState} from '@react-stately/radio';\n\ninterface RadioGroupData {\n name: string,\n descriptionId: string | undefined,\n errorMessageId: string | undefined,\n validationBehavior: 'aria' | 'native'\n}\n\nexport const radioGroupData = new WeakMap<RadioGroupState, RadioGroupData>();\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 {DOMAttributes, ValidationResult} from '@react-types/shared';\nimport {filterDOMProps, mergeProps, useId} from '@react-aria/utils';\nimport {getFocusableTreeWalker} from '@react-aria/focus';\nimport {radioGroupData} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useField} from '@react-aria/label';\nimport {useFocusWithin} from '@react-aria/interactions';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface RadioGroupAria extends ValidationResult {\n /** Props for the radio group wrapper element. */\n radioGroupProps: DOMAttributes,\n /** Props for the radio group's visible label (if any). */\n labelProps: DOMAttributes,\n /** Props for the radio group description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the radio group error message element, if any. */\n errorMessageProps: DOMAttributes\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 isReadOnly,\n isRequired,\n isDisabled,\n orientation = 'vertical',\n validationBehavior = 'aria'\n } = props;\n let {direction} = useLocale();\n\n let {isInvalid, validationErrors, validationDetails} = state.displayValidation;\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\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 isInvalid: state.isInvalid,\n errorMessage: props.errorMessage || validationErrors\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(e) {\n props.onBlur?.(e);\n if (!state.selectedValue) {\n state.setLastFocusedValue(null);\n }\n },\n onFocusWithin: props.onFocus,\n onFocusWithinChange: props.onFocusChange\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 radioGroupData.set(state, {\n name: groupName,\n descriptionId: descriptionProps.id,\n errorMessageId: errorMessageProps.id,\n validationBehavior\n });\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': state.isInvalid || 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 descriptionProps,\n errorMessageProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/radio/src/index.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 */\nexport {useRadio} from './useRadio';\nexport {useRadioGroup} from './useRadioGroup';\nexport type {AriaRadioGroupProps, AriaRadioProps} from '@react-types/radio';\nexport type {Orientation} from '@react-types/shared';\nexport type {RadioAria} from './useRadio';\nexport type {RadioGroupAria} from './useRadioGroup';\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,93 @@
1
+ var $eeb149278aae5c67$exports = require("./utils.main.js");
2
+ var $gWC9A$reactariautils = require("@react-aria/utils");
3
+ var $gWC9A$reactariafocus = require("@react-aria/focus");
4
+ var $gWC9A$reactariaform = require("@react-aria/form");
5
+ var $gWC9A$reactariainteractions = require("@react-aria/interactions");
6
+
7
+
8
+ function $parcel$export(e, n, v, s) {
9
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
10
+ }
11
+
12
+ $parcel$export(module.exports, "useRadio", () => $e184702b1b7f1863$export$37b0961d2f4751e2);
13
+ /*
14
+ * Copyright 2020 Adobe. All rights reserved.
15
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
16
+ * you may not use this file except in compliance with the License. You may obtain a copy
17
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software distributed under
20
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21
+ * OF ANY KIND, either express or implied. See the License for the specific language
22
+ * governing permissions and limitations under the License.
23
+ */
24
+
25
+
26
+
27
+
28
+ function $e184702b1b7f1863$export$37b0961d2f4751e2(props, state, ref) {
29
+ let { value: value, children: children, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby } = props;
30
+ const isDisabled = props.isDisabled || state.isDisabled;
31
+ let hasChildren = children != null;
32
+ let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;
33
+ if (!hasChildren && !hasAriaLabel) console.warn("If you do not provide children, you must specify an aria-label for accessibility");
34
+ let checked = state.selectedValue === value;
35
+ let onChange = (e)=>{
36
+ e.stopPropagation();
37
+ state.setSelectedValue(value);
38
+ };
39
+ let { pressProps: pressProps, isPressed: isPressed } = (0, $gWC9A$reactariainteractions.usePress)({
40
+ isDisabled: isDisabled
41
+ });
42
+ // iOS does not toggle radios if you drag off and back onto the label, so handle it ourselves.
43
+ let { pressProps: labelProps, isPressed: isLabelPressed } = (0, $gWC9A$reactariainteractions.usePress)({
44
+ isDisabled: isDisabled,
45
+ onPress () {
46
+ state.setSelectedValue(value);
47
+ }
48
+ });
49
+ let { focusableProps: focusableProps } = (0, $gWC9A$reactariafocus.useFocusable)((0, $gWC9A$reactariautils.mergeProps)(props, {
50
+ onFocus: ()=>state.setLastFocusedValue(value)
51
+ }), ref);
52
+ let interactions = (0, $gWC9A$reactariautils.mergeProps)(pressProps, focusableProps);
53
+ let domProps = (0, $gWC9A$reactariautils.filterDOMProps)(props, {
54
+ labelable: true
55
+ });
56
+ let tabIndex = -1;
57
+ if (state.selectedValue != null) {
58
+ if (state.selectedValue === value) tabIndex = 0;
59
+ } else if (state.lastFocusedValue === value || state.lastFocusedValue == null) tabIndex = 0;
60
+ if (isDisabled) tabIndex = undefined;
61
+ let { name: name, descriptionId: descriptionId, errorMessageId: errorMessageId, validationBehavior: validationBehavior } = (0, $eeb149278aae5c67$exports.radioGroupData).get(state);
62
+ (0, $gWC9A$reactariautils.useFormReset)(ref, state.selectedValue, state.setSelectedValue);
63
+ (0, $gWC9A$reactariaform.useFormValidation)({
64
+ validationBehavior: validationBehavior
65
+ }, state, ref);
66
+ return {
67
+ labelProps: (0, $gWC9A$reactariautils.mergeProps)(labelProps, {
68
+ onClick: (e)=>e.preventDefault()
69
+ }),
70
+ inputProps: (0, $gWC9A$reactariautils.mergeProps)(domProps, {
71
+ ...interactions,
72
+ type: "radio",
73
+ name: name,
74
+ tabIndex: tabIndex,
75
+ disabled: isDisabled,
76
+ required: state.isRequired && validationBehavior === "native",
77
+ checked: checked,
78
+ value: value,
79
+ onChange: onChange,
80
+ "aria-describedby": [
81
+ props["aria-describedby"],
82
+ state.isInvalid ? errorMessageId : null,
83
+ descriptionId
84
+ ].filter(Boolean).join(" ") || undefined
85
+ }),
86
+ isDisabled: isDisabled,
87
+ isSelected: checked,
88
+ isPressed: isPressed || isLabelPressed
89
+ };
90
+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Gb,IAAI,QAAC,IAAI,iBAAE,aAAa,kBAAE,cAAc,sBAAE,kBAAkB,EAAC,GAAG,CAAA,GAAA,wCAAa,EAAE,GAAG,CAAC;IACnF,CAAA,GAAA,kCAAW,EAAE,KAAK,MAAM,aAAa,EAAE,MAAM,gBAAgB;IAC7D,CAAA,GAAA,sCAAgB,EAAE;4BAAC;IAAkB,GAAG,OAAO;IAE/C,OAAO;QACL,YAAY,CAAA,GAAA,gCAAS,EAAE,YAAY;YAAC,SAAS,CAAA,IAAK,EAAE,cAAc;QAAE;QACpE,YAAY,CAAA,GAAA,gCAAS,EAAE,UAAU;YAC/B,GAAG,YAAY;YACf,MAAM;kBACN;sBACA;YACA,UAAU;YACV,UAAU,MAAM,UAAU,IAAI,uBAAuB;qBACrD;mBACA;sBACA;YACA,oBAAoB;gBAClB,KAAK,CAAC,mBAAmB;gBACzB,MAAM,SAAS,GAAG,iBAAiB;gBACnC;aACD,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,QAAQ;QACjC;oBACA;QACA,YAAY;QACZ,WAAW,aAAa;IAC1B;AACF","sources":["packages/@react-aria/radio/src/useRadio.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 {AriaRadioProps} from '@react-types/radio';\nimport {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';\nimport {InputHTMLAttributes, LabelHTMLAttributes, RefObject} from 'react';\nimport {radioGroupData} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useFocusable} from '@react-aria/focus';\nimport {useFormValidation} from '@react-aria/form';\nimport {usePress} from '@react-aria/interactions';\n\nexport interface RadioAria {\n /** Props for the label wrapper element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>,\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Whether the radio is disabled. */\n isDisabled: boolean,\n /** Whether the radio is currently selected. */\n isSelected: boolean,\n /** Whether the radio is in a pressed state. */\n isPressed: boolean\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<HTMLInputElement>): 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, isPressed} = usePress({\n isDisabled\n });\n\n // iOS does not toggle radios if you drag off and back onto the label, so handle it ourselves.\n let {pressProps: labelProps, isPressed: isLabelPressed} = usePress({\n isDisabled,\n onPress() {\n state.setSelectedValue(value);\n }\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: number | undefined = -1;\n if (state.selectedValue != null) {\n if (state.selectedValue === value) {\n tabIndex = 0;\n }\n } else if (state.lastFocusedValue === value || state.lastFocusedValue == null) {\n tabIndex = 0;\n }\n if (isDisabled) {\n tabIndex = undefined;\n }\n\n let {name, descriptionId, errorMessageId, validationBehavior} = radioGroupData.get(state)!;\n useFormReset(ref, state.selectedValue, state.setSelectedValue);\n useFormValidation({validationBehavior}, state, ref);\n\n return {\n labelProps: mergeProps(labelProps, {onClick: e => e.preventDefault()}),\n inputProps: mergeProps(domProps, {\n ...interactions,\n type: 'radio',\n name,\n tabIndex,\n disabled: isDisabled,\n required: state.isRequired && validationBehavior === 'native',\n checked,\n value,\n onChange,\n 'aria-describedby': [\n props['aria-describedby'],\n state.isInvalid ? errorMessageId : null,\n descriptionId\n ].filter(Boolean).join(' ') || undefined\n }),\n isDisabled,\n isSelected: checked,\n isPressed: isPressed || isLabelPressed\n };\n}\n"],"names":[],"version":3,"file":"useRadio.main.js.map"}
@@ -0,0 +1,88 @@
1
+ import {radioGroupData as $884aeceb3d67f00f$export$37b65e5b5444d35c} from "./utils.mjs";
2
+ import {mergeProps as $5jJ3f$mergeProps, filterDOMProps as $5jJ3f$filterDOMProps, useFormReset as $5jJ3f$useFormReset} from "@react-aria/utils";
3
+ import {useFocusable as $5jJ3f$useFocusable} from "@react-aria/focus";
4
+ import {useFormValidation as $5jJ3f$useFormValidation} from "@react-aria/form";
5
+ import {usePress as $5jJ3f$usePress} from "@react-aria/interactions";
6
+
7
+ /*
8
+ * Copyright 2020 Adobe. All rights reserved.
9
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License. You may obtain a copy
11
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software distributed under
14
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
+ * OF ANY KIND, either express or implied. See the License for the specific language
16
+ * governing permissions and limitations under the License.
17
+ */
18
+
19
+
20
+
21
+
22
+ function $0d5c49892c1215da$export$37b0961d2f4751e2(props, state, ref) {
23
+ let { value: value, children: children, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby } = props;
24
+ const isDisabled = props.isDisabled || state.isDisabled;
25
+ let hasChildren = children != null;
26
+ let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;
27
+ if (!hasChildren && !hasAriaLabel) console.warn("If you do not provide children, you must specify an aria-label for accessibility");
28
+ let checked = state.selectedValue === value;
29
+ let onChange = (e)=>{
30
+ e.stopPropagation();
31
+ state.setSelectedValue(value);
32
+ };
33
+ let { pressProps: pressProps, isPressed: isPressed } = (0, $5jJ3f$usePress)({
34
+ isDisabled: isDisabled
35
+ });
36
+ // iOS does not toggle radios if you drag off and back onto the label, so handle it ourselves.
37
+ let { pressProps: labelProps, isPressed: isLabelPressed } = (0, $5jJ3f$usePress)({
38
+ isDisabled: isDisabled,
39
+ onPress () {
40
+ state.setSelectedValue(value);
41
+ }
42
+ });
43
+ let { focusableProps: focusableProps } = (0, $5jJ3f$useFocusable)((0, $5jJ3f$mergeProps)(props, {
44
+ onFocus: ()=>state.setLastFocusedValue(value)
45
+ }), ref);
46
+ let interactions = (0, $5jJ3f$mergeProps)(pressProps, focusableProps);
47
+ let domProps = (0, $5jJ3f$filterDOMProps)(props, {
48
+ labelable: true
49
+ });
50
+ let tabIndex = -1;
51
+ if (state.selectedValue != null) {
52
+ if (state.selectedValue === value) tabIndex = 0;
53
+ } else if (state.lastFocusedValue === value || state.lastFocusedValue == null) tabIndex = 0;
54
+ if (isDisabled) tabIndex = undefined;
55
+ let { name: name, descriptionId: descriptionId, errorMessageId: errorMessageId, validationBehavior: validationBehavior } = (0, $884aeceb3d67f00f$export$37b65e5b5444d35c).get(state);
56
+ (0, $5jJ3f$useFormReset)(ref, state.selectedValue, state.setSelectedValue);
57
+ (0, $5jJ3f$useFormValidation)({
58
+ validationBehavior: validationBehavior
59
+ }, state, ref);
60
+ return {
61
+ labelProps: (0, $5jJ3f$mergeProps)(labelProps, {
62
+ onClick: (e)=>e.preventDefault()
63
+ }),
64
+ inputProps: (0, $5jJ3f$mergeProps)(domProps, {
65
+ ...interactions,
66
+ type: "radio",
67
+ name: name,
68
+ tabIndex: tabIndex,
69
+ disabled: isDisabled,
70
+ required: state.isRequired && validationBehavior === "native",
71
+ checked: checked,
72
+ value: value,
73
+ onChange: onChange,
74
+ "aria-describedby": [
75
+ props["aria-describedby"],
76
+ state.isInvalid ? errorMessageId : null,
77
+ descriptionId
78
+ ].filter(Boolean).join(" ") || undefined
79
+ }),
80
+ isDisabled: isDisabled,
81
+ isSelected: checked,
82
+ isPressed: isPressed || isLabelPressed
83
+ };
84
+ }
85
+
86
+
87
+ export {$0d5c49892c1215da$export$37b0961d2f4751e2 as useRadio};
88
+ //# sourceMappingURL=useRadio.mjs.map
@@ -0,0 +1,88 @@
1
+ import {radioGroupData as $884aeceb3d67f00f$export$37b65e5b5444d35c} from "./utils.module.js";
2
+ import {mergeProps as $5jJ3f$mergeProps, filterDOMProps as $5jJ3f$filterDOMProps, useFormReset as $5jJ3f$useFormReset} from "@react-aria/utils";
3
+ import {useFocusable as $5jJ3f$useFocusable} from "@react-aria/focus";
4
+ import {useFormValidation as $5jJ3f$useFormValidation} from "@react-aria/form";
5
+ import {usePress as $5jJ3f$usePress} from "@react-aria/interactions";
6
+
7
+ /*
8
+ * Copyright 2020 Adobe. All rights reserved.
9
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License. You may obtain a copy
11
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software distributed under
14
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
+ * OF ANY KIND, either express or implied. See the License for the specific language
16
+ * governing permissions and limitations under the License.
17
+ */
18
+
19
+
20
+
21
+
22
+ function $0d5c49892c1215da$export$37b0961d2f4751e2(props, state, ref) {
23
+ let { value: value, children: children, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby } = props;
24
+ const isDisabled = props.isDisabled || state.isDisabled;
25
+ let hasChildren = children != null;
26
+ let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;
27
+ if (!hasChildren && !hasAriaLabel) console.warn("If you do not provide children, you must specify an aria-label for accessibility");
28
+ let checked = state.selectedValue === value;
29
+ let onChange = (e)=>{
30
+ e.stopPropagation();
31
+ state.setSelectedValue(value);
32
+ };
33
+ let { pressProps: pressProps, isPressed: isPressed } = (0, $5jJ3f$usePress)({
34
+ isDisabled: isDisabled
35
+ });
36
+ // iOS does not toggle radios if you drag off and back onto the label, so handle it ourselves.
37
+ let { pressProps: labelProps, isPressed: isLabelPressed } = (0, $5jJ3f$usePress)({
38
+ isDisabled: isDisabled,
39
+ onPress () {
40
+ state.setSelectedValue(value);
41
+ }
42
+ });
43
+ let { focusableProps: focusableProps } = (0, $5jJ3f$useFocusable)((0, $5jJ3f$mergeProps)(props, {
44
+ onFocus: ()=>state.setLastFocusedValue(value)
45
+ }), ref);
46
+ let interactions = (0, $5jJ3f$mergeProps)(pressProps, focusableProps);
47
+ let domProps = (0, $5jJ3f$filterDOMProps)(props, {
48
+ labelable: true
49
+ });
50
+ let tabIndex = -1;
51
+ if (state.selectedValue != null) {
52
+ if (state.selectedValue === value) tabIndex = 0;
53
+ } else if (state.lastFocusedValue === value || state.lastFocusedValue == null) tabIndex = 0;
54
+ if (isDisabled) tabIndex = undefined;
55
+ let { name: name, descriptionId: descriptionId, errorMessageId: errorMessageId, validationBehavior: validationBehavior } = (0, $884aeceb3d67f00f$export$37b65e5b5444d35c).get(state);
56
+ (0, $5jJ3f$useFormReset)(ref, state.selectedValue, state.setSelectedValue);
57
+ (0, $5jJ3f$useFormValidation)({
58
+ validationBehavior: validationBehavior
59
+ }, state, ref);
60
+ return {
61
+ labelProps: (0, $5jJ3f$mergeProps)(labelProps, {
62
+ onClick: (e)=>e.preventDefault()
63
+ }),
64
+ inputProps: (0, $5jJ3f$mergeProps)(domProps, {
65
+ ...interactions,
66
+ type: "radio",
67
+ name: name,
68
+ tabIndex: tabIndex,
69
+ disabled: isDisabled,
70
+ required: state.isRequired && validationBehavior === "native",
71
+ checked: checked,
72
+ value: value,
73
+ onChange: onChange,
74
+ "aria-describedby": [
75
+ props["aria-describedby"],
76
+ state.isInvalid ? errorMessageId : null,
77
+ descriptionId
78
+ ].filter(Boolean).join(" ") || undefined
79
+ }),
80
+ isDisabled: isDisabled,
81
+ isSelected: checked,
82
+ isPressed: isPressed || isLabelPressed
83
+ };
84
+ }
85
+
86
+
87
+ export {$0d5c49892c1215da$export$37b0961d2f4751e2 as useRadio};
88
+ //# sourceMappingURL=useRadio.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA+BM,SAAS,0CAAS,KAAqB,EAAE,KAAsB,EAAE,GAAgC;IACtG,IAAI,SACF,KAAK,YACL,QAAQ,EACR,cAAc,SAAS,EACvB,mBAAmB,cAAc,EAClC,GAAG;IAEJ,MAAM,aAAa,MAAM,UAAU,IAAI,MAAM,UAAU;IAEvD,IAAI,cAAc,YAAY;IAC9B,IAAI,eAAe,aAAa,QAAQ,kBAAkB;IAC1D,IAAI,CAAC,eAAe,CAAC,cACnB,QAAQ,IAAI,CAAC;IAGf,IAAI,UAAU,MAAM,aAAa,KAAK;IAEtC,IAAI,WAAW,CAAC;QACd,EAAE,eAAe;QACjB,MAAM,gBAAgB,CAAC;IACzB;IAEA,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;oBACrC;IACF;IAEA,8FAA8F;IAC9F,IAAI,EAAC,YAAY,UAAU,EAAE,WAAW,cAAc,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;oBACjE;QACA;YACE,MAAM,gBAAgB,CAAC;QACzB;IACF;IAEA,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,mBAAW,EAAE,CAAA,GAAA,iBAAS,EAAE,OAAO;QACpD,SAAS,IAAM,MAAM,mBAAmB,CAAC;IAC3C,IAAI;IACJ,IAAI,eAAe,CAAA,GAAA,iBAAS,EAAE,YAAY;IAC1C,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IACrD,IAAI,WAA+B;IACnC,IAAI,MAAM,aAAa,IAAI,MACzB;QAAA,IAAI,MAAM,aAAa,KAAK,OAC1B,WAAW;IACb,OACK,IAAI,MAAM,gBAAgB,KAAK,SAAS,MAAM,gBAAgB,IAAI,MACvE,WAAW;IAEb,IAAI,YACF,WAAW;IAGb,IAAI,QAAC,IAAI,iBAAE,aAAa,kBAAE,cAAc,sBAAE,kBAAkB,EAAC,GAAG,CAAA,GAAA,yCAAa,EAAE,GAAG,CAAC;IACnF,CAAA,GAAA,mBAAW,EAAE,KAAK,MAAM,aAAa,EAAE,MAAM,gBAAgB;IAC7D,CAAA,GAAA,wBAAgB,EAAE;4BAAC;IAAkB,GAAG,OAAO;IAE/C,OAAO;QACL,YAAY,CAAA,GAAA,iBAAS,EAAE,YAAY;YAAC,SAAS,CAAA,IAAK,EAAE,cAAc;QAAE;QACpE,YAAY,CAAA,GAAA,iBAAS,EAAE,UAAU;YAC/B,GAAG,YAAY;YACf,MAAM;kBACN;sBACA;YACA,UAAU;YACV,UAAU,MAAM,UAAU,IAAI,uBAAuB;qBACrD;mBACA;sBACA;YACA,oBAAoB;gBAClB,KAAK,CAAC,mBAAmB;gBACzB,MAAM,SAAS,GAAG,iBAAiB;gBACnC;aACD,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,QAAQ;QACjC;oBACA;QACA,YAAY;QACZ,WAAW,aAAa;IAC1B;AACF","sources":["packages/@react-aria/radio/src/useRadio.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 {AriaRadioProps} from '@react-types/radio';\nimport {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';\nimport {InputHTMLAttributes, LabelHTMLAttributes, RefObject} from 'react';\nimport {radioGroupData} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useFocusable} from '@react-aria/focus';\nimport {useFormValidation} from '@react-aria/form';\nimport {usePress} from '@react-aria/interactions';\n\nexport interface RadioAria {\n /** Props for the label wrapper element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>,\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Whether the radio is disabled. */\n isDisabled: boolean,\n /** Whether the radio is currently selected. */\n isSelected: boolean,\n /** Whether the radio is in a pressed state. */\n isPressed: boolean\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<HTMLInputElement>): 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, isPressed} = usePress({\n isDisabled\n });\n\n // iOS does not toggle radios if you drag off and back onto the label, so handle it ourselves.\n let {pressProps: labelProps, isPressed: isLabelPressed} = usePress({\n isDisabled,\n onPress() {\n state.setSelectedValue(value);\n }\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: number | undefined = -1;\n if (state.selectedValue != null) {\n if (state.selectedValue === value) {\n tabIndex = 0;\n }\n } else if (state.lastFocusedValue === value || state.lastFocusedValue == null) {\n tabIndex = 0;\n }\n if (isDisabled) {\n tabIndex = undefined;\n }\n\n let {name, descriptionId, errorMessageId, validationBehavior} = radioGroupData.get(state)!;\n useFormReset(ref, state.selectedValue, state.setSelectedValue);\n useFormValidation({validationBehavior}, state, ref);\n\n return {\n labelProps: mergeProps(labelProps, {onClick: e => e.preventDefault()}),\n inputProps: mergeProps(domProps, {\n ...interactions,\n type: 'radio',\n name,\n tabIndex,\n disabled: isDisabled,\n required: state.isRequired && validationBehavior === 'native',\n checked,\n value,\n onChange,\n 'aria-describedby': [\n props['aria-describedby'],\n state.isInvalid ? errorMessageId : null,\n descriptionId\n ].filter(Boolean).join(' ') || undefined\n }),\n isDisabled,\n isSelected: checked,\n isPressed: isPressed || isLabelPressed\n };\n}\n"],"names":[],"version":3,"file":"useRadio.module.js.map"}