@react-stately/radio 3.9.1 → 3.10.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 CHANGED
@@ -1,3 +1,4 @@
1
+ import {useFormValidationState as $fQ2SF$useFormValidationState} from "@react-stately/form";
1
2
  import {useControlledState as $fQ2SF$useControlledState} from "@react-stately/utils";
2
3
  import {useMemo as $fQ2SF$useMemo, useState as $fQ2SF$useState} from "react";
3
4
 
@@ -23,6 +24,7 @@ import {useMemo as $fQ2SF$useMemo, useState as $fQ2SF$useState} from "react";
23
24
  * governing permissions and limitations under the License.
24
25
  */
25
26
 
27
+
26
28
  let $a54cdc5c1942b639$var$instance = Math.round(Math.random() * 10000000000);
27
29
  let $a54cdc5c1942b639$var$i = 0;
28
30
  function $a54cdc5c1942b639$export$bca9d026f8e704eb(props) {
@@ -30,12 +32,22 @@ function $a54cdc5c1942b639$export$bca9d026f8e704eb(props) {
30
32
  let name = (0, $fQ2SF$useMemo)(()=>props.name || `radio-group-${$a54cdc5c1942b639$var$instance}-${++$a54cdc5c1942b639$var$i}`, [
31
33
  props.name
32
34
  ]);
33
- let [selectedValue, setSelected] = (0, $fQ2SF$useControlledState)(props.value, props.defaultValue, props.onChange);
35
+ var _props_defaultValue;
36
+ let [selectedValue, setSelected] = (0, $fQ2SF$useControlledState)(props.value, (_props_defaultValue = props.defaultValue) !== null && _props_defaultValue !== void 0 ? _props_defaultValue : null, props.onChange);
34
37
  let [lastFocusedValue, setLastFocusedValue] = (0, $fQ2SF$useState)(null);
38
+ let validation = (0, $fQ2SF$useFormValidationState)({
39
+ ...props,
40
+ value: selectedValue
41
+ });
35
42
  let setSelectedValue = (value)=>{
36
- if (!props.isReadOnly && !props.isDisabled) setSelected(value);
43
+ if (!props.isReadOnly && !props.isDisabled) {
44
+ setSelected(value);
45
+ validation.commitValidation();
46
+ }
37
47
  };
48
+ let isInvalid = validation.displayValidation.isInvalid;
38
49
  return {
50
+ ...validation,
39
51
  name: name,
40
52
  selectedValue: selectedValue,
41
53
  setSelectedValue: setSelectedValue,
@@ -44,8 +56,8 @@ function $a54cdc5c1942b639$export$bca9d026f8e704eb(props) {
44
56
  isDisabled: props.isDisabled || false,
45
57
  isReadOnly: props.isReadOnly || false,
46
58
  isRequired: props.isRequired || false,
47
- validationState: props.validationState || null,
48
- isInvalid: props.isInvalid || props.validationState === "invalid"
59
+ validationState: props.validationState || (isInvalid ? "invalid" : null),
60
+ isInvalid: isInvalid
49
61
  };
50
62
  }
51
63
 
package/dist/main.js CHANGED
@@ -1,6 +1,8 @@
1
+ var $6fRYN$reactstatelyform = require("@react-stately/form");
1
2
  var $6fRYN$reactstatelyutils = require("@react-stately/utils");
2
3
  var $6fRYN$react = require("react");
3
4
 
5
+
4
6
  function $parcel$export(e, n, v, s) {
5
7
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
8
  }
@@ -28,6 +30,7 @@ $parcel$export(module.exports, "useRadioGroupState", () => $307db30b5687e2e8$exp
28
30
  * governing permissions and limitations under the License.
29
31
  */
30
32
 
33
+
31
34
  let $307db30b5687e2e8$var$instance = Math.round(Math.random() * 10000000000);
32
35
  let $307db30b5687e2e8$var$i = 0;
33
36
  function $307db30b5687e2e8$export$bca9d026f8e704eb(props) {
@@ -35,12 +38,22 @@ function $307db30b5687e2e8$export$bca9d026f8e704eb(props) {
35
38
  let name = (0, $6fRYN$react.useMemo)(()=>props.name || `radio-group-${$307db30b5687e2e8$var$instance}-${++$307db30b5687e2e8$var$i}`, [
36
39
  props.name
37
40
  ]);
38
- let [selectedValue, setSelected] = (0, $6fRYN$reactstatelyutils.useControlledState)(props.value, props.defaultValue, props.onChange);
41
+ var _props_defaultValue;
42
+ let [selectedValue, setSelected] = (0, $6fRYN$reactstatelyutils.useControlledState)(props.value, (_props_defaultValue = props.defaultValue) !== null && _props_defaultValue !== void 0 ? _props_defaultValue : null, props.onChange);
39
43
  let [lastFocusedValue, setLastFocusedValue] = (0, $6fRYN$react.useState)(null);
44
+ let validation = (0, $6fRYN$reactstatelyform.useFormValidationState)({
45
+ ...props,
46
+ value: selectedValue
47
+ });
40
48
  let setSelectedValue = (value)=>{
41
- if (!props.isReadOnly && !props.isDisabled) setSelected(value);
49
+ if (!props.isReadOnly && !props.isDisabled) {
50
+ setSelected(value);
51
+ validation.commitValidation();
52
+ }
42
53
  };
54
+ let isInvalid = validation.displayValidation.isInvalid;
43
55
  return {
56
+ ...validation,
44
57
  name: name,
45
58
  selectedValue: selectedValue,
46
59
  setSelectedValue: setSelectedValue,
@@ -49,8 +62,8 @@ function $307db30b5687e2e8$export$bca9d026f8e704eb(props) {
49
62
  isDisabled: props.isDisabled || false,
50
63
  isReadOnly: props.isReadOnly || false,
51
64
  isRequired: props.isRequired || false,
52
- validationState: props.validationState || null,
53
- isInvalid: props.isInvalid || props.validationState === "invalid"
65
+ validationState: props.validationState || (isInvalid ? "invalid" : null),
66
+ isInvalid: isInvalid
54
67
  };
55
68
  }
56
69
 
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;AA8CD,IAAI,iCAAW,KAAK,MAAM,KAAK,WAAW;AAC1C,IAAI,0BAAI;AAMD,SAAS,0CAAmB,KAAsB;IACvD,mGAAmG;IACnG,IAAI,OAAO,CAAA,GAAA,oBAAM,EAAE,IAAM,MAAM,QAAQ,CAAC,YAAY,EAAE,+BAAS,CAAC,EAAE,EAAE,wBAAE,CAAC,EAAE;QAAC,MAAM;KAAK;IACrF,IAAI,CAAC,eAAe,YAAY,GAAG,CAAA,GAAA,2CAAiB,EAAE,MAAM,OAAO,MAAM,cAAc,MAAM;IAC7F,IAAI,CAAC,kBAAkB,oBAAoB,GAAG,CAAA,GAAA,qBAAO,EAAE;IAEvD,IAAI,mBAAmB,CAAC;QACtB,IAAI,CAAC,MAAM,cAAc,CAAC,MAAM,YAC9B,YAAY;IAEhB;IAEA,OAAO;cACL;uBACA;0BACA;0BACA;6BACA;QACA,YAAY,MAAM,cAAc;QAChC,YAAY,MAAM,cAAc;QAChC,YAAY,MAAM,cAAc;QAChC,iBAAiB,MAAM,mBAAmB;QAC1C,WAAW,MAAM,aAAa,MAAM,oBAAoB;IAC1D;AACF;;CD7EC","sources":["packages/@react-stately/radio/src/index.ts","packages/@react-stately/radio/src/useRadioGroupState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useRadioGroupState} from './useRadioGroupState';\n\nexport type {RadioGroupProps} from '@react-types/radio';\nexport type {RadioGroupState} from './useRadioGroupState';\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 {RadioGroupProps} from '@react-types/radio';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useState} from 'react';\nimport {ValidationState} from '@react-types/shared';\n\nexport interface RadioGroupState {\n /**\n * The name for the group, used for native form submission.\n * @deprecated\n * @private\n */\n readonly name: string,\n\n /** Whether the radio group is disabled. */\n readonly isDisabled: boolean,\n\n /** Whether the radio group is read only. */\n readonly isReadOnly: boolean,\n\n /** Whether the radio group is required. */\n readonly isRequired: boolean,\n\n /**\n * Whether the radio group is valid or invalid.\n * @deprecated Use `isInvalid` instead.\n */\n readonly validationState: ValidationState | null,\n\n /** Whether the radio group is invalid. */\n readonly isInvalid: boolean,\n\n /** The currently selected value. */\n readonly selectedValue: string | null,\n\n /** Sets the selected value. */\n setSelectedValue(value: string): void,\n\n /** The value of the last focused radio. */\n readonly lastFocusedValue: string | null,\n\n /** Sets the last focused value. */\n setLastFocusedValue(value: string): void\n}\n\nlet instance = Math.round(Math.random() * 10000000000);\nlet i = 0;\n\n/**\n * Provides state management for a radio group component. Provides a name for the group,\n * and manages selection and focus state.\n */\nexport function useRadioGroupState(props: RadioGroupProps): RadioGroupState {\n // Preserved here for backward compatibility. React Aria now generates the name instead of stately.\n let name = useMemo(() => props.name || `radio-group-${instance}-${++i}`, [props.name]);\n let [selectedValue, setSelected] = useControlledState(props.value, props.defaultValue, props.onChange);\n let [lastFocusedValue, setLastFocusedValue] = useState(null);\n\n let setSelectedValue = (value) => {\n if (!props.isReadOnly && !props.isDisabled) {\n setSelected(value);\n }\n };\n\n return {\n name,\n selectedValue,\n setSelectedValue,\n lastFocusedValue,\n setLastFocusedValue,\n isDisabled: props.isDisabled || false,\n isReadOnly: props.isReadOnly || false,\n isRequired: props.isRequired || false,\n validationState: props.validationState || null,\n isInvalid: props.isInvalid || props.validationState === 'invalid'\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;AA+CD,IAAI,iCAAW,KAAK,KAAK,CAAC,KAAK,MAAM,KAAK;AAC1C,IAAI,0BAAI;AAMD,SAAS,0CAAmB,KAAsB;IACvD,mGAAmG;IACnG,IAAI,OAAO,CAAA,GAAA,oBAAM,EAAE,IAAM,MAAM,IAAI,IAAI,CAAC,YAAY,EAAE,+BAAS,CAAC,EAAE,EAAE,wBAAE,CAAC,EAAE;QAAC,MAAM,IAAI;KAAC;QAClB;IAAnE,IAAI,CAAC,eAAe,YAAY,GAAG,CAAA,GAAA,2CAAiB,EAAE,MAAM,KAAK,EAAE,CAAA,sBAAA,MAAM,YAAY,cAAlB,iCAAA,sBAAsB,MAAM,MAAM,QAAQ;IAC7G,IAAI,CAAC,kBAAkB,oBAAoB,GAAG,CAAA,GAAA,qBAAO,EAAiB;IAEtE,IAAI,aAAa,CAAA,GAAA,8CAAqB,EAAE;QACtC,GAAG,KAAK;QACR,OAAO;IACT;IAEA,IAAI,mBAAmB,CAAC;QACtB,IAAI,CAAC,MAAM,UAAU,IAAI,CAAC,MAAM,UAAU,EAAE;YAC1C,YAAY;YACZ,WAAW,gBAAgB;QAC7B;IACF;IAEA,IAAI,YAAY,WAAW,iBAAiB,CAAC,SAAS;IAEtD,OAAO;QACL,GAAG,UAAU;cACb;QACA,eAAe;0BACf;0BACA;6BACA;QACA,YAAY,MAAM,UAAU,IAAI;QAChC,YAAY,MAAM,UAAU,IAAI;QAChC,YAAY,MAAM,UAAU,IAAI;QAChC,iBAAiB,MAAM,eAAe,IAAK,CAAA,YAAY,YAAY,IAAG;mBACtE;IACF;AACF;;CDvFC","sources":["packages/@react-stately/radio/src/index.ts","packages/@react-stately/radio/src/useRadioGroupState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useRadioGroupState} from './useRadioGroupState';\n\nexport type {RadioGroupProps} from '@react-types/radio';\nexport type {RadioGroupState} from './useRadioGroupState';\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 {FormValidationState, useFormValidationState} from '@react-stately/form';\nimport {RadioGroupProps} from '@react-types/radio';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useState} from 'react';\nimport {ValidationState} from '@react-types/shared';\n\nexport interface RadioGroupState extends FormValidationState {\n /**\n * The name for the group, used for native form submission.\n * @deprecated\n * @private\n */\n readonly name: string,\n\n /** Whether the radio group is disabled. */\n readonly isDisabled: boolean,\n\n /** Whether the radio group is read only. */\n readonly isReadOnly: boolean,\n\n /** Whether the radio group is required. */\n readonly isRequired: boolean,\n\n /**\n * Whether the radio group is valid or invalid.\n * @deprecated Use `isInvalid` instead.\n */\n readonly validationState: ValidationState | null,\n\n /** Whether the radio group is invalid. */\n readonly isInvalid: boolean,\n\n /** The currently selected value. */\n readonly selectedValue: string | null,\n\n /** Sets the selected value. */\n setSelectedValue(value: string | null): void,\n\n /** The value of the last focused radio. */\n readonly lastFocusedValue: string | null,\n\n /** Sets the last focused value. */\n setLastFocusedValue(value: string | null): void\n}\n\nlet instance = Math.round(Math.random() * 10000000000);\nlet i = 0;\n\n/**\n * Provides state management for a radio group component. Provides a name for the group,\n * and manages selection and focus state.\n */\nexport function useRadioGroupState(props: RadioGroupProps): RadioGroupState {\n // Preserved here for backward compatibility. React Aria now generates the name instead of stately.\n let name = useMemo(() => props.name || `radio-group-${instance}-${++i}`, [props.name]);\n let [selectedValue, setSelected] = useControlledState(props.value, props.defaultValue ?? null, props.onChange);\n let [lastFocusedValue, setLastFocusedValue] = useState<string | null>(null);\n\n let validation = useFormValidationState({\n ...props,\n value: selectedValue\n });\n\n let setSelectedValue = (value) => {\n if (!props.isReadOnly && !props.isDisabled) {\n setSelected(value);\n validation.commitValidation();\n }\n };\n\n let isInvalid = validation.displayValidation.isInvalid;\n\n return {\n ...validation,\n name,\n selectedValue: selectedValue,\n setSelectedValue,\n lastFocusedValue,\n setLastFocusedValue,\n isDisabled: props.isDisabled || false,\n isReadOnly: props.isReadOnly || false,\n isRequired: props.isRequired || false,\n validationState: props.validationState || (isInvalid ? 'invalid' : null),\n isInvalid\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,3 +1,4 @@
1
+ import {useFormValidationState as $fQ2SF$useFormValidationState} from "@react-stately/form";
1
2
  import {useControlledState as $fQ2SF$useControlledState} from "@react-stately/utils";
2
3
  import {useMemo as $fQ2SF$useMemo, useState as $fQ2SF$useState} from "react";
3
4
 
@@ -23,6 +24,7 @@ import {useMemo as $fQ2SF$useMemo, useState as $fQ2SF$useState} from "react";
23
24
  * governing permissions and limitations under the License.
24
25
  */
25
26
 
27
+
26
28
  let $a54cdc5c1942b639$var$instance = Math.round(Math.random() * 10000000000);
27
29
  let $a54cdc5c1942b639$var$i = 0;
28
30
  function $a54cdc5c1942b639$export$bca9d026f8e704eb(props) {
@@ -30,12 +32,22 @@ function $a54cdc5c1942b639$export$bca9d026f8e704eb(props) {
30
32
  let name = (0, $fQ2SF$useMemo)(()=>props.name || `radio-group-${$a54cdc5c1942b639$var$instance}-${++$a54cdc5c1942b639$var$i}`, [
31
33
  props.name
32
34
  ]);
33
- let [selectedValue, setSelected] = (0, $fQ2SF$useControlledState)(props.value, props.defaultValue, props.onChange);
35
+ var _props_defaultValue;
36
+ let [selectedValue, setSelected] = (0, $fQ2SF$useControlledState)(props.value, (_props_defaultValue = props.defaultValue) !== null && _props_defaultValue !== void 0 ? _props_defaultValue : null, props.onChange);
34
37
  let [lastFocusedValue, setLastFocusedValue] = (0, $fQ2SF$useState)(null);
38
+ let validation = (0, $fQ2SF$useFormValidationState)({
39
+ ...props,
40
+ value: selectedValue
41
+ });
35
42
  let setSelectedValue = (value)=>{
36
- if (!props.isReadOnly && !props.isDisabled) setSelected(value);
43
+ if (!props.isReadOnly && !props.isDisabled) {
44
+ setSelected(value);
45
+ validation.commitValidation();
46
+ }
37
47
  };
48
+ let isInvalid = validation.displayValidation.isInvalid;
38
49
  return {
50
+ ...validation,
39
51
  name: name,
40
52
  selectedValue: selectedValue,
41
53
  setSelectedValue: setSelectedValue,
@@ -44,8 +56,8 @@ function $a54cdc5c1942b639$export$bca9d026f8e704eb(props) {
44
56
  isDisabled: props.isDisabled || false,
45
57
  isReadOnly: props.isReadOnly || false,
46
58
  isRequired: props.isRequired || false,
47
- validationState: props.validationState || null,
48
- isInvalid: props.isInvalid || props.validationState === "invalid"
59
+ validationState: props.validationState || (isInvalid ? "invalid" : null),
60
+ isInvalid: isInvalid
49
61
  };
50
62
  }
51
63
 
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;AA8CD,IAAI,iCAAW,KAAK,MAAM,KAAK,WAAW;AAC1C,IAAI,0BAAI;AAMD,SAAS,0CAAmB,KAAsB;IACvD,mGAAmG;IACnG,IAAI,OAAO,CAAA,GAAA,cAAM,EAAE,IAAM,MAAM,QAAQ,CAAC,YAAY,EAAE,+BAAS,CAAC,EAAE,EAAE,wBAAE,CAAC,EAAE;QAAC,MAAM;KAAK;IACrF,IAAI,CAAC,eAAe,YAAY,GAAG,CAAA,GAAA,yBAAiB,EAAE,MAAM,OAAO,MAAM,cAAc,MAAM;IAC7F,IAAI,CAAC,kBAAkB,oBAAoB,GAAG,CAAA,GAAA,eAAO,EAAE;IAEvD,IAAI,mBAAmB,CAAC;QACtB,IAAI,CAAC,MAAM,cAAc,CAAC,MAAM,YAC9B,YAAY;IAEhB;IAEA,OAAO;cACL;uBACA;0BACA;0BACA;6BACA;QACA,YAAY,MAAM,cAAc;QAChC,YAAY,MAAM,cAAc;QAChC,YAAY,MAAM,cAAc;QAChC,iBAAiB,MAAM,mBAAmB;QAC1C,WAAW,MAAM,aAAa,MAAM,oBAAoB;IAC1D;AACF;;CD7EC","sources":["packages/@react-stately/radio/src/index.ts","packages/@react-stately/radio/src/useRadioGroupState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useRadioGroupState} from './useRadioGroupState';\n\nexport type {RadioGroupProps} from '@react-types/radio';\nexport type {RadioGroupState} from './useRadioGroupState';\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 {RadioGroupProps} from '@react-types/radio';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useState} from 'react';\nimport {ValidationState} from '@react-types/shared';\n\nexport interface RadioGroupState {\n /**\n * The name for the group, used for native form submission.\n * @deprecated\n * @private\n */\n readonly name: string,\n\n /** Whether the radio group is disabled. */\n readonly isDisabled: boolean,\n\n /** Whether the radio group is read only. */\n readonly isReadOnly: boolean,\n\n /** Whether the radio group is required. */\n readonly isRequired: boolean,\n\n /**\n * Whether the radio group is valid or invalid.\n * @deprecated Use `isInvalid` instead.\n */\n readonly validationState: ValidationState | null,\n\n /** Whether the radio group is invalid. */\n readonly isInvalid: boolean,\n\n /** The currently selected value. */\n readonly selectedValue: string | null,\n\n /** Sets the selected value. */\n setSelectedValue(value: string): void,\n\n /** The value of the last focused radio. */\n readonly lastFocusedValue: string | null,\n\n /** Sets the last focused value. */\n setLastFocusedValue(value: string): void\n}\n\nlet instance = Math.round(Math.random() * 10000000000);\nlet i = 0;\n\n/**\n * Provides state management for a radio group component. Provides a name for the group,\n * and manages selection and focus state.\n */\nexport function useRadioGroupState(props: RadioGroupProps): RadioGroupState {\n // Preserved here for backward compatibility. React Aria now generates the name instead of stately.\n let name = useMemo(() => props.name || `radio-group-${instance}-${++i}`, [props.name]);\n let [selectedValue, setSelected] = useControlledState(props.value, props.defaultValue, props.onChange);\n let [lastFocusedValue, setLastFocusedValue] = useState(null);\n\n let setSelectedValue = (value) => {\n if (!props.isReadOnly && !props.isDisabled) {\n setSelected(value);\n }\n };\n\n return {\n name,\n selectedValue,\n setSelectedValue,\n lastFocusedValue,\n setLastFocusedValue,\n isDisabled: props.isDisabled || false,\n isReadOnly: props.isReadOnly || false,\n isRequired: props.isRequired || false,\n validationState: props.validationState || null,\n isInvalid: props.isInvalid || props.validationState === 'invalid'\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;AA+CD,IAAI,iCAAW,KAAK,KAAK,CAAC,KAAK,MAAM,KAAK;AAC1C,IAAI,0BAAI;AAMD,SAAS,0CAAmB,KAAsB;IACvD,mGAAmG;IACnG,IAAI,OAAO,CAAA,GAAA,cAAM,EAAE,IAAM,MAAM,IAAI,IAAI,CAAC,YAAY,EAAE,+BAAS,CAAC,EAAE,EAAE,wBAAE,CAAC,EAAE;QAAC,MAAM,IAAI;KAAC;QAClB;IAAnE,IAAI,CAAC,eAAe,YAAY,GAAG,CAAA,GAAA,yBAAiB,EAAE,MAAM,KAAK,EAAE,CAAA,sBAAA,MAAM,YAAY,cAAlB,iCAAA,sBAAsB,MAAM,MAAM,QAAQ;IAC7G,IAAI,CAAC,kBAAkB,oBAAoB,GAAG,CAAA,GAAA,eAAO,EAAiB;IAEtE,IAAI,aAAa,CAAA,GAAA,6BAAqB,EAAE;QACtC,GAAG,KAAK;QACR,OAAO;IACT;IAEA,IAAI,mBAAmB,CAAC;QACtB,IAAI,CAAC,MAAM,UAAU,IAAI,CAAC,MAAM,UAAU,EAAE;YAC1C,YAAY;YACZ,WAAW,gBAAgB;QAC7B;IACF;IAEA,IAAI,YAAY,WAAW,iBAAiB,CAAC,SAAS;IAEtD,OAAO;QACL,GAAG,UAAU;cACb;QACA,eAAe;0BACf;0BACA;6BACA;QACA,YAAY,MAAM,UAAU,IAAI;QAChC,YAAY,MAAM,UAAU,IAAI;QAChC,YAAY,MAAM,UAAU,IAAI;QAChC,iBAAiB,MAAM,eAAe,IAAK,CAAA,YAAY,YAAY,IAAG;mBACtE;IACF;AACF;;CDvFC","sources":["packages/@react-stately/radio/src/index.ts","packages/@react-stately/radio/src/useRadioGroupState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useRadioGroupState} from './useRadioGroupState';\n\nexport type {RadioGroupProps} from '@react-types/radio';\nexport type {RadioGroupState} from './useRadioGroupState';\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 {FormValidationState, useFormValidationState} from '@react-stately/form';\nimport {RadioGroupProps} from '@react-types/radio';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useState} from 'react';\nimport {ValidationState} from '@react-types/shared';\n\nexport interface RadioGroupState extends FormValidationState {\n /**\n * The name for the group, used for native form submission.\n * @deprecated\n * @private\n */\n readonly name: string,\n\n /** Whether the radio group is disabled. */\n readonly isDisabled: boolean,\n\n /** Whether the radio group is read only. */\n readonly isReadOnly: boolean,\n\n /** Whether the radio group is required. */\n readonly isRequired: boolean,\n\n /**\n * Whether the radio group is valid or invalid.\n * @deprecated Use `isInvalid` instead.\n */\n readonly validationState: ValidationState | null,\n\n /** Whether the radio group is invalid. */\n readonly isInvalid: boolean,\n\n /** The currently selected value. */\n readonly selectedValue: string | null,\n\n /** Sets the selected value. */\n setSelectedValue(value: string | null): void,\n\n /** The value of the last focused radio. */\n readonly lastFocusedValue: string | null,\n\n /** Sets the last focused value. */\n setLastFocusedValue(value: string | null): void\n}\n\nlet instance = Math.round(Math.random() * 10000000000);\nlet i = 0;\n\n/**\n * Provides state management for a radio group component. Provides a name for the group,\n * and manages selection and focus state.\n */\nexport function useRadioGroupState(props: RadioGroupProps): RadioGroupState {\n // Preserved here for backward compatibility. React Aria now generates the name instead of stately.\n let name = useMemo(() => props.name || `radio-group-${instance}-${++i}`, [props.name]);\n let [selectedValue, setSelected] = useControlledState(props.value, props.defaultValue ?? null, props.onChange);\n let [lastFocusedValue, setLastFocusedValue] = useState<string | null>(null);\n\n let validation = useFormValidationState({\n ...props,\n value: selectedValue\n });\n\n let setSelectedValue = (value) => {\n if (!props.isReadOnly && !props.isDisabled) {\n setSelected(value);\n validation.commitValidation();\n }\n };\n\n let isInvalid = validation.displayValidation.isInvalid;\n\n return {\n ...validation,\n name,\n selectedValue: selectedValue,\n setSelectedValue,\n lastFocusedValue,\n setLastFocusedValue,\n isDisabled: props.isDisabled || false,\n isReadOnly: props.isReadOnly || false,\n isRequired: props.isRequired || false,\n validationState: props.validationState || (isInvalid ? 'invalid' : null),\n isInvalid\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -1,6 +1,7 @@
1
+ import { FormValidationState } from "@react-stately/form";
1
2
  import { RadioGroupProps } from "@react-types/radio";
2
3
  import { ValidationState } from "@react-types/shared";
3
- export interface RadioGroupState {
4
+ export interface RadioGroupState extends FormValidationState {
4
5
  /**
5
6
  * The name for the group, used for native form submission.
6
7
  * @deprecated
@@ -23,11 +24,11 @@ export interface RadioGroupState {
23
24
  /** The currently selected value. */
24
25
  readonly selectedValue: string | null;
25
26
  /** Sets the selected value. */
26
- setSelectedValue(value: string): void;
27
+ setSelectedValue(value: string | null): void;
27
28
  /** The value of the last focused radio. */
28
29
  readonly lastFocusedValue: string | null;
29
30
  /** Sets the last focused value. */
30
- setLastFocusedValue(value: string): void;
31
+ setLastFocusedValue(value: string | null): void;
31
32
  }
32
33
  /**
33
34
  * Provides state management for a radio group component. Provides a name for the group,
@@ -1 +1 @@
1
- {"mappings":";;AAiBA;IACE;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,2CAA2C;IAC3C,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B,4CAA4C;IAC5C,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B,2CAA2C;IAC3C,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B;;;OAGG;IACH,QAAQ,CAAC,eAAe,EAAE,eAAe,GAAG,IAAI,CAAC;IAEjD,0CAA0C;IAC1C,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAE5B,oCAAoC;IACpC,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtC,+BAA+B;IAC/B,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtC,2CAA2C;IAC3C,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAEzC,mCAAmC;IACnC,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CACzC;AAKD;;;GAGG;AACH,mCAAmC,KAAK,EAAE,eAAe,GAAG,eAAe,CAwB1E;ACzED,YAAY,EAAC,eAAe,EAAC,MAAM,oBAAoB,CAAC","sources":["packages/@react-stately/radio/src/packages/@react-stately/radio/src/useRadioGroupState.ts","packages/@react-stately/radio/src/packages/@react-stately/radio/src/index.ts","packages/@react-stately/radio/src/index.ts"],"sourcesContent":[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 */\n\nexport {useRadioGroupState} from './useRadioGroupState';\n\nexport type {RadioGroupProps} from '@react-types/radio';\nexport type {RadioGroupState} from './useRadioGroupState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;;AAkBA,gCAAiC,SAAQ,mBAAmB;IAC1D;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,2CAA2C;IAC3C,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B,4CAA4C;IAC5C,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B,2CAA2C;IAC3C,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B;;;OAGG;IACH,QAAQ,CAAC,eAAe,EAAE,eAAe,GAAG,IAAI,CAAC;IAEjD,0CAA0C;IAC1C,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAE5B,oCAAoC;IACpC,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtC,+BAA+B;IAC/B,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IAE7C,2CAA2C;IAC3C,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAEzC,mCAAmC;IACnC,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAA;CAChD;AAKD;;;GAGG;AACH,mCAAmC,KAAK,EAAE,eAAe,GAAG,eAAe,CAiC1E;ACnFD,YAAY,EAAC,eAAe,EAAC,MAAM,oBAAoB,CAAC","sources":["packages/@react-stately/radio/src/packages/@react-stately/radio/src/useRadioGroupState.ts","packages/@react-stately/radio/src/packages/@react-stately/radio/src/index.ts","packages/@react-stately/radio/src/index.ts"],"sourcesContent":[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 */\n\nexport {useRadioGroupState} from './useRadioGroupState';\n\nexport type {RadioGroupProps} from '@react-types/radio';\nexport type {RadioGroupState} from './useRadioGroupState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/radio",
3
- "version": "3.9.1",
3
+ "version": "3.10.1",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,9 +22,10 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-stately/utils": "^3.8.0",
26
- "@react-types/radio": "^3.5.2",
27
- "@react-types/shared": "^3.21.0",
25
+ "@react-stately/form": "^3.0.0",
26
+ "@react-stately/utils": "^3.9.0",
27
+ "@react-types/radio": "^3.7.0",
28
+ "@react-types/shared": "^3.22.0",
28
29
  "@swc/helpers": "^0.5.0"
29
30
  },
30
31
  "peerDependencies": {
@@ -33,5 +34,5 @@
33
34
  "publishConfig": {
34
35
  "access": "public"
35
36
  },
36
- "gitHead": "4122e44d1991c90507d630d35ed297f89db435d3"
37
+ "gitHead": "86b38c87868ce7f262e0df905e5ac4eb2653791d"
37
38
  }
@@ -10,12 +10,13 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
+ import {FormValidationState, useFormValidationState} from '@react-stately/form';
13
14
  import {RadioGroupProps} from '@react-types/radio';
14
15
  import {useControlledState} from '@react-stately/utils';
15
16
  import {useMemo, useState} from 'react';
16
17
  import {ValidationState} from '@react-types/shared';
17
18
 
18
- export interface RadioGroupState {
19
+ export interface RadioGroupState extends FormValidationState {
19
20
  /**
20
21
  * The name for the group, used for native form submission.
21
22
  * @deprecated
@@ -45,13 +46,13 @@ export interface RadioGroupState {
45
46
  readonly selectedValue: string | null,
46
47
 
47
48
  /** Sets the selected value. */
48
- setSelectedValue(value: string): void,
49
+ setSelectedValue(value: string | null): void,
49
50
 
50
51
  /** The value of the last focused radio. */
51
52
  readonly lastFocusedValue: string | null,
52
53
 
53
54
  /** Sets the last focused value. */
54
- setLastFocusedValue(value: string): void
55
+ setLastFocusedValue(value: string | null): void
55
56
  }
56
57
 
57
58
  let instance = Math.round(Math.random() * 10000000000);
@@ -64,25 +65,34 @@ let i = 0;
64
65
  export function useRadioGroupState(props: RadioGroupProps): RadioGroupState {
65
66
  // Preserved here for backward compatibility. React Aria now generates the name instead of stately.
66
67
  let name = useMemo(() => props.name || `radio-group-${instance}-${++i}`, [props.name]);
67
- let [selectedValue, setSelected] = useControlledState(props.value, props.defaultValue, props.onChange);
68
- let [lastFocusedValue, setLastFocusedValue] = useState(null);
68
+ let [selectedValue, setSelected] = useControlledState(props.value, props.defaultValue ?? null, props.onChange);
69
+ let [lastFocusedValue, setLastFocusedValue] = useState<string | null>(null);
70
+
71
+ let validation = useFormValidationState({
72
+ ...props,
73
+ value: selectedValue
74
+ });
69
75
 
70
76
  let setSelectedValue = (value) => {
71
77
  if (!props.isReadOnly && !props.isDisabled) {
72
78
  setSelected(value);
79
+ validation.commitValidation();
73
80
  }
74
81
  };
75
82
 
83
+ let isInvalid = validation.displayValidation.isInvalid;
84
+
76
85
  return {
86
+ ...validation,
77
87
  name,
78
- selectedValue,
88
+ selectedValue: selectedValue,
79
89
  setSelectedValue,
80
90
  lastFocusedValue,
81
91
  setLastFocusedValue,
82
92
  isDisabled: props.isDisabled || false,
83
93
  isReadOnly: props.isReadOnly || false,
84
94
  isRequired: props.isRequired || false,
85
- validationState: props.validationState || null,
86
- isInvalid: props.isInvalid || props.validationState === 'invalid'
95
+ validationState: props.validationState || (isInvalid ? 'invalid' : null),
96
+ isInvalid
87
97
  };
88
98
  }