@react-aria/radio 3.7.0 → 3.8.1
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/import.mjs +13 -10
- package/dist/main.js +13 -10
- package/dist/main.js.map +1 -1
- package/dist/module.js +13 -10
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +10 -10
- package/src/useRadio.ts +9 -2
- package/src/useRadioGroup.ts +1 -2
package/dist/import.mjs
CHANGED
|
@@ -43,7 +43,7 @@ const $884aeceb3d67f00f$export$61c8d3f0151e21b2 = new WeakMap();
|
|
|
43
43
|
|
|
44
44
|
|
|
45
45
|
function $0d5c49892c1215da$export$37b0961d2f4751e2(props, state, ref) {
|
|
46
|
-
let { value: value
|
|
46
|
+
let { value: value, children: children, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby } = props;
|
|
47
47
|
const isDisabled = props.isDisabled || state.isDisabled;
|
|
48
48
|
let hasChildren = children != null;
|
|
49
49
|
let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;
|
|
@@ -53,17 +53,20 @@ function $0d5c49892c1215da$export$37b0961d2f4751e2(props, state, ref) {
|
|
|
53
53
|
e.stopPropagation();
|
|
54
54
|
state.setSelectedValue(value);
|
|
55
55
|
};
|
|
56
|
-
let { pressProps: pressProps
|
|
56
|
+
let { pressProps: pressProps, isPressed: isPressed } = (0, $4vDl6$usePress)({
|
|
57
57
|
isDisabled: isDisabled
|
|
58
58
|
});
|
|
59
|
-
let { focusableProps: focusableProps
|
|
59
|
+
let { focusableProps: focusableProps } = (0, $4vDl6$useFocusable)((0, $4vDl6$mergeProps)(props, {
|
|
60
60
|
onFocus: ()=>state.setLastFocusedValue(value)
|
|
61
61
|
}), ref);
|
|
62
62
|
let interactions = (0, $4vDl6$mergeProps)(pressProps, focusableProps);
|
|
63
63
|
let domProps = (0, $4vDl6$filterDOMProps)(props, {
|
|
64
64
|
labelable: true
|
|
65
65
|
});
|
|
66
|
-
let tabIndex =
|
|
66
|
+
let tabIndex = -1;
|
|
67
|
+
if (state.selectedValue != null) {
|
|
68
|
+
if (state.selectedValue === value) tabIndex = 0;
|
|
69
|
+
} else if (state.lastFocusedValue === value || state.lastFocusedValue == null) tabIndex = 0;
|
|
67
70
|
if (isDisabled) tabIndex = undefined;
|
|
68
71
|
(0, $4vDl6$useFormReset)(ref, state.selectedValue, state.setSelectedValue);
|
|
69
72
|
return {
|
|
@@ -78,7 +81,7 @@ function $0d5c49892c1215da$export$37b0961d2f4751e2(props, state, ref) {
|
|
|
78
81
|
onChange: onChange,
|
|
79
82
|
"aria-describedby": [
|
|
80
83
|
props["aria-describedby"],
|
|
81
|
-
state.
|
|
84
|
+
state.isInvalid ? (0, $884aeceb3d67f00f$export$61c8d3f0151e21b2).get(state) : null,
|
|
82
85
|
(0, $884aeceb3d67f00f$export$8e8b214e06dd397d).get(state)
|
|
83
86
|
].filter(Boolean).join(" ") || undefined
|
|
84
87
|
}),
|
|
@@ -106,9 +109,9 @@ function $0d5c49892c1215da$export$37b0961d2f4751e2(props, state, ref) {
|
|
|
106
109
|
|
|
107
110
|
|
|
108
111
|
function $430f30ed08ec25fa$export$62b9571f283ff5c2(props, state) {
|
|
109
|
-
let { name: name
|
|
110
|
-
let { direction: direction
|
|
111
|
-
let { labelProps: labelProps
|
|
112
|
+
let { name: name, isReadOnly: isReadOnly, isRequired: isRequired, isDisabled: isDisabled, orientation: orientation = "vertical" } = props;
|
|
113
|
+
let { direction: direction } = (0, $4vDl6$useLocale)();
|
|
114
|
+
let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $4vDl6$useField)({
|
|
112
115
|
...props,
|
|
113
116
|
// Radio group is not an HTML input element so it
|
|
114
117
|
// shouldn't be labeled by a <label> element.
|
|
@@ -122,7 +125,7 @@ function $430f30ed08ec25fa$export$62b9571f283ff5c2(props, state) {
|
|
|
122
125
|
// When the radio group loses focus, reset the focusable radio to null if
|
|
123
126
|
// there is no selection. This allows tabbing into the group from either
|
|
124
127
|
// direction to go to the first or last radio.
|
|
125
|
-
let { focusWithinProps: focusWithinProps
|
|
128
|
+
let { focusWithinProps: focusWithinProps } = (0, $4vDl6$useFocusWithin)({
|
|
126
129
|
onBlurWithin () {
|
|
127
130
|
if (!state.selectedValue) state.setLastFocusedValue(null);
|
|
128
131
|
}
|
|
@@ -178,7 +181,7 @@ function $430f30ed08ec25fa$export$62b9571f283ff5c2(props, state) {
|
|
|
178
181
|
// https://www.w3.org/TR/wai-aria-1.2/#radiogroup
|
|
179
182
|
role: "radiogroup",
|
|
180
183
|
onKeyDown: onKeyDown,
|
|
181
|
-
"aria-invalid":
|
|
184
|
+
"aria-invalid": state.isInvalid || undefined,
|
|
182
185
|
"aria-errormessage": props["aria-errormessage"],
|
|
183
186
|
"aria-readonly": isReadOnly || undefined,
|
|
184
187
|
"aria-required": isRequired || undefined,
|
package/dist/main.js
CHANGED
|
@@ -49,7 +49,7 @@ const $eeb149278aae5c67$export$61c8d3f0151e21b2 = new WeakMap();
|
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
function $e184702b1b7f1863$export$37b0961d2f4751e2(props, state, ref) {
|
|
52
|
-
let { value: value
|
|
52
|
+
let { value: value, children: children, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby } = props;
|
|
53
53
|
const isDisabled = props.isDisabled || state.isDisabled;
|
|
54
54
|
let hasChildren = children != null;
|
|
55
55
|
let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;
|
|
@@ -59,17 +59,20 @@ function $e184702b1b7f1863$export$37b0961d2f4751e2(props, state, ref) {
|
|
|
59
59
|
e.stopPropagation();
|
|
60
60
|
state.setSelectedValue(value);
|
|
61
61
|
};
|
|
62
|
-
let { pressProps: pressProps
|
|
62
|
+
let { pressProps: pressProps, isPressed: isPressed } = (0, $fMEGB$reactariainteractions.usePress)({
|
|
63
63
|
isDisabled: isDisabled
|
|
64
64
|
});
|
|
65
|
-
let { focusableProps: focusableProps
|
|
65
|
+
let { focusableProps: focusableProps } = (0, $fMEGB$reactariafocus.useFocusable)((0, $fMEGB$reactariautils.mergeProps)(props, {
|
|
66
66
|
onFocus: ()=>state.setLastFocusedValue(value)
|
|
67
67
|
}), ref);
|
|
68
68
|
let interactions = (0, $fMEGB$reactariautils.mergeProps)(pressProps, focusableProps);
|
|
69
69
|
let domProps = (0, $fMEGB$reactariautils.filterDOMProps)(props, {
|
|
70
70
|
labelable: true
|
|
71
71
|
});
|
|
72
|
-
let tabIndex =
|
|
72
|
+
let tabIndex = -1;
|
|
73
|
+
if (state.selectedValue != null) {
|
|
74
|
+
if (state.selectedValue === value) tabIndex = 0;
|
|
75
|
+
} else if (state.lastFocusedValue === value || state.lastFocusedValue == null) tabIndex = 0;
|
|
73
76
|
if (isDisabled) tabIndex = undefined;
|
|
74
77
|
(0, $fMEGB$reactariautils.useFormReset)(ref, state.selectedValue, state.setSelectedValue);
|
|
75
78
|
return {
|
|
@@ -84,7 +87,7 @@ function $e184702b1b7f1863$export$37b0961d2f4751e2(props, state, ref) {
|
|
|
84
87
|
onChange: onChange,
|
|
85
88
|
"aria-describedby": [
|
|
86
89
|
props["aria-describedby"],
|
|
87
|
-
state.
|
|
90
|
+
state.isInvalid ? (0, $eeb149278aae5c67$export$61c8d3f0151e21b2).get(state) : null,
|
|
88
91
|
(0, $eeb149278aae5c67$export$8e8b214e06dd397d).get(state)
|
|
89
92
|
].filter(Boolean).join(" ") || undefined
|
|
90
93
|
}),
|
|
@@ -112,9 +115,9 @@ function $e184702b1b7f1863$export$37b0961d2f4751e2(props, state, ref) {
|
|
|
112
115
|
|
|
113
116
|
|
|
114
117
|
function $dfcade00a56a6317$export$62b9571f283ff5c2(props, state) {
|
|
115
|
-
let { name: name
|
|
116
|
-
let { direction: direction
|
|
117
|
-
let { labelProps: labelProps
|
|
118
|
+
let { name: name, isReadOnly: isReadOnly, isRequired: isRequired, isDisabled: isDisabled, orientation: orientation = "vertical" } = props;
|
|
119
|
+
let { direction: direction } = (0, $fMEGB$reactariai18n.useLocale)();
|
|
120
|
+
let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $fMEGB$reactarialabel.useField)({
|
|
118
121
|
...props,
|
|
119
122
|
// Radio group is not an HTML input element so it
|
|
120
123
|
// shouldn't be labeled by a <label> element.
|
|
@@ -128,7 +131,7 @@ function $dfcade00a56a6317$export$62b9571f283ff5c2(props, state) {
|
|
|
128
131
|
// When the radio group loses focus, reset the focusable radio to null if
|
|
129
132
|
// there is no selection. This allows tabbing into the group from either
|
|
130
133
|
// direction to go to the first or last radio.
|
|
131
|
-
let { focusWithinProps: focusWithinProps
|
|
134
|
+
let { focusWithinProps: focusWithinProps } = (0, $fMEGB$reactariainteractions.useFocusWithin)({
|
|
132
135
|
onBlurWithin () {
|
|
133
136
|
if (!state.selectedValue) state.setLastFocusedValue(null);
|
|
134
137
|
}
|
|
@@ -184,7 +187,7 @@ function $dfcade00a56a6317$export$62b9571f283ff5c2(props, state) {
|
|
|
184
187
|
// https://www.w3.org/TR/wai-aria-1.2/#radiogroup
|
|
185
188
|
role: "radiogroup",
|
|
186
189
|
onKeyDown: onKeyDown,
|
|
187
|
-
"aria-invalid":
|
|
190
|
+
"aria-invalid": state.isInvalid || undefined,
|
|
188
191
|
"aria-errormessage": props["aria-errormessage"],
|
|
189
192
|
"aria-readonly": isReadOnly || undefined,
|
|
190
193
|
"aria-required": isRequired || undefined,
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;ACVD;;;;;;;;;;CAUC,GAIM,MAAM,4CAAkB,IAAI;AAC5B,MAAM,4CAA2B,IAAI;AACrC,MAAM,4CAA4B,IAAI;;;;;ADsBtC,SAAS,0CAAS,KAAqB,EAAE,KAAsB,EAAE,GAAgC;IACtG,IAAI,SACF,MAAK,YACL,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AI,CAAC,UAAU;gBACb,OAAO,cAAc,EAAE;gBACvB,WAAW,OAAO;YACpB;QACF;QACA,IAAI,UAAU;YACZ,iFAAiF;YACjF,SAAS;YACT,MAAM,iBAAiB,SAAS;QAClC;IACF;IAEA,IAAI,YAAY,CAAA,GAAA,2BAAI,EAAE;IACtB,CAAA,GAAA,yCAAc,EAAE,IAAI,OAAO;IAE3B,OAAO;QACL,iBAAiB,CAAA,GAAA,gCAAS,EAAE,UAAU;YACpC,iDAAiD;YACjD,MAAM;uBACN;YACA,gBAAgB,oBAAoB,aAAa;YACjD,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;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, RefObject} from 'react';\nimport {radioGroupDescriptionIds, radioGroupErrorMessageIds, radioGroupNames} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useFocusable} from '@react-aria/focus';\nimport {usePress} from '@react-aria/interactions';\n\nexport interface RadioAria {\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 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 useFormReset(ref, state.selectedValue, state.setSelectedValue);\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 'aria-describedby': [\n props['aria-describedby'],\n state.validationState === 'invalid' ? radioGroupErrorMessageIds.get(state) : null,\n radioGroupDescriptionIds.get(state)\n ].filter(Boolean).join(' ') || undefined\n }),\n isDisabled,\n isSelected: checked,\n isPressed\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\nexport const radioGroupNames = new WeakMap<RadioGroupState, string>();\nexport const radioGroupDescriptionIds = new WeakMap<RadioGroupState, string>();\nexport const radioGroupErrorMessageIds = 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 {AriaRadioGroupProps} from '@react-types/radio';\nimport {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps, useId} from '@react-aria/utils';\nimport {getFocusableTreeWalker} from '@react-aria/focus';\nimport {radioGroupDescriptionIds, radioGroupErrorMessageIds, radioGroupNames} 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 {\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 validationState,\n isReadOnly,\n isRequired,\n isDisabled,\n orientation = 'vertical'\n } = props;\n let {direction} = useLocale();\n\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 });\n radioGroupDescriptionIds.set(state, descriptionProps.id);\n radioGroupErrorMessageIds.set(state, errorMessageProps.id);\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 descriptionProps,\n errorMessageProps\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;ACVD;;;;;;;;;;CAUC,GAIM,MAAM,4CAAkB,IAAI;AAC5B,MAAM,4CAA2B,IAAI;AACrC,MAAM,4CAA4B,IAAI;;;;;ADsBtC,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,cAAc,MAAM;IAE7C,IAAI,cAAc,YAAY;IAC9B,IAAI,eAAe,aAAa,QAAQ,kBAAkB;IAC1D,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jF,SAAS;YACT,MAAM,iBAAiB,SAAS;QAClC;IACF;IAEA,IAAI,YAAY,CAAA,GAAA,2BAAI,EAAE;IACtB,CAAA,GAAA,yCAAc,EAAE,IAAI,OAAO;IAE3B,OAAO;QACL,iBAAiB,CAAA,GAAA,gCAAS,EAAE,UAAU;YACpC,iDAAiD;YACjD,MAAM;uBACN;YACA,gBAAgB,MAAM,aAAa;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;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, RefObject} from 'react';\nimport {radioGroupDescriptionIds, radioGroupErrorMessageIds, radioGroupNames} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useFocusable} from '@react-aria/focus';\nimport {usePress} from '@react-aria/interactions';\n\nexport interface RadioAria {\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 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 = -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 useFormReset(ref, state.selectedValue, state.setSelectedValue);\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 'aria-describedby': [\n props['aria-describedby'],\n state.isInvalid ? radioGroupErrorMessageIds.get(state) : null,\n radioGroupDescriptionIds.get(state)\n ].filter(Boolean).join(' ') || undefined\n }),\n isDisabled,\n isSelected: checked,\n isPressed\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\nexport const radioGroupNames = new WeakMap<RadioGroupState, string>();\nexport const radioGroupDescriptionIds = new WeakMap<RadioGroupState, string>();\nexport const radioGroupErrorMessageIds = 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 {AriaRadioGroupProps} from '@react-types/radio';\nimport {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps, useId} from '@react-aria/utils';\nimport {getFocusableTreeWalker} from '@react-aria/focus';\nimport {radioGroupDescriptionIds, radioGroupErrorMessageIds, radioGroupNames} 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 {\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 } = props;\n let {direction} = useLocale();\n\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 });\n radioGroupDescriptionIds.set(state, descriptionProps.id);\n radioGroupErrorMessageIds.set(state, errorMessageProps.id);\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': 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 };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -43,7 +43,7 @@ const $884aeceb3d67f00f$export$61c8d3f0151e21b2 = new WeakMap();
|
|
|
43
43
|
|
|
44
44
|
|
|
45
45
|
function $0d5c49892c1215da$export$37b0961d2f4751e2(props, state, ref) {
|
|
46
|
-
let { value: value
|
|
46
|
+
let { value: value, children: children, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby } = props;
|
|
47
47
|
const isDisabled = props.isDisabled || state.isDisabled;
|
|
48
48
|
let hasChildren = children != null;
|
|
49
49
|
let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;
|
|
@@ -53,17 +53,20 @@ function $0d5c49892c1215da$export$37b0961d2f4751e2(props, state, ref) {
|
|
|
53
53
|
e.stopPropagation();
|
|
54
54
|
state.setSelectedValue(value);
|
|
55
55
|
};
|
|
56
|
-
let { pressProps: pressProps
|
|
56
|
+
let { pressProps: pressProps, isPressed: isPressed } = (0, $4vDl6$usePress)({
|
|
57
57
|
isDisabled: isDisabled
|
|
58
58
|
});
|
|
59
|
-
let { focusableProps: focusableProps
|
|
59
|
+
let { focusableProps: focusableProps } = (0, $4vDl6$useFocusable)((0, $4vDl6$mergeProps)(props, {
|
|
60
60
|
onFocus: ()=>state.setLastFocusedValue(value)
|
|
61
61
|
}), ref);
|
|
62
62
|
let interactions = (0, $4vDl6$mergeProps)(pressProps, focusableProps);
|
|
63
63
|
let domProps = (0, $4vDl6$filterDOMProps)(props, {
|
|
64
64
|
labelable: true
|
|
65
65
|
});
|
|
66
|
-
let tabIndex =
|
|
66
|
+
let tabIndex = -1;
|
|
67
|
+
if (state.selectedValue != null) {
|
|
68
|
+
if (state.selectedValue === value) tabIndex = 0;
|
|
69
|
+
} else if (state.lastFocusedValue === value || state.lastFocusedValue == null) tabIndex = 0;
|
|
67
70
|
if (isDisabled) tabIndex = undefined;
|
|
68
71
|
(0, $4vDl6$useFormReset)(ref, state.selectedValue, state.setSelectedValue);
|
|
69
72
|
return {
|
|
@@ -78,7 +81,7 @@ function $0d5c49892c1215da$export$37b0961d2f4751e2(props, state, ref) {
|
|
|
78
81
|
onChange: onChange,
|
|
79
82
|
"aria-describedby": [
|
|
80
83
|
props["aria-describedby"],
|
|
81
|
-
state.
|
|
84
|
+
state.isInvalid ? (0, $884aeceb3d67f00f$export$61c8d3f0151e21b2).get(state) : null,
|
|
82
85
|
(0, $884aeceb3d67f00f$export$8e8b214e06dd397d).get(state)
|
|
83
86
|
].filter(Boolean).join(" ") || undefined
|
|
84
87
|
}),
|
|
@@ -106,9 +109,9 @@ function $0d5c49892c1215da$export$37b0961d2f4751e2(props, state, ref) {
|
|
|
106
109
|
|
|
107
110
|
|
|
108
111
|
function $430f30ed08ec25fa$export$62b9571f283ff5c2(props, state) {
|
|
109
|
-
let { name: name
|
|
110
|
-
let { direction: direction
|
|
111
|
-
let { labelProps: labelProps
|
|
112
|
+
let { name: name, isReadOnly: isReadOnly, isRequired: isRequired, isDisabled: isDisabled, orientation: orientation = "vertical" } = props;
|
|
113
|
+
let { direction: direction } = (0, $4vDl6$useLocale)();
|
|
114
|
+
let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $4vDl6$useField)({
|
|
112
115
|
...props,
|
|
113
116
|
// Radio group is not an HTML input element so it
|
|
114
117
|
// shouldn't be labeled by a <label> element.
|
|
@@ -122,7 +125,7 @@ function $430f30ed08ec25fa$export$62b9571f283ff5c2(props, state) {
|
|
|
122
125
|
// When the radio group loses focus, reset the focusable radio to null if
|
|
123
126
|
// there is no selection. This allows tabbing into the group from either
|
|
124
127
|
// direction to go to the first or last radio.
|
|
125
|
-
let { focusWithinProps: focusWithinProps
|
|
128
|
+
let { focusWithinProps: focusWithinProps } = (0, $4vDl6$useFocusWithin)({
|
|
126
129
|
onBlurWithin () {
|
|
127
130
|
if (!state.selectedValue) state.setLastFocusedValue(null);
|
|
128
131
|
}
|
|
@@ -178,7 +181,7 @@ function $430f30ed08ec25fa$export$62b9571f283ff5c2(props, state) {
|
|
|
178
181
|
// https://www.w3.org/TR/wai-aria-1.2/#radiogroup
|
|
179
182
|
role: "radiogroup",
|
|
180
183
|
onKeyDown: onKeyDown,
|
|
181
|
-
"aria-invalid":
|
|
184
|
+
"aria-invalid": state.isInvalid || undefined,
|
|
182
185
|
"aria-errormessage": props["aria-errormessage"],
|
|
183
186
|
"aria-readonly": isReadOnly || undefined,
|
|
184
187
|
"aria-required": isRequired || undefined,
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;ACVD;;;;;;;;;;CAUC,GAIM,MAAM,4CAAkB,IAAI;AAC5B,MAAM,4CAA2B,IAAI;AACrC,MAAM,4C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CAAC,UAAU;gBACb,OAAO,cAAc,EAAE;gBACvB,WAAW,OAAO;YACpB;QACF,OAAO;YACL,WAAW,OAAO;YAClB,IAAI,CAAC,UAAU;gBACb,OAAO,cAAc,EAAE;gBACvB,WAAW,OAAO;YACpB;QACF;QACA,IAAI,UAAU;YACZ,iFAAiF;YACjF,SAAS;YACT,MAAM,iBAAiB,SAAS;QAClC;IACF;IAEA,IAAI,YAAY,CAAA,GAAA,YAAI,EAAE;IACtB,CAAA,GAAA,yCAAc,EAAE,IAAI,OAAO;IAE3B,OAAO;QACL,iBAAiB,CAAA,GAAA,iBAAS,EAAE,UAAU;YACpC,iDAAiD;YACjD,MAAM;uBACN;YACA,gBAAgB,oBAAoB,aAAa;YACjD,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;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, RefObject} from 'react';\nimport {radioGroupDescriptionIds, radioGroupErrorMessageIds, radioGroupNames} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useFocusable} from '@react-aria/focus';\nimport {usePress} from '@react-aria/interactions';\n\nexport interface RadioAria {\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 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 useFormReset(ref, state.selectedValue, state.setSelectedValue);\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 'aria-describedby': [\n props['aria-describedby'],\n state.validationState === 'invalid' ? radioGroupErrorMessageIds.get(state) : null,\n radioGroupDescriptionIds.get(state)\n ].filter(Boolean).join(' ') || undefined\n }),\n isDisabled,\n isSelected: checked,\n isPressed\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\nexport const radioGroupNames = new WeakMap<RadioGroupState, string>();\nexport const radioGroupDescriptionIds = new WeakMap<RadioGroupState, string>();\nexport const radioGroupErrorMessageIds = 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 {AriaRadioGroupProps} from '@react-types/radio';\nimport {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps, useId} from '@react-aria/utils';\nimport {getFocusableTreeWalker} from '@react-aria/focus';\nimport {radioGroupDescriptionIds, radioGroupErrorMessageIds, radioGroupNames} 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 {\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 validationState,\n isReadOnly,\n isRequired,\n isDisabled,\n orientation = 'vertical'\n } = props;\n let {direction} = useLocale();\n\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 });\n radioGroupDescriptionIds.set(state, descriptionProps.id);\n radioGroupErrorMessageIds.set(state, errorMessageProps.id);\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 descriptionProps,\n errorMessageProps\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;ACVD;;;;;;;;;;CAUC,GAIM,MAAM,4CAAkB,IAAI;AAC5B,MAAM,4CAA2B,IAAI;AACrC,MAAM,4CAA4B,IAAI;;;;;ADsBtC,SAAS,0CAAS,KAAqB,EAAE,KAAsB,EAAE,GAAgC;IACtG,IAAI,SACF,KAAK,YACL,QAAQ,EACR,cAAc,SAAS,EACvB,mBAAmB,cAAc,EAClC,GAAG;IAEJ,MAAM,aAAa,MA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BACb,OAAO,cAAc,EAAE;gBACvB,WAAW,OAAO;YACpB;QACF;QACA,IAAI,UAAU;YACZ,iFAAiF;YACjF,SAAS;YACT,MAAM,iBAAiB,SAAS;QAClC;IACF;IAEA,IAAI,YAAY,CAAA,GAAA,YAAI,EAAE;IACtB,CAAA,GAAA,yCAAc,EAAE,IAAI,OAAO;IAE3B,OAAO;QACL,iBAAiB,CAAA,GAAA,iBAAS,EAAE,UAAU;YACpC,iDAAiD;YACjD,MAAM;uBACN;YACA,gBAAgB,MAAM,aAAa;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;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, RefObject} from 'react';\nimport {radioGroupDescriptionIds, radioGroupErrorMessageIds, radioGroupNames} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useFocusable} from '@react-aria/focus';\nimport {usePress} from '@react-aria/interactions';\n\nexport interface RadioAria {\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 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 = -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 useFormReset(ref, state.selectedValue, state.setSelectedValue);\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 'aria-describedby': [\n props['aria-describedby'],\n state.isInvalid ? radioGroupErrorMessageIds.get(state) : null,\n radioGroupDescriptionIds.get(state)\n ].filter(Boolean).join(' ') || undefined\n }),\n isDisabled,\n isSelected: checked,\n isPressed\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\nexport const radioGroupNames = new WeakMap<RadioGroupState, string>();\nexport const radioGroupDescriptionIds = new WeakMap<RadioGroupState, string>();\nexport const radioGroupErrorMessageIds = 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 {AriaRadioGroupProps} from '@react-types/radio';\nimport {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps, useId} from '@react-aria/utils';\nimport {getFocusableTreeWalker} from '@react-aria/focus';\nimport {radioGroupDescriptionIds, radioGroupErrorMessageIds, radioGroupNames} 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 {\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 } = props;\n let {direction} = useLocale();\n\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 });\n radioGroupDescriptionIds.set(state, descriptionProps.id);\n radioGroupErrorMessageIds.set(state, errorMessageProps.id);\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': 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 };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;ACoBA;IACE,mCAAmC;IACnC,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAClD,qCAAqC;IACrC,UAAU,EAAE,OAAO,CAAC;IACpB,+CAA+C;IAC/C,UAAU,EAAE,OAAO,CAAC;IACpB,+CAA+C;IAC/C,SAAS,EAAE,OAAO,CAAA;CACnB;AAED;;;;;;GAMG;AACH,yBAAyB,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,UAAU,gBAAgB,CAAC,GAAG,SAAS,
|
|
1
|
+
{"mappings":";;;;ACoBA;IACE,mCAAmC;IACnC,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAClD,qCAAqC;IACrC,UAAU,EAAE,OAAO,CAAC;IACpB,+CAA+C;IAC/C,UAAU,EAAE,OAAO,CAAC;IACpB,+CAA+C;IAC/C,SAAS,EAAE,OAAO,CAAA;CACnB;AAED;;;;;;GAMG;AACH,yBAAyB,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,UAAU,gBAAgB,CAAC,GAAG,SAAS,CAkEnH;AClFD;IACE,iDAAiD;IACjD,eAAe,EAAE,aAAa,CAAC;IAC/B,0DAA0D;IAC1D,UAAU,EAAE,aAAa,CAAC;IAC1B,6DAA6D;IAC7D,gBAAgB,EAAE,aAAa,CAAC;IAChC,+DAA+D;IAC/D,iBAAiB,EAAE,aAAa,CAAA;CACjC;AAED;;;;;GAKG;AACH,8BAA8B,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,eAAe,GAAG,cAAc,CAsGhG;AChID,YAAY,EAAC,mBAAmB,EAAE,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAC5E,YAAY,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAC","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","packages/@react-aria/radio/src/index.ts"],"sourcesContent":[null,null,null,null,"/*\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":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/radio",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.1",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-aria/focus": "^3.14.
|
|
26
|
-
"@react-aria/i18n": "^3.8.
|
|
27
|
-
"@react-aria/interactions": "^3.
|
|
28
|
-
"@react-aria/label": "^3.
|
|
29
|
-
"@react-aria/utils": "^3.
|
|
30
|
-
"@react-stately/radio": "^3.
|
|
31
|
-
"@react-types/radio": "^3.5.
|
|
32
|
-
"@react-types/shared": "^3.
|
|
25
|
+
"@react-aria/focus": "^3.14.2",
|
|
26
|
+
"@react-aria/i18n": "^3.8.3",
|
|
27
|
+
"@react-aria/interactions": "^3.19.0",
|
|
28
|
+
"@react-aria/label": "^3.7.1",
|
|
29
|
+
"@react-aria/utils": "^3.21.0",
|
|
30
|
+
"@react-stately/radio": "^3.9.1",
|
|
31
|
+
"@react-types/radio": "^3.5.2",
|
|
32
|
+
"@react-types/shared": "^3.21.0",
|
|
33
33
|
"@swc/helpers": "^0.5.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "4122e44d1991c90507d630d35ed297f89db435d3"
|
|
42
42
|
}
|
package/src/useRadio.ts
CHANGED
|
@@ -68,7 +68,14 @@ export function useRadio(props: AriaRadioProps, state: RadioGroupState, ref: Ref
|
|
|
68
68
|
}), ref);
|
|
69
69
|
let interactions = mergeProps(pressProps, focusableProps);
|
|
70
70
|
let domProps = filterDOMProps(props, {labelable: true});
|
|
71
|
-
let tabIndex =
|
|
71
|
+
let tabIndex = -1;
|
|
72
|
+
if (state.selectedValue != null) {
|
|
73
|
+
if (state.selectedValue === value) {
|
|
74
|
+
tabIndex = 0;
|
|
75
|
+
}
|
|
76
|
+
} else if (state.lastFocusedValue === value || state.lastFocusedValue == null) {
|
|
77
|
+
tabIndex = 0;
|
|
78
|
+
}
|
|
72
79
|
if (isDisabled) {
|
|
73
80
|
tabIndex = undefined;
|
|
74
81
|
}
|
|
@@ -87,7 +94,7 @@ export function useRadio(props: AriaRadioProps, state: RadioGroupState, ref: Ref
|
|
|
87
94
|
onChange,
|
|
88
95
|
'aria-describedby': [
|
|
89
96
|
props['aria-describedby'],
|
|
90
|
-
state.
|
|
97
|
+
state.isInvalid ? radioGroupErrorMessageIds.get(state) : null,
|
|
91
98
|
radioGroupDescriptionIds.get(state)
|
|
92
99
|
].filter(Boolean).join(' ') || undefined
|
|
93
100
|
}),
|
package/src/useRadioGroup.ts
CHANGED
|
@@ -40,7 +40,6 @@ export interface RadioGroupAria {
|
|
|
40
40
|
export function useRadioGroup(props: AriaRadioGroupProps, state: RadioGroupState): RadioGroupAria {
|
|
41
41
|
let {
|
|
42
42
|
name,
|
|
43
|
-
validationState,
|
|
44
43
|
isReadOnly,
|
|
45
44
|
isRequired,
|
|
46
45
|
isDisabled,
|
|
@@ -127,7 +126,7 @@ export function useRadioGroup(props: AriaRadioGroupProps, state: RadioGroupState
|
|
|
127
126
|
// https://www.w3.org/TR/wai-aria-1.2/#radiogroup
|
|
128
127
|
role: 'radiogroup',
|
|
129
128
|
onKeyDown,
|
|
130
|
-
'aria-invalid':
|
|
129
|
+
'aria-invalid': state.isInvalid || undefined,
|
|
131
130
|
'aria-errormessage': props['aria-errormessage'],
|
|
132
131
|
'aria-readonly': isReadOnly || undefined,
|
|
133
132
|
'aria-required': isRequired || undefined,
|