@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.
@@ -0,0 +1,132 @@
1
+ var $eeb149278aae5c67$exports = require("./utils.main.js");
2
+ var $bNSfM$reactariautils = require("@react-aria/utils");
3
+ var $bNSfM$reactariafocus = require("@react-aria/focus");
4
+ var $bNSfM$reactarialabel = require("@react-aria/label");
5
+ var $bNSfM$reactariainteractions = require("@react-aria/interactions");
6
+ var $bNSfM$reactariai18n = require("@react-aria/i18n");
7
+
8
+
9
+ function $parcel$export(e, n, v, s) {
10
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
11
+ }
12
+
13
+ $parcel$export(module.exports, "useRadioGroup", () => $dfcade00a56a6317$export$62b9571f283ff5c2);
14
+ /*
15
+ * Copyright 2020 Adobe. All rights reserved.
16
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
17
+ * you may not use this file except in compliance with the License. You may obtain a copy
18
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
19
+ *
20
+ * Unless required by applicable law or agreed to in writing, software distributed under
21
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
22
+ * OF ANY KIND, either express or implied. See the License for the specific language
23
+ * governing permissions and limitations under the License.
24
+ */
25
+
26
+
27
+
28
+
29
+
30
+ function $dfcade00a56a6317$export$62b9571f283ff5c2(props, state) {
31
+ let { name: name, isReadOnly: isReadOnly, isRequired: isRequired, isDisabled: isDisabled, orientation: orientation = "vertical", validationBehavior: validationBehavior = "aria" } = props;
32
+ let { direction: direction } = (0, $bNSfM$reactariai18n.useLocale)();
33
+ let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
34
+ let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $bNSfM$reactarialabel.useField)({
35
+ ...props,
36
+ // Radio group is not an HTML input element so it
37
+ // shouldn't be labeled by a <label> element.
38
+ labelElementType: "span",
39
+ isInvalid: state.isInvalid,
40
+ errorMessage: props.errorMessage || validationErrors
41
+ });
42
+ let domProps = (0, $bNSfM$reactariautils.filterDOMProps)(props, {
43
+ labelable: true
44
+ });
45
+ // When the radio group loses focus, reset the focusable radio to null if
46
+ // there is no selection. This allows tabbing into the group from either
47
+ // direction to go to the first or last radio.
48
+ let { focusWithinProps: focusWithinProps } = (0, $bNSfM$reactariainteractions.useFocusWithin)({
49
+ onBlurWithin (e) {
50
+ var _props_onBlur;
51
+ (_props_onBlur = props.onBlur) === null || _props_onBlur === void 0 ? void 0 : _props_onBlur.call(props, e);
52
+ if (!state.selectedValue) state.setLastFocusedValue(null);
53
+ },
54
+ onFocusWithin: props.onFocus,
55
+ onFocusWithinChange: props.onFocusChange
56
+ });
57
+ let onKeyDown = (e)=>{
58
+ let nextDir;
59
+ switch(e.key){
60
+ case "ArrowRight":
61
+ if (direction === "rtl" && orientation !== "vertical") nextDir = "prev";
62
+ else nextDir = "next";
63
+ break;
64
+ case "ArrowLeft":
65
+ if (direction === "rtl" && orientation !== "vertical") nextDir = "next";
66
+ else nextDir = "prev";
67
+ break;
68
+ case "ArrowDown":
69
+ nextDir = "next";
70
+ break;
71
+ case "ArrowUp":
72
+ nextDir = "prev";
73
+ break;
74
+ default:
75
+ return;
76
+ }
77
+ e.preventDefault();
78
+ let walker = (0, $bNSfM$reactariafocus.getFocusableTreeWalker)(e.currentTarget, {
79
+ from: e.target
80
+ });
81
+ let nextElem;
82
+ if (nextDir === "next") {
83
+ nextElem = walker.nextNode();
84
+ if (!nextElem) {
85
+ walker.currentNode = e.currentTarget;
86
+ nextElem = walker.firstChild();
87
+ }
88
+ } else {
89
+ nextElem = walker.previousNode();
90
+ if (!nextElem) {
91
+ walker.currentNode = e.currentTarget;
92
+ nextElem = walker.lastChild();
93
+ }
94
+ }
95
+ if (nextElem) {
96
+ // Call focus on nextElem so that keyboard navigation scrolls the radio into view
97
+ nextElem.focus();
98
+ state.setSelectedValue(nextElem.value);
99
+ }
100
+ };
101
+ let groupName = (0, $bNSfM$reactariautils.useId)(name);
102
+ (0, $eeb149278aae5c67$exports.radioGroupData).set(state, {
103
+ name: groupName,
104
+ descriptionId: descriptionProps.id,
105
+ errorMessageId: errorMessageProps.id,
106
+ validationBehavior: validationBehavior
107
+ });
108
+ return {
109
+ radioGroupProps: (0, $bNSfM$reactariautils.mergeProps)(domProps, {
110
+ // https://www.w3.org/TR/wai-aria-1.2/#radiogroup
111
+ role: "radiogroup",
112
+ onKeyDown: onKeyDown,
113
+ "aria-invalid": state.isInvalid || undefined,
114
+ "aria-errormessage": props["aria-errormessage"],
115
+ "aria-readonly": isReadOnly || undefined,
116
+ "aria-required": isRequired || undefined,
117
+ "aria-disabled": isDisabled || undefined,
118
+ "aria-orientation": orientation,
119
+ ...fieldProps,
120
+ ...focusWithinProps
121
+ }),
122
+ labelProps: labelProps,
123
+ descriptionProps: descriptionProps,
124
+ errorMessageProps: errorMessageProps,
125
+ isInvalid: isInvalid,
126
+ validationErrors: validationErrors,
127
+ validationDetails: validationDetails
128
+ };
129
+ }
130
+
131
+
132
+ //# sourceMappingURL=useRadioGroup.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AA6BM,SAAS,0CAAc,KAA0B,EAAE,KAAsB;IAC9E,IAAI,QACF,IAAI,cACJ,UAAU,cACV,UAAU,cACV,UAAU,eACV,cAAc,gCACd,qBAAqB,QACtB,GAAG;IACJ,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,8BAAQ;IAE1B,IAAI,aAAC,SAAS,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,MAAM,iBAAiB;IAC9E,IAAI,cAAC,UAAU,cAAE,UAAU,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,CAAA,GAAA,8BAAO,EAAE;QAC3E,GAAG,K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gBAAgB,CAAC,SAAS,KAAK;QACvC;IACF;IAEA,IAAI,YAAY,CAAA,GAAA,2BAAI,EAAE;IACtB,CAAA,GAAA,wCAAa,EAAE,GAAG,CAAC,OAAO;QACxB,MAAM;QACN,eAAe,iBAAiB,EAAE;QAClC,gBAAgB,kBAAkB,EAAE;4BACpC;IACF;IAEA,OAAO;QACL,iBAAiB,CAAA,GAAA,gCAAS,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/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 {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":"useRadioGroup.main.js.map"}
@@ -0,0 +1,127 @@
1
+ import {radioGroupData as $884aeceb3d67f00f$export$37b65e5b5444d35c} from "./utils.mjs";
2
+ import {filterDOMProps as $czmJy$filterDOMProps, useId as $czmJy$useId, mergeProps as $czmJy$mergeProps} from "@react-aria/utils";
3
+ import {getFocusableTreeWalker as $czmJy$getFocusableTreeWalker} from "@react-aria/focus";
4
+ import {useField as $czmJy$useField} from "@react-aria/label";
5
+ import {useFocusWithin as $czmJy$useFocusWithin} from "@react-aria/interactions";
6
+ import {useLocale as $czmJy$useLocale} from "@react-aria/i18n";
7
+
8
+ /*
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
+
20
+
21
+
22
+
23
+
24
+ function $430f30ed08ec25fa$export$62b9571f283ff5c2(props, state) {
25
+ let { name: name, isReadOnly: isReadOnly, isRequired: isRequired, isDisabled: isDisabled, orientation: orientation = "vertical", validationBehavior: validationBehavior = "aria" } = props;
26
+ let { direction: direction } = (0, $czmJy$useLocale)();
27
+ let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
28
+ let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $czmJy$useField)({
29
+ ...props,
30
+ // Radio group is not an HTML input element so it
31
+ // shouldn't be labeled by a <label> element.
32
+ labelElementType: "span",
33
+ isInvalid: state.isInvalid,
34
+ errorMessage: props.errorMessage || validationErrors
35
+ });
36
+ let domProps = (0, $czmJy$filterDOMProps)(props, {
37
+ labelable: true
38
+ });
39
+ // When the radio group loses focus, reset the focusable radio to null if
40
+ // there is no selection. This allows tabbing into the group from either
41
+ // direction to go to the first or last radio.
42
+ let { focusWithinProps: focusWithinProps } = (0, $czmJy$useFocusWithin)({
43
+ onBlurWithin (e) {
44
+ var _props_onBlur;
45
+ (_props_onBlur = props.onBlur) === null || _props_onBlur === void 0 ? void 0 : _props_onBlur.call(props, e);
46
+ if (!state.selectedValue) state.setLastFocusedValue(null);
47
+ },
48
+ onFocusWithin: props.onFocus,
49
+ onFocusWithinChange: props.onFocusChange
50
+ });
51
+ let onKeyDown = (e)=>{
52
+ let nextDir;
53
+ switch(e.key){
54
+ case "ArrowRight":
55
+ if (direction === "rtl" && orientation !== "vertical") nextDir = "prev";
56
+ else nextDir = "next";
57
+ break;
58
+ case "ArrowLeft":
59
+ if (direction === "rtl" && orientation !== "vertical") nextDir = "next";
60
+ else nextDir = "prev";
61
+ break;
62
+ case "ArrowDown":
63
+ nextDir = "next";
64
+ break;
65
+ case "ArrowUp":
66
+ nextDir = "prev";
67
+ break;
68
+ default:
69
+ return;
70
+ }
71
+ e.preventDefault();
72
+ let walker = (0, $czmJy$getFocusableTreeWalker)(e.currentTarget, {
73
+ from: e.target
74
+ });
75
+ let nextElem;
76
+ if (nextDir === "next") {
77
+ nextElem = walker.nextNode();
78
+ if (!nextElem) {
79
+ walker.currentNode = e.currentTarget;
80
+ nextElem = walker.firstChild();
81
+ }
82
+ } else {
83
+ nextElem = walker.previousNode();
84
+ if (!nextElem) {
85
+ walker.currentNode = e.currentTarget;
86
+ nextElem = walker.lastChild();
87
+ }
88
+ }
89
+ if (nextElem) {
90
+ // Call focus on nextElem so that keyboard navigation scrolls the radio into view
91
+ nextElem.focus();
92
+ state.setSelectedValue(nextElem.value);
93
+ }
94
+ };
95
+ let groupName = (0, $czmJy$useId)(name);
96
+ (0, $884aeceb3d67f00f$export$37b65e5b5444d35c).set(state, {
97
+ name: groupName,
98
+ descriptionId: descriptionProps.id,
99
+ errorMessageId: errorMessageProps.id,
100
+ validationBehavior: validationBehavior
101
+ });
102
+ return {
103
+ radioGroupProps: (0, $czmJy$mergeProps)(domProps, {
104
+ // https://www.w3.org/TR/wai-aria-1.2/#radiogroup
105
+ role: "radiogroup",
106
+ onKeyDown: onKeyDown,
107
+ "aria-invalid": state.isInvalid || undefined,
108
+ "aria-errormessage": props["aria-errormessage"],
109
+ "aria-readonly": isReadOnly || undefined,
110
+ "aria-required": isRequired || undefined,
111
+ "aria-disabled": isDisabled || undefined,
112
+ "aria-orientation": orientation,
113
+ ...fieldProps,
114
+ ...focusWithinProps
115
+ }),
116
+ labelProps: labelProps,
117
+ descriptionProps: descriptionProps,
118
+ errorMessageProps: errorMessageProps,
119
+ isInvalid: isInvalid,
120
+ validationErrors: validationErrors,
121
+ validationDetails: validationDetails
122
+ };
123
+ }
124
+
125
+
126
+ export {$430f30ed08ec25fa$export$62b9571f283ff5c2 as useRadioGroup};
127
+ //# sourceMappingURL=useRadioGroup.mjs.map
@@ -0,0 +1,127 @@
1
+ import {radioGroupData as $884aeceb3d67f00f$export$37b65e5b5444d35c} from "./utils.module.js";
2
+ import {filterDOMProps as $czmJy$filterDOMProps, useId as $czmJy$useId, mergeProps as $czmJy$mergeProps} from "@react-aria/utils";
3
+ import {getFocusableTreeWalker as $czmJy$getFocusableTreeWalker} from "@react-aria/focus";
4
+ import {useField as $czmJy$useField} from "@react-aria/label";
5
+ import {useFocusWithin as $czmJy$useFocusWithin} from "@react-aria/interactions";
6
+ import {useLocale as $czmJy$useLocale} from "@react-aria/i18n";
7
+
8
+ /*
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
+
20
+
21
+
22
+
23
+
24
+ function $430f30ed08ec25fa$export$62b9571f283ff5c2(props, state) {
25
+ let { name: name, isReadOnly: isReadOnly, isRequired: isRequired, isDisabled: isDisabled, orientation: orientation = "vertical", validationBehavior: validationBehavior = "aria" } = props;
26
+ let { direction: direction } = (0, $czmJy$useLocale)();
27
+ let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
28
+ let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $czmJy$useField)({
29
+ ...props,
30
+ // Radio group is not an HTML input element so it
31
+ // shouldn't be labeled by a <label> element.
32
+ labelElementType: "span",
33
+ isInvalid: state.isInvalid,
34
+ errorMessage: props.errorMessage || validationErrors
35
+ });
36
+ let domProps = (0, $czmJy$filterDOMProps)(props, {
37
+ labelable: true
38
+ });
39
+ // When the radio group loses focus, reset the focusable radio to null if
40
+ // there is no selection. This allows tabbing into the group from either
41
+ // direction to go to the first or last radio.
42
+ let { focusWithinProps: focusWithinProps } = (0, $czmJy$useFocusWithin)({
43
+ onBlurWithin (e) {
44
+ var _props_onBlur;
45
+ (_props_onBlur = props.onBlur) === null || _props_onBlur === void 0 ? void 0 : _props_onBlur.call(props, e);
46
+ if (!state.selectedValue) state.setLastFocusedValue(null);
47
+ },
48
+ onFocusWithin: props.onFocus,
49
+ onFocusWithinChange: props.onFocusChange
50
+ });
51
+ let onKeyDown = (e)=>{
52
+ let nextDir;
53
+ switch(e.key){
54
+ case "ArrowRight":
55
+ if (direction === "rtl" && orientation !== "vertical") nextDir = "prev";
56
+ else nextDir = "next";
57
+ break;
58
+ case "ArrowLeft":
59
+ if (direction === "rtl" && orientation !== "vertical") nextDir = "next";
60
+ else nextDir = "prev";
61
+ break;
62
+ case "ArrowDown":
63
+ nextDir = "next";
64
+ break;
65
+ case "ArrowUp":
66
+ nextDir = "prev";
67
+ break;
68
+ default:
69
+ return;
70
+ }
71
+ e.preventDefault();
72
+ let walker = (0, $czmJy$getFocusableTreeWalker)(e.currentTarget, {
73
+ from: e.target
74
+ });
75
+ let nextElem;
76
+ if (nextDir === "next") {
77
+ nextElem = walker.nextNode();
78
+ if (!nextElem) {
79
+ walker.currentNode = e.currentTarget;
80
+ nextElem = walker.firstChild();
81
+ }
82
+ } else {
83
+ nextElem = walker.previousNode();
84
+ if (!nextElem) {
85
+ walker.currentNode = e.currentTarget;
86
+ nextElem = walker.lastChild();
87
+ }
88
+ }
89
+ if (nextElem) {
90
+ // Call focus on nextElem so that keyboard navigation scrolls the radio into view
91
+ nextElem.focus();
92
+ state.setSelectedValue(nextElem.value);
93
+ }
94
+ };
95
+ let groupName = (0, $czmJy$useId)(name);
96
+ (0, $884aeceb3d67f00f$export$37b65e5b5444d35c).set(state, {
97
+ name: groupName,
98
+ descriptionId: descriptionProps.id,
99
+ errorMessageId: errorMessageProps.id,
100
+ validationBehavior: validationBehavior
101
+ });
102
+ return {
103
+ radioGroupProps: (0, $czmJy$mergeProps)(domProps, {
104
+ // https://www.w3.org/TR/wai-aria-1.2/#radiogroup
105
+ role: "radiogroup",
106
+ onKeyDown: onKeyDown,
107
+ "aria-invalid": state.isInvalid || undefined,
108
+ "aria-errormessage": props["aria-errormessage"],
109
+ "aria-readonly": isReadOnly || undefined,
110
+ "aria-required": isRequired || undefined,
111
+ "aria-disabled": isDisabled || undefined,
112
+ "aria-orientation": orientation,
113
+ ...fieldProps,
114
+ ...focusWithinProps
115
+ }),
116
+ labelProps: labelProps,
117
+ descriptionProps: descriptionProps,
118
+ errorMessageProps: errorMessageProps,
119
+ isInvalid: isInvalid,
120
+ validationErrors: validationErrors,
121
+ validationDetails: validationDetails
122
+ };
123
+ }
124
+
125
+
126
+ export {$430f30ed08ec25fa$export$62b9571f283ff5c2 as useRadioGroup};
127
+ //# sourceMappingURL=useRadioGroup.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AA6BM,SAAS,0CAAc,KAA0B,EAAE,KAAsB;IAC9E,IAAI,QACF,IAAI,cACJ,UAAU,cACV,UAAU,cACV,UAAU,eACV,cAAc,gCACd,qBAAqB,QACtB,GAAG;IACJ,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAE1B,IAAI,aAAC,SAAS,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,MAAM,iBAAiB;IAC9E,IAAI,cAAC,UAAU,cAAE,UAAU,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;QAC3E,GAAG,KAAK;QACR,iDAAiD;QACjD,6CAA6C;QAC7C,kBAAkB;QAClB,WAAW,MAAM,SAAS;QAC1B,cAAc,MAAM,YAAY,IAAI;IACtC;I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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/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 {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":"useRadioGroup.module.js.map"}
@@ -0,0 +1,20 @@
1
+
2
+ function $parcel$export(e, n, v, s) {
3
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
4
+ }
5
+
6
+ $parcel$export(module.exports, "radioGroupData", () => $eeb149278aae5c67$export$37b65e5b5444d35c);
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
+ */ const $eeb149278aae5c67$export$37b65e5b5444d35c = new WeakMap();
18
+
19
+
20
+ //# sourceMappingURL=utils.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GAWM,MAAM,4CAAiB,IAAI","sources":["packages/@react-aria/radio/src/utils.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\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"],"names":[],"version":3,"file":"utils.main.js.map"}
package/dist/utils.mjs ADDED
@@ -0,0 +1,15 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */ const $884aeceb3d67f00f$export$37b65e5b5444d35c = new WeakMap();
12
+
13
+
14
+ export {$884aeceb3d67f00f$export$37b65e5b5444d35c as radioGroupData};
15
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1,15 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */ const $884aeceb3d67f00f$export$37b65e5b5444d35c = new WeakMap();
12
+
13
+
14
+ export {$884aeceb3d67f00f$export$37b65e5b5444d35c as radioGroupData};
15
+ //# sourceMappingURL=utils.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAAA;;;;;;;;;;CAUC,GAWM,MAAM,4CAAiB,IAAI","sources":["packages/@react-aria/radio/src/utils.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\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"],"names":[],"version":3,"file":"utils.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/radio",
3
- "version": "3.10.2",
3
+ "version": "3.10.3",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,15 +22,15 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-aria/focus": "^3.16.2",
26
- "@react-aria/form": "^3.0.3",
27
- "@react-aria/i18n": "^3.10.2",
28
- "@react-aria/interactions": "^3.21.1",
29
- "@react-aria/label": "^3.7.6",
30
- "@react-aria/utils": "^3.23.2",
31
- "@react-stately/radio": "^3.10.2",
32
- "@react-types/radio": "^3.7.1",
33
- "@react-types/shared": "^3.22.1",
25
+ "@react-aria/focus": "^3.17.0",
26
+ "@react-aria/form": "^3.0.4",
27
+ "@react-aria/i18n": "^3.11.0",
28
+ "@react-aria/interactions": "^3.21.2",
29
+ "@react-aria/label": "^3.7.7",
30
+ "@react-aria/utils": "^3.24.0",
31
+ "@react-stately/radio": "^3.10.3",
32
+ "@react-types/radio": "^3.8.0",
33
+ "@react-types/shared": "^3.23.0",
34
34
  "@swc/helpers": "^0.5.0"
35
35
  },
36
36
  "peerDependencies": {
@@ -39,5 +39,5 @@
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
- "gitHead": "de9f84a22583fc741c29b341d14cd35ef4cca161"
42
+ "gitHead": "f645f29edc1322153fd60af4640cbcab1d992dbd"
43
43
  }