@react-aria/radio 3.8.2 → 3.9.0

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 CHANGED
@@ -1,5 +1,6 @@
1
1
  import {mergeProps as $4vDl6$mergeProps, filterDOMProps as $4vDl6$filterDOMProps, useFormReset as $4vDl6$useFormReset, useId as $4vDl6$useId} from "@react-aria/utils";
2
2
  import {useFocusable as $4vDl6$useFocusable, getFocusableTreeWalker as $4vDl6$getFocusableTreeWalker} from "@react-aria/focus";
3
+ import {useFormValidation as $4vDl6$useFormValidation} from "@react-aria/form";
3
4
  import {usePress as $4vDl6$usePress, useFocusWithin as $4vDl6$useFocusWithin} from "@react-aria/interactions";
4
5
  import {useField as $4vDl6$useField} from "@react-aria/label";
5
6
  import {useLocale as $4vDl6$useLocale} from "@react-aria/i18n";
@@ -35,9 +36,8 @@ import {useLocale as $4vDl6$useLocale} from "@react-aria/i18n";
35
36
  * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
36
37
  * OF ANY KIND, either express or implied. See the License for the specific language
37
38
  * governing permissions and limitations under the License.
38
- */ const $884aeceb3d67f00f$export$3b7b268d09480394 = new WeakMap();
39
- const $884aeceb3d67f00f$export$8e8b214e06dd397d = new WeakMap();
40
- const $884aeceb3d67f00f$export$61c8d3f0151e21b2 = new WeakMap();
39
+ */ const $884aeceb3d67f00f$export$37b65e5b5444d35c = new WeakMap();
40
+
41
41
 
42
42
 
43
43
 
@@ -68,21 +68,26 @@ function $0d5c49892c1215da$export$37b0961d2f4751e2(props, state, ref) {
68
68
  if (state.selectedValue === value) tabIndex = 0;
69
69
  } else if (state.lastFocusedValue === value || state.lastFocusedValue == null) tabIndex = 0;
70
70
  if (isDisabled) tabIndex = undefined;
71
+ let { name: name, descriptionId: descriptionId, errorMessageId: errorMessageId, validationBehavior: validationBehavior } = (0, $884aeceb3d67f00f$export$37b65e5b5444d35c).get(state);
71
72
  (0, $4vDl6$useFormReset)(ref, state.selectedValue, state.setSelectedValue);
73
+ (0, $4vDl6$useFormValidation)({
74
+ validationBehavior: validationBehavior
75
+ }, state, ref);
72
76
  return {
73
77
  inputProps: (0, $4vDl6$mergeProps)(domProps, {
74
78
  ...interactions,
75
79
  type: "radio",
76
- name: (0, $884aeceb3d67f00f$export$3b7b268d09480394).get(state),
80
+ name: name,
77
81
  tabIndex: tabIndex,
78
82
  disabled: isDisabled,
83
+ required: state.isRequired && validationBehavior === "native",
79
84
  checked: checked,
80
85
  value: value,
81
86
  onChange: onChange,
82
87
  "aria-describedby": [
83
88
  props["aria-describedby"],
84
- state.isInvalid ? (0, $884aeceb3d67f00f$export$61c8d3f0151e21b2).get(state) : null,
85
- (0, $884aeceb3d67f00f$export$8e8b214e06dd397d).get(state)
89
+ state.isInvalid ? errorMessageId : null,
90
+ descriptionId
86
91
  ].filter(Boolean).join(" ") || undefined
87
92
  }),
88
93
  isDisabled: isDisabled,
@@ -109,16 +114,17 @@ function $0d5c49892c1215da$export$37b0961d2f4751e2(props, state, ref) {
109
114
 
110
115
 
111
116
  function $430f30ed08ec25fa$export$62b9571f283ff5c2(props, state) {
112
- let { name: name, isReadOnly: isReadOnly, isRequired: isRequired, isDisabled: isDisabled, orientation: orientation = "vertical" } = props;
117
+ let { name: name, isReadOnly: isReadOnly, isRequired: isRequired, isDisabled: isDisabled, orientation: orientation = "vertical", validationBehavior: validationBehavior = "aria" } = props;
113
118
  let { direction: direction } = (0, $4vDl6$useLocale)();
119
+ let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
114
120
  let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $4vDl6$useField)({
115
121
  ...props,
116
122
  // Radio group is not an HTML input element so it
117
123
  // shouldn't be labeled by a <label> element.
118
- labelElementType: "span"
124
+ labelElementType: "span",
125
+ isInvalid: state.isInvalid,
126
+ errorMessage: props.errorMessage || validationErrors
119
127
  });
120
- (0, $884aeceb3d67f00f$export$8e8b214e06dd397d).set(state, descriptionProps.id);
121
- (0, $884aeceb3d67f00f$export$61c8d3f0151e21b2).set(state, errorMessageProps.id);
122
128
  let domProps = (0, $4vDl6$filterDOMProps)(props, {
123
129
  labelable: true
124
130
  });
@@ -175,7 +181,12 @@ function $430f30ed08ec25fa$export$62b9571f283ff5c2(props, state) {
175
181
  }
176
182
  };
177
183
  let groupName = (0, $4vDl6$useId)(name);
178
- (0, $884aeceb3d67f00f$export$3b7b268d09480394).set(state, groupName);
184
+ (0, $884aeceb3d67f00f$export$37b65e5b5444d35c).set(state, {
185
+ name: groupName,
186
+ descriptionId: descriptionProps.id,
187
+ errorMessageId: errorMessageProps.id,
188
+ validationBehavior: validationBehavior
189
+ });
179
190
  return {
180
191
  radioGroupProps: (0, $4vDl6$mergeProps)(domProps, {
181
192
  // https://www.w3.org/TR/wai-aria-1.2/#radiogroup
@@ -192,7 +203,10 @@ function $430f30ed08ec25fa$export$62b9571f283ff5c2(props, state) {
192
203
  }),
193
204
  labelProps: labelProps,
194
205
  descriptionProps: descriptionProps,
195
- errorMessageProps: errorMessageProps
206
+ errorMessageProps: errorMessageProps,
207
+ isInvalid: isInvalid,
208
+ validationErrors: validationErrors,
209
+ validationDetails: validationDetails
196
210
  };
197
211
  }
198
212
 
package/dist/main.js CHANGED
@@ -1,9 +1,11 @@
1
1
  var $fMEGB$reactariautils = require("@react-aria/utils");
2
2
  var $fMEGB$reactariafocus = require("@react-aria/focus");
3
+ var $fMEGB$reactariaform = require("@react-aria/form");
3
4
  var $fMEGB$reactariainteractions = require("@react-aria/interactions");
4
5
  var $fMEGB$reactarialabel = require("@react-aria/label");
5
6
  var $fMEGB$reactariai18n = require("@react-aria/i18n");
6
7
 
8
+
7
9
  function $parcel$export(e, n, v, s) {
8
10
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
9
11
  }
@@ -41,9 +43,8 @@ $parcel$export(module.exports, "useRadioGroup", () => $dfcade00a56a6317$export$6
41
43
  * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
42
44
  * OF ANY KIND, either express or implied. See the License for the specific language
43
45
  * governing permissions and limitations under the License.
44
- */ const $eeb149278aae5c67$export$3b7b268d09480394 = new WeakMap();
45
- const $eeb149278aae5c67$export$8e8b214e06dd397d = new WeakMap();
46
- const $eeb149278aae5c67$export$61c8d3f0151e21b2 = new WeakMap();
46
+ */ const $eeb149278aae5c67$export$37b65e5b5444d35c = new WeakMap();
47
+
47
48
 
48
49
 
49
50
 
@@ -74,21 +75,26 @@ function $e184702b1b7f1863$export$37b0961d2f4751e2(props, state, ref) {
74
75
  if (state.selectedValue === value) tabIndex = 0;
75
76
  } else if (state.lastFocusedValue === value || state.lastFocusedValue == null) tabIndex = 0;
76
77
  if (isDisabled) tabIndex = undefined;
78
+ let { name: name, descriptionId: descriptionId, errorMessageId: errorMessageId, validationBehavior: validationBehavior } = (0, $eeb149278aae5c67$export$37b65e5b5444d35c).get(state);
77
79
  (0, $fMEGB$reactariautils.useFormReset)(ref, state.selectedValue, state.setSelectedValue);
80
+ (0, $fMEGB$reactariaform.useFormValidation)({
81
+ validationBehavior: validationBehavior
82
+ }, state, ref);
78
83
  return {
79
84
  inputProps: (0, $fMEGB$reactariautils.mergeProps)(domProps, {
80
85
  ...interactions,
81
86
  type: "radio",
82
- name: (0, $eeb149278aae5c67$export$3b7b268d09480394).get(state),
87
+ name: name,
83
88
  tabIndex: tabIndex,
84
89
  disabled: isDisabled,
90
+ required: state.isRequired && validationBehavior === "native",
85
91
  checked: checked,
86
92
  value: value,
87
93
  onChange: onChange,
88
94
  "aria-describedby": [
89
95
  props["aria-describedby"],
90
- state.isInvalid ? (0, $eeb149278aae5c67$export$61c8d3f0151e21b2).get(state) : null,
91
- (0, $eeb149278aae5c67$export$8e8b214e06dd397d).get(state)
96
+ state.isInvalid ? errorMessageId : null,
97
+ descriptionId
92
98
  ].filter(Boolean).join(" ") || undefined
93
99
  }),
94
100
  isDisabled: isDisabled,
@@ -115,16 +121,17 @@ function $e184702b1b7f1863$export$37b0961d2f4751e2(props, state, ref) {
115
121
 
116
122
 
117
123
  function $dfcade00a56a6317$export$62b9571f283ff5c2(props, state) {
118
- let { name: name, isReadOnly: isReadOnly, isRequired: isRequired, isDisabled: isDisabled, orientation: orientation = "vertical" } = props;
124
+ let { name: name, isReadOnly: isReadOnly, isRequired: isRequired, isDisabled: isDisabled, orientation: orientation = "vertical", validationBehavior: validationBehavior = "aria" } = props;
119
125
  let { direction: direction } = (0, $fMEGB$reactariai18n.useLocale)();
126
+ let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
120
127
  let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $fMEGB$reactarialabel.useField)({
121
128
  ...props,
122
129
  // Radio group is not an HTML input element so it
123
130
  // shouldn't be labeled by a <label> element.
124
- labelElementType: "span"
131
+ labelElementType: "span",
132
+ isInvalid: state.isInvalid,
133
+ errorMessage: props.errorMessage || validationErrors
125
134
  });
126
- (0, $eeb149278aae5c67$export$8e8b214e06dd397d).set(state, descriptionProps.id);
127
- (0, $eeb149278aae5c67$export$61c8d3f0151e21b2).set(state, errorMessageProps.id);
128
135
  let domProps = (0, $fMEGB$reactariautils.filterDOMProps)(props, {
129
136
  labelable: true
130
137
  });
@@ -181,7 +188,12 @@ function $dfcade00a56a6317$export$62b9571f283ff5c2(props, state) {
181
188
  }
182
189
  };
183
190
  let groupName = (0, $fMEGB$reactariautils.useId)(name);
184
- (0, $eeb149278aae5c67$export$3b7b268d09480394).set(state, groupName);
191
+ (0, $eeb149278aae5c67$export$37b65e5b5444d35c).set(state, {
192
+ name: groupName,
193
+ descriptionId: descriptionProps.id,
194
+ errorMessageId: errorMessageProps.id,
195
+ validationBehavior: validationBehavior
196
+ });
185
197
  return {
186
198
  radioGroupProps: (0, $fMEGB$reactariautils.mergeProps)(domProps, {
187
199
  // https://www.w3.org/TR/wai-aria-1.2/#radiogroup
@@ -198,7 +210,10 @@ function $dfcade00a56a6317$export$62b9571f283ff5c2(props, state) {
198
210
  }),
199
211
  labelProps: labelProps,
200
212
  descriptionProps: descriptionProps,
201
- errorMessageProps: errorMessageProps
213
+ errorMessageProps: errorMessageProps,
214
+ isInvalid: isInvalid,
215
+ validationErrors: validationErrors,
216
+ validationDetails: validationDetails
202
217
  };
203
218
  }
204
219
 
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,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,IAAI,CAAC,eAAe,CAAC,cACnB,QAAQ,KAAK;IAGf,IAAI,UAAU,MAAM,kBAAkB;IAEtC,IAAI,WAAW,CAAC;QACd,EAAE;QACF,MAAM,iBAAiB;IACzB;IAEA,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,qCAAO,EAAE;oBACrC;IACF;IAEA,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,kCAAW,EAAE,CAAA,GAAA,gCAAS,EAAE,OAAO;QACpD,SAAS,IAAM,MAAM,oBAAoB;IAC3C,IAAI;IACJ,IAAI,eAAe,CAAA,GAAA,gCAAS,EAAE,YAAY;IAC1C,IAAI,WAAW,CAAA,GAAA,oCAAa,EAAE,OAAO;QAAC,WAAW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/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"}
1
+ {"mappings":";;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;ACVD;;;;;;;;;;CAUC,GAWM,MAAM,4CAAiB,IAAI;;;;;;ADkB3B,SAAS,0CAAS,KAAqB,EAAE,KAAsB,EAAE,GAAgC;IACtG,IAAI,SACF,KAAK,YACL,QAAQ,EACR,cAAc,SAAS,EACvB,mBAAmB,cAAc,EAClC,GAAG;IAEJ,MAAM,aAAa,MAAM,UAAU,IAAI,MAAM,UAAU;IAEvD,IAAI,cAAc,YAAY;IAC9B,IAAI,eAAe,aAAa,QAAQ,kBAAkB;IAC1D,IAAI,CAAC,eAAe,CAAC,cACnB,QAAQ,IAAI,CAAC;IAGf,IAAI,UAAU,MAAM,aAAa,KAAK;IAEtC,IAAI,WAAW,CAAC;QACd,EAAE,eAAe;QACjB,MAAM,gBAAgB,CAAC;IACzB;IAEA,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,qCAAO,EAAE;oBACrC;IACF;IAEA,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,kCAAW,EAAE,CAAA,GAAA,gCAAS,EAAE,OAAO;QACpD,SAAS,IAAM,MAAM,mBAAmB,CAAC;IAC3C,IAAI;IACJ,IAAI,eAAe,CAAA,GAAA,gCAAS,EAAE,YAAY;IAC1C,IAAI,WAAW,CAAA,GAAA,oCAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IACrD,IAAI,WAA+B;IACnC,IAAI,MAAM,aAAa,IAAI,MACzB;QAAA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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/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 {radioGroupData} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useFocusable} from '@react-aria/focus';\nimport {useFormValidation} from '@react-aria/form';\nimport {usePress} from '@react-aria/interactions';\n\nexport interface RadioAria {\n /** Props for the 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: number | undefined = -1;\n if (state.selectedValue != null) {\n if (state.selectedValue === value) {\n tabIndex = 0;\n }\n } else if (state.lastFocusedValue === value || state.lastFocusedValue == null) {\n tabIndex = 0;\n }\n if (isDisabled) {\n tabIndex = undefined;\n }\n\n let {name, descriptionId, errorMessageId, validationBehavior} = radioGroupData.get(state)!;\n useFormReset(ref, state.selectedValue, state.setSelectedValue);\n useFormValidation({validationBehavior}, state, ref);\n\n return {\n inputProps: mergeProps(domProps, {\n ...interactions,\n type: 'radio',\n name,\n tabIndex,\n disabled: isDisabled,\n required: state.isRequired && validationBehavior === 'native',\n checked,\n value,\n onChange,\n 'aria-describedby': [\n props['aria-describedby'],\n state.isInvalid ? errorMessageId : null,\n descriptionId\n ].filter(Boolean).join(' ') || undefined\n }),\n isDisabled,\n isSelected: checked,\n isPressed\n };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {RadioGroupState} from '@react-stately/radio';\n\ninterface RadioGroupData {\n name: string,\n descriptionId: string,\n errorMessageId: string,\n validationBehavior: 'aria' | 'native'\n}\n\nexport const radioGroupData = new WeakMap<RadioGroupState, RadioGroupData>();\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaRadioGroupProps} from '@react-types/radio';\nimport {DOMAttributes, ValidationResult} from '@react-types/shared';\nimport {filterDOMProps, mergeProps, useId} from '@react-aria/utils';\nimport {getFocusableTreeWalker} from '@react-aria/focus';\nimport {radioGroupData} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useField} from '@react-aria/label';\nimport {useFocusWithin} from '@react-aria/interactions';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface RadioGroupAria extends ValidationResult {\n /** Props for the radio group wrapper element. */\n radioGroupProps: DOMAttributes,\n /** Props for the radio group's visible label (if any). */\n labelProps: DOMAttributes,\n /** Props for the radio group description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the radio group error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a radio group component.\n * Radio groups allow users to select a single item from a list of mutually exclusive options.\n * @param props - Props for the radio group.\n * @param state - State for the radio group, as returned by `useRadioGroupState`.\n */\nexport function useRadioGroup(props: AriaRadioGroupProps, state: RadioGroupState): RadioGroupAria {\n let {\n name,\n isReadOnly,\n isRequired,\n isDisabled,\n orientation = 'vertical',\n validationBehavior = 'aria'\n } = props;\n let {direction} = useLocale();\n\n let {isInvalid, validationErrors, validationDetails} = state.displayValidation;\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n // Radio group is not an HTML input element so it\n // shouldn't be labeled by a <label> element.\n labelElementType: 'span',\n isInvalid: state.isInvalid,\n errorMessage: props.errorMessage || validationErrors\n });\n\n let domProps = filterDOMProps(props, {labelable: true});\n\n // When the radio group loses focus, reset the focusable radio to null if\n // there is no selection. This allows tabbing into the group from either\n // direction to go to the first or last radio.\n let {focusWithinProps} = useFocusWithin({\n onBlurWithin() {\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 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":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import {mergeProps as $4vDl6$mergeProps, filterDOMProps as $4vDl6$filterDOMProps, useFormReset as $4vDl6$useFormReset, useId as $4vDl6$useId} from "@react-aria/utils";
2
2
  import {useFocusable as $4vDl6$useFocusable, getFocusableTreeWalker as $4vDl6$getFocusableTreeWalker} from "@react-aria/focus";
3
+ import {useFormValidation as $4vDl6$useFormValidation} from "@react-aria/form";
3
4
  import {usePress as $4vDl6$usePress, useFocusWithin as $4vDl6$useFocusWithin} from "@react-aria/interactions";
4
5
  import {useField as $4vDl6$useField} from "@react-aria/label";
5
6
  import {useLocale as $4vDl6$useLocale} from "@react-aria/i18n";
@@ -35,9 +36,8 @@ import {useLocale as $4vDl6$useLocale} from "@react-aria/i18n";
35
36
  * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
36
37
  * OF ANY KIND, either express or implied. See the License for the specific language
37
38
  * governing permissions and limitations under the License.
38
- */ const $884aeceb3d67f00f$export$3b7b268d09480394 = new WeakMap();
39
- const $884aeceb3d67f00f$export$8e8b214e06dd397d = new WeakMap();
40
- const $884aeceb3d67f00f$export$61c8d3f0151e21b2 = new WeakMap();
39
+ */ const $884aeceb3d67f00f$export$37b65e5b5444d35c = new WeakMap();
40
+
41
41
 
42
42
 
43
43
 
@@ -68,21 +68,26 @@ function $0d5c49892c1215da$export$37b0961d2f4751e2(props, state, ref) {
68
68
  if (state.selectedValue === value) tabIndex = 0;
69
69
  } else if (state.lastFocusedValue === value || state.lastFocusedValue == null) tabIndex = 0;
70
70
  if (isDisabled) tabIndex = undefined;
71
+ let { name: name, descriptionId: descriptionId, errorMessageId: errorMessageId, validationBehavior: validationBehavior } = (0, $884aeceb3d67f00f$export$37b65e5b5444d35c).get(state);
71
72
  (0, $4vDl6$useFormReset)(ref, state.selectedValue, state.setSelectedValue);
73
+ (0, $4vDl6$useFormValidation)({
74
+ validationBehavior: validationBehavior
75
+ }, state, ref);
72
76
  return {
73
77
  inputProps: (0, $4vDl6$mergeProps)(domProps, {
74
78
  ...interactions,
75
79
  type: "radio",
76
- name: (0, $884aeceb3d67f00f$export$3b7b268d09480394).get(state),
80
+ name: name,
77
81
  tabIndex: tabIndex,
78
82
  disabled: isDisabled,
83
+ required: state.isRequired && validationBehavior === "native",
79
84
  checked: checked,
80
85
  value: value,
81
86
  onChange: onChange,
82
87
  "aria-describedby": [
83
88
  props["aria-describedby"],
84
- state.isInvalid ? (0, $884aeceb3d67f00f$export$61c8d3f0151e21b2).get(state) : null,
85
- (0, $884aeceb3d67f00f$export$8e8b214e06dd397d).get(state)
89
+ state.isInvalid ? errorMessageId : null,
90
+ descriptionId
86
91
  ].filter(Boolean).join(" ") || undefined
87
92
  }),
88
93
  isDisabled: isDisabled,
@@ -109,16 +114,17 @@ function $0d5c49892c1215da$export$37b0961d2f4751e2(props, state, ref) {
109
114
 
110
115
 
111
116
  function $430f30ed08ec25fa$export$62b9571f283ff5c2(props, state) {
112
- let { name: name, isReadOnly: isReadOnly, isRequired: isRequired, isDisabled: isDisabled, orientation: orientation = "vertical" } = props;
117
+ let { name: name, isReadOnly: isReadOnly, isRequired: isRequired, isDisabled: isDisabled, orientation: orientation = "vertical", validationBehavior: validationBehavior = "aria" } = props;
113
118
  let { direction: direction } = (0, $4vDl6$useLocale)();
119
+ let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
114
120
  let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $4vDl6$useField)({
115
121
  ...props,
116
122
  // Radio group is not an HTML input element so it
117
123
  // shouldn't be labeled by a <label> element.
118
- labelElementType: "span"
124
+ labelElementType: "span",
125
+ isInvalid: state.isInvalid,
126
+ errorMessage: props.errorMessage || validationErrors
119
127
  });
120
- (0, $884aeceb3d67f00f$export$8e8b214e06dd397d).set(state, descriptionProps.id);
121
- (0, $884aeceb3d67f00f$export$61c8d3f0151e21b2).set(state, errorMessageProps.id);
122
128
  let domProps = (0, $4vDl6$filterDOMProps)(props, {
123
129
  labelable: true
124
130
  });
@@ -175,7 +181,12 @@ function $430f30ed08ec25fa$export$62b9571f283ff5c2(props, state) {
175
181
  }
176
182
  };
177
183
  let groupName = (0, $4vDl6$useId)(name);
178
- (0, $884aeceb3d67f00f$export$3b7b268d09480394).set(state, groupName);
184
+ (0, $884aeceb3d67f00f$export$37b65e5b5444d35c).set(state, {
185
+ name: groupName,
186
+ descriptionId: descriptionProps.id,
187
+ errorMessageId: errorMessageProps.id,
188
+ validationBehavior: validationBehavior
189
+ });
179
190
  return {
180
191
  radioGroupProps: (0, $4vDl6$mergeProps)(domProps, {
181
192
  // https://www.w3.org/TR/wai-aria-1.2/#radiogroup
@@ -192,7 +203,10 @@ function $430f30ed08ec25fa$export$62b9571f283ff5c2(props, state) {
192
203
  }),
193
204
  labelProps: labelProps,
194
205
  descriptionProps: descriptionProps,
195
- errorMessageProps: errorMessageProps
206
+ errorMessageProps: errorMessageProps,
207
+ isInvalid: isInvalid,
208
+ validationErrors: validationErrors,
209
+ validationDetails: validationDetails
196
210
  };
197
211
  }
198
212
 
@@ -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,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,IAAI,CAAC,eAAe,CAAC,cACnB,QAAQ,KAAK;IAGf,IAAI,UAAU,MAAM,kBAAkB;IAEtC,IAAI,WAAW,CAAC;QACd,EAAE;QACF,MAAM,iBAAiB;IACzB;IAEA,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;oBACrC;IACF;IAEA,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,mBAAW,EAAE,CAAA,GAAA,iBAAS,EAAE,OAAO;QACpD,SAAS,IAAM,MAAM,oBAAoB;IAC3C,IAAI;IACJ,IAAI,eAAe,CAAA,GAAA,iBAAS,EAAE,YAAY;IAC1C,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IACrD,IAAI,WAAW;IACf,IAAI,MAAM,iBAA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Aa,EAAE;QACtC;YACE,IAAI,CAAC,MAAM,eACT,MAAM,oBAAoB;QAE9B;IACF;IAEA,IAAI,YAAY,CAAC;QACf,IAAI;QACJ,OAAQ,EAAE;YACR,KAAK;gBACH,IAAI,cAAc,SAAS,gBAAgB,YACzC,UAAU;qBAEV,UAAU;gBAEZ;YACF,KAAK;gBACH,IAAI,cAAc,SAAS,gBAAgB,YACzC,UAAU;qBAEV,UAAU;gBAEZ;YACF,KAAK;gBACH,UAAU;gBACV;YACF,KAAK;gBACH,UAAU;gBACV;YACF;gBACE;QACJ;QACA,EAAE;QACF,IAAI,SAAS,CAAA,GAAA,6BAAqB,EAAE,EAAE,eAAe;YAAC,MAAM,EAAE;QAAM;QACpE,IAAI;QACJ,IAAI,YAAY,QAAQ;YACtB,WAAW,OAAO;YAClB,IAAI,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,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"}
1
+ {"mappings":";;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;ACVD;;;;;;;;;;CAUC,GAWM,MAAM,4CAAiB,IAAI;;;;;;ADkB3B,SAAS,0CAAS,KAAqB,EAAE,KAAsB,EAAE,GAAgC;IACtG,IAAI,SACF,KAAK,YACL,QAAQ,EACR,cAAc,SAAS,EACvB,mBAAmB,cAAc,EAClC,GAAG;IAEJ,MAAM,aAAa,MAAM,UAAU,IAAI,MAAM,UAAU;IAEvD,IAAI,cAAc,YAAY;IAC9B,IAAI,eAAe,aAAa,QAAQ,kBAAkB;IAC1D,IAAI,CAAC,eAAe,CAAC,cACnB,QAAQ,IAAI,CAAC;IAGf,IAAI,UAAU,MAAM,aAAa,KAAK;IAEtC,IAAI,WAAW,CAAC;QACd,EAAE,eAAe;QACjB,MAAM,gBAAgB,CAAC;IACzB;IAEA,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;oBACrC;IACF;IAEA,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,mBAAW,EAAE,CAAA,GAAA,iBAAS,EAAE,OAAO;QACpD,SAAS,IAAM,MAAM,mBAAmB,CAAC;IAC3C,IAAI;IACJ,IAAI,eAAe,CAAA,GAAA,iBAAS,EAAE,YAAY;IAC1C,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IACrD,IAAI,WAA+B;IACnC,IAAI,MAAM,aAAa,IAAI,MACzB;QAAA,IAAI,MAAM,aAAa,KAAK,OAC1B,WAAW;IACb,OACK,IAAI,MAAM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,iDAAiD;YACjD,MAAM;uBACN;YACA,gBAAgB,MAAM,SAAS,IAAI;YACnC,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,iBAAiB,cAAc;YAC/B,iBAAiB,cAAc;YAC/B,iBAAiB,cAAc;YAC/B,oBAAoB;YACpB,GAAG,UAAU;YACb,GAAG,gBAAgB;QACrB;oBACA;0BACA;2BACA;mBACA;0BACA;2BACA;IACF;AACF;","sources":["packages/@react-aria/radio/src/index.ts","packages/@react-aria/radio/src/useRadio.ts","packages/@react-aria/radio/src/utils.ts","packages/@react-aria/radio/src/useRadioGroup.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useRadio} from './useRadio';\nexport {useRadioGroup} from './useRadioGroup';\nexport type {AriaRadioGroupProps, AriaRadioProps} from '@react-types/radio';\nexport type {Orientation} from '@react-types/shared';\nexport type {RadioAria} from './useRadio';\nexport type {RadioGroupAria} from './useRadioGroup';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaRadioProps} from '@react-types/radio';\nimport {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';\nimport {InputHTMLAttributes, RefObject} from 'react';\nimport {radioGroupData} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useFocusable} from '@react-aria/focus';\nimport {useFormValidation} from '@react-aria/form';\nimport {usePress} from '@react-aria/interactions';\n\nexport interface RadioAria {\n /** Props for the 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: number | undefined = -1;\n if (state.selectedValue != null) {\n if (state.selectedValue === value) {\n tabIndex = 0;\n }\n } else if (state.lastFocusedValue === value || state.lastFocusedValue == null) {\n tabIndex = 0;\n }\n if (isDisabled) {\n tabIndex = undefined;\n }\n\n let {name, descriptionId, errorMessageId, validationBehavior} = radioGroupData.get(state)!;\n useFormReset(ref, state.selectedValue, state.setSelectedValue);\n useFormValidation({validationBehavior}, state, ref);\n\n return {\n inputProps: mergeProps(domProps, {\n ...interactions,\n type: 'radio',\n name,\n tabIndex,\n disabled: isDisabled,\n required: state.isRequired && validationBehavior === 'native',\n checked,\n value,\n onChange,\n 'aria-describedby': [\n props['aria-describedby'],\n state.isInvalid ? errorMessageId : null,\n descriptionId\n ].filter(Boolean).join(' ') || undefined\n }),\n isDisabled,\n isSelected: checked,\n isPressed\n };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {RadioGroupState} from '@react-stately/radio';\n\ninterface RadioGroupData {\n name: string,\n descriptionId: string,\n errorMessageId: string,\n validationBehavior: 'aria' | 'native'\n}\n\nexport const radioGroupData = new WeakMap<RadioGroupState, RadioGroupData>();\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaRadioGroupProps} from '@react-types/radio';\nimport {DOMAttributes, ValidationResult} from '@react-types/shared';\nimport {filterDOMProps, mergeProps, useId} from '@react-aria/utils';\nimport {getFocusableTreeWalker} from '@react-aria/focus';\nimport {radioGroupData} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useField} from '@react-aria/label';\nimport {useFocusWithin} from '@react-aria/interactions';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface RadioGroupAria extends ValidationResult {\n /** Props for the radio group wrapper element. */\n radioGroupProps: DOMAttributes,\n /** Props for the radio group's visible label (if any). */\n labelProps: DOMAttributes,\n /** Props for the radio group description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the radio group error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a radio group component.\n * Radio groups allow users to select a single item from a list of mutually exclusive options.\n * @param props - Props for the radio group.\n * @param state - State for the radio group, as returned by `useRadioGroupState`.\n */\nexport function useRadioGroup(props: AriaRadioGroupProps, state: RadioGroupState): RadioGroupAria {\n let {\n name,\n isReadOnly,\n isRequired,\n isDisabled,\n orientation = 'vertical',\n validationBehavior = 'aria'\n } = props;\n let {direction} = useLocale();\n\n let {isInvalid, validationErrors, validationDetails} = state.displayValidation;\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n // Radio group is not an HTML input element so it\n // shouldn't be labeled by a <label> element.\n labelElementType: 'span',\n isInvalid: state.isInvalid,\n errorMessage: props.errorMessage || validationErrors\n });\n\n let domProps = filterDOMProps(props, {labelable: true});\n\n // When the radio group loses focus, reset the focusable radio to null if\n // there is no selection. This allows tabbing into the group from either\n // direction to go to the first or last radio.\n let {focusWithinProps} = useFocusWithin({\n onBlurWithin() {\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 radioGroupData.set(state, {\n name: groupName,\n descriptionId: descriptionProps.id,\n errorMessageId: errorMessageProps.id,\n validationBehavior\n });\n\n return {\n radioGroupProps: mergeProps(domProps, {\n // https://www.w3.org/TR/wai-aria-1.2/#radiogroup\n role: 'radiogroup',\n onKeyDown,\n 'aria-invalid': state.isInvalid || undefined,\n 'aria-errormessage': props['aria-errormessage'],\n 'aria-readonly': isReadOnly || undefined,\n 'aria-required': isRequired || undefined,\n 'aria-disabled': isDisabled || undefined,\n 'aria-orientation': orientation,\n ...fieldProps,\n ...focusWithinProps\n }),\n labelProps,\n descriptionProps,\n errorMessageProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AriaRadioProps, AriaRadioGroupProps } from "@react-types/radio";
2
2
  import { InputHTMLAttributes, RefObject } from "react";
3
3
  import { RadioGroupState } from "@react-stately/radio";
4
- import { DOMAttributes } from "@react-types/shared";
4
+ import { DOMAttributes, ValidationResult } from "@react-types/shared";
5
5
  export interface RadioAria {
6
6
  /** Props for the input element. */
7
7
  inputProps: InputHTMLAttributes<HTMLInputElement>;
@@ -20,7 +20,7 @@ export interface RadioAria {
20
20
  * @param ref - Ref to the HTML input element.
21
21
  */
22
22
  export function useRadio(props: AriaRadioProps, state: RadioGroupState, ref: RefObject<HTMLInputElement>): RadioAria;
23
- export interface RadioGroupAria {
23
+ export interface RadioGroupAria extends ValidationResult {
24
24
  /** Props for the radio group wrapper element. */
25
25
  radioGroupProps: DOMAttributes;
26
26
  /** Props for the radio group's visible label (if any). */
@@ -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,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"}
1
+ {"mappings":";;;;ACqBA;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,CAqEnH;ACtFD,+BAAgC,SAAQ,gBAAgB;IACtD,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,CAgHhG;AC1ID,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.8.2",
3
+ "version": "3.9.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,14 +22,15 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-aria/focus": "^3.14.3",
26
- "@react-aria/i18n": "^3.8.4",
27
- "@react-aria/interactions": "^3.19.1",
28
- "@react-aria/label": "^3.7.2",
29
- "@react-aria/utils": "^3.21.1",
30
- "@react-stately/radio": "^3.9.1",
31
- "@react-types/radio": "^3.5.2",
32
- "@react-types/shared": "^3.21.0",
25
+ "@react-aria/focus": "^3.15.0",
26
+ "@react-aria/form": "^3.0.0",
27
+ "@react-aria/i18n": "^3.9.0",
28
+ "@react-aria/interactions": "^3.20.0",
29
+ "@react-aria/label": "^3.7.3",
30
+ "@react-aria/utils": "^3.22.0",
31
+ "@react-stately/radio": "^3.10.0",
32
+ "@react-types/radio": "^3.6.0",
33
+ "@react-types/shared": "^3.22.0",
33
34
  "@swc/helpers": "^0.5.0"
34
35
  },
35
36
  "peerDependencies": {
@@ -38,5 +39,5 @@
38
39
  "publishConfig": {
39
40
  "access": "public"
40
41
  },
41
- "gitHead": "3ecf62dcceea437cb12df1851636dd491bb6591c"
42
+ "gitHead": "9ce2f674eab2cc8912800d3162dcf00a1ce94274"
42
43
  }
package/src/useRadio.ts CHANGED
@@ -13,9 +13,10 @@
13
13
  import {AriaRadioProps} from '@react-types/radio';
14
14
  import {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';
15
15
  import {InputHTMLAttributes, RefObject} from 'react';
16
- import {radioGroupDescriptionIds, radioGroupErrorMessageIds, radioGroupNames} from './utils';
16
+ import {radioGroupData} from './utils';
17
17
  import {RadioGroupState} from '@react-stately/radio';
18
18
  import {useFocusable} from '@react-aria/focus';
19
+ import {useFormValidation} from '@react-aria/form';
19
20
  import {usePress} from '@react-aria/interactions';
20
21
 
21
22
  export interface RadioAria {
@@ -68,7 +69,7 @@ export function useRadio(props: AriaRadioProps, state: RadioGroupState, ref: Ref
68
69
  }), ref);
69
70
  let interactions = mergeProps(pressProps, focusableProps);
70
71
  let domProps = filterDOMProps(props, {labelable: true});
71
- let tabIndex = -1;
72
+ let tabIndex: number | undefined = -1;
72
73
  if (state.selectedValue != null) {
73
74
  if (state.selectedValue === value) {
74
75
  tabIndex = 0;
@@ -80,22 +81,25 @@ export function useRadio(props: AriaRadioProps, state: RadioGroupState, ref: Ref
80
81
  tabIndex = undefined;
81
82
  }
82
83
 
84
+ let {name, descriptionId, errorMessageId, validationBehavior} = radioGroupData.get(state)!;
83
85
  useFormReset(ref, state.selectedValue, state.setSelectedValue);
86
+ useFormValidation({validationBehavior}, state, ref);
84
87
 
85
88
  return {
86
89
  inputProps: mergeProps(domProps, {
87
90
  ...interactions,
88
91
  type: 'radio',
89
- name: radioGroupNames.get(state),
92
+ name,
90
93
  tabIndex,
91
94
  disabled: isDisabled,
95
+ required: state.isRequired && validationBehavior === 'native',
92
96
  checked,
93
97
  value,
94
98
  onChange,
95
99
  'aria-describedby': [
96
100
  props['aria-describedby'],
97
- state.isInvalid ? radioGroupErrorMessageIds.get(state) : null,
98
- radioGroupDescriptionIds.get(state)
101
+ state.isInvalid ? errorMessageId : null,
102
+ descriptionId
99
103
  ].filter(Boolean).join(' ') || undefined
100
104
  }),
101
105
  isDisabled,
@@ -11,16 +11,16 @@
11
11
  */
12
12
 
13
13
  import {AriaRadioGroupProps} from '@react-types/radio';
14
- import {DOMAttributes} from '@react-types/shared';
14
+ import {DOMAttributes, ValidationResult} from '@react-types/shared';
15
15
  import {filterDOMProps, mergeProps, useId} from '@react-aria/utils';
16
16
  import {getFocusableTreeWalker} from '@react-aria/focus';
17
- import {radioGroupDescriptionIds, radioGroupErrorMessageIds, radioGroupNames} from './utils';
17
+ import {radioGroupData} from './utils';
18
18
  import {RadioGroupState} from '@react-stately/radio';
19
19
  import {useField} from '@react-aria/label';
20
20
  import {useFocusWithin} from '@react-aria/interactions';
21
21
  import {useLocale} from '@react-aria/i18n';
22
22
 
23
- export interface RadioGroupAria {
23
+ export interface RadioGroupAria extends ValidationResult {
24
24
  /** Props for the radio group wrapper element. */
25
25
  radioGroupProps: DOMAttributes,
26
26
  /** Props for the radio group's visible label (if any). */
@@ -43,18 +43,20 @@ export function useRadioGroup(props: AriaRadioGroupProps, state: RadioGroupState
43
43
  isReadOnly,
44
44
  isRequired,
45
45
  isDisabled,
46
- orientation = 'vertical'
46
+ orientation = 'vertical',
47
+ validationBehavior = 'aria'
47
48
  } = props;
48
49
  let {direction} = useLocale();
49
50
 
51
+ let {isInvalid, validationErrors, validationDetails} = state.displayValidation;
50
52
  let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({
51
53
  ...props,
52
54
  // Radio group is not an HTML input element so it
53
55
  // shouldn't be labeled by a <label> element.
54
- labelElementType: 'span'
56
+ labelElementType: 'span',
57
+ isInvalid: state.isInvalid,
58
+ errorMessage: props.errorMessage || validationErrors
55
59
  });
56
- radioGroupDescriptionIds.set(state, descriptionProps.id);
57
- radioGroupErrorMessageIds.set(state, errorMessageProps.id);
58
60
 
59
61
  let domProps = filterDOMProps(props, {labelable: true});
60
62
 
@@ -119,7 +121,12 @@ export function useRadioGroup(props: AriaRadioGroupProps, state: RadioGroupState
119
121
  };
120
122
 
121
123
  let groupName = useId(name);
122
- radioGroupNames.set(state, groupName);
124
+ radioGroupData.set(state, {
125
+ name: groupName,
126
+ descriptionId: descriptionProps.id,
127
+ errorMessageId: errorMessageProps.id,
128
+ validationBehavior
129
+ });
123
130
 
124
131
  return {
125
132
  radioGroupProps: mergeProps(domProps, {
@@ -137,6 +144,9 @@ export function useRadioGroup(props: AriaRadioGroupProps, state: RadioGroupState
137
144
  }),
138
145
  labelProps,
139
146
  descriptionProps,
140
- errorMessageProps
147
+ errorMessageProps,
148
+ isInvalid,
149
+ validationErrors,
150
+ validationDetails
141
151
  };
142
152
  }
package/src/utils.ts CHANGED
@@ -12,6 +12,11 @@
12
12
 
13
13
  import {RadioGroupState} from '@react-stately/radio';
14
14
 
15
- export const radioGroupNames = new WeakMap<RadioGroupState, string>();
16
- export const radioGroupDescriptionIds = new WeakMap<RadioGroupState, string>();
17
- export const radioGroupErrorMessageIds = new WeakMap<RadioGroupState, string>();
15
+ interface RadioGroupData {
16
+ name: string,
17
+ descriptionId: string,
18
+ errorMessageId: string,
19
+ validationBehavior: 'aria' | 'native'
20
+ }
21
+
22
+ export const radioGroupData = new WeakMap<RadioGroupState, RadioGroupData>();