@react-aria/checkbox 3.11.2 → 3.12.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,4 +1,6 @@
1
- import {useEffect as $cKEhs$useEffect} from "react";
1
+ import {useEffect as $cKEhs$useEffect, useRef as $cKEhs$useRef} from "react";
2
+ import {useFormValidation as $cKEhs$useFormValidation} from "@react-aria/form";
3
+ import {useFormValidationState as $cKEhs$useFormValidationState, DEFAULT_VALIDATION_RESULT as $cKEhs$DEFAULT_VALIDATION_RESULT, privateValidationStateProp as $cKEhs$privateValidationStateProp} from "@react-stately/form";
2
4
  import {useToggle as $cKEhs$useToggle} from "@react-aria/toggle";
3
5
  import {filterDOMProps as $cKEhs$filterDOMProps, mergeProps as $cKEhs$mergeProps} from "@react-aria/utils";
4
6
  import {useField as $cKEhs$useField} from "@react-aria/label";
@@ -26,9 +28,21 @@ import {useToggleState as $cKEhs$useToggleState} from "@react-stately/toggle";
26
28
  * governing permissions and limitations under the License.
27
29
  */
28
30
 
31
+
32
+
29
33
  function $406796ff087fe49b$export$e375f10ce42261c5(props, state, inputRef) {
30
- let { inputProps: inputProps, isSelected: isSelected, isPressed: isPressed, isDisabled: isDisabled, isReadOnly: isReadOnly, isInvalid: isInvalid } = (0, $cKEhs$useToggle)(props, state, inputRef);
31
- let { isIndeterminate: isIndeterminate } = props;
34
+ // Create validation state here because it doesn't make sense to add to general useToggleState.
35
+ let validationState = (0, $cKEhs$useFormValidationState)({
36
+ ...props,
37
+ value: state.isSelected
38
+ });
39
+ let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = validationState.displayValidation;
40
+ let { inputProps: inputProps, isSelected: isSelected, isPressed: isPressed, isDisabled: isDisabled, isReadOnly: isReadOnly } = (0, $cKEhs$useToggle)({
41
+ ...props,
42
+ isInvalid: isInvalid
43
+ }, state, inputRef);
44
+ (0, $cKEhs$useFormValidation)(props, validationState, inputRef);
45
+ let { isIndeterminate: isIndeterminate, isRequired: isRequired, validationBehavior: validationBehavior = "aria" } = props;
32
46
  (0, $cKEhs$useEffect)(()=>{
33
47
  // indeterminate is a property, but it can only be set via javascript
34
48
  // https://css-tricks.com/indeterminate-checkboxes/
@@ -37,13 +51,17 @@ function $406796ff087fe49b$export$e375f10ce42261c5(props, state, inputRef) {
37
51
  return {
38
52
  inputProps: {
39
53
  ...inputProps,
40
- checked: isSelected
54
+ checked: isSelected,
55
+ "aria-required": isRequired && validationBehavior === "aria" || undefined,
56
+ required: isRequired && validationBehavior === "native"
41
57
  },
42
58
  isSelected: isSelected,
43
59
  isPressed: isPressed,
44
60
  isDisabled: isDisabled,
45
61
  isReadOnly: isReadOnly,
46
- isInvalid: isInvalid
62
+ isInvalid: isInvalid,
63
+ validationErrors: validationErrors,
64
+ validationDetails: validationDetails
47
65
  };
48
66
  }
49
67
 
@@ -68,28 +86,31 @@ function $406796ff087fe49b$export$e375f10ce42261c5(props, state, inputRef) {
68
86
  * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
69
87
  * OF ANY KIND, either express or implied. See the License for the specific language
70
88
  * governing permissions and limitations under the License.
71
- */ const $1ae600c947479353$export$31440636951aa68c = new WeakMap();
72
- const $1ae600c947479353$export$a3077e9c93f7360f = new WeakMap();
73
- const $1ae600c947479353$export$d5679492e2864181 = new WeakMap();
89
+ */ const $1ae600c947479353$export$ec98120685d4f57d = new WeakMap();
74
90
 
75
91
 
76
92
 
77
93
 
78
94
  function $1e9fce0cfacc738b$export$49ff6f28c54f1cbe(props, state) {
79
- let { isDisabled: isDisabled, name: name } = props;
95
+ let { isDisabled: isDisabled, name: name, validationBehavior: validationBehavior = "aria" } = props;
96
+ let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
80
97
  let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $cKEhs$useField)({
81
98
  ...props,
82
99
  // Checkbox group is not an HTML input element so it
83
100
  // shouldn't be labeled by a <label> element.
84
- labelElementType: "span"
101
+ labelElementType: "span",
102
+ isInvalid: isInvalid,
103
+ errorMessage: props.errorMessage || validationErrors
104
+ });
105
+ (0, $1ae600c947479353$export$ec98120685d4f57d).set(state, {
106
+ name: name,
107
+ descriptionId: descriptionProps.id,
108
+ errorMessageId: errorMessageProps.id,
109
+ validationBehavior: validationBehavior
85
110
  });
86
- (0, $1ae600c947479353$export$a3077e9c93f7360f).set(state, descriptionProps.id);
87
- (0, $1ae600c947479353$export$d5679492e2864181).set(state, errorMessageProps.id);
88
111
  let domProps = (0, $cKEhs$filterDOMProps)(props, {
89
112
  labelable: true
90
113
  });
91
- // Pass name prop from group to all items by attaching to the state.
92
- (0, $1ae600c947479353$export$31440636951aa68c).set(state, name);
93
114
  return {
94
115
  groupProps: (0, $cKEhs$mergeProps)(domProps, {
95
116
  role: "group",
@@ -98,7 +119,10 @@ function $1e9fce0cfacc738b$export$49ff6f28c54f1cbe(props, state) {
98
119
  }),
99
120
  labelProps: labelProps,
100
121
  descriptionProps: descriptionProps,
101
- errorMessageProps: errorMessageProps
122
+ errorMessageProps: errorMessageProps,
123
+ isInvalid: isInvalid,
124
+ validationErrors: validationErrors,
125
+ validationDetails: validationDetails
102
126
  };
103
127
  }
104
128
 
@@ -116,6 +140,8 @@ function $1e9fce0cfacc738b$export$49ff6f28c54f1cbe(props, state) {
116
140
  */
117
141
 
118
142
 
143
+
144
+
119
145
  function $fba3e38d5ca8983f$export$353b32fc6898d37d(props, state, inputRef) {
120
146
  const toggleState = (0, $cKEhs$useToggleState)({
121
147
  isReadOnly: props.isReadOnly || state.isReadOnly,
@@ -126,11 +152,44 @@ function $fba3e38d5ca8983f$export$353b32fc6898d37d(props, state, inputRef) {
126
152
  if (props.onChange) props.onChange(isSelected);
127
153
  }
128
154
  });
155
+ let { name: name, descriptionId: descriptionId, errorMessageId: errorMessageId, validationBehavior: validationBehavior } = (0, $1ae600c947479353$export$ec98120685d4f57d).get(state);
156
+ var _props_validationBehavior;
157
+ validationBehavior = (_props_validationBehavior = props.validationBehavior) !== null && _props_validationBehavior !== void 0 ? _props_validationBehavior : validationBehavior;
158
+ // Local validation for this checkbox.
159
+ let { realtimeValidation: realtimeValidation } = (0, $cKEhs$useFormValidationState)({
160
+ ...props,
161
+ value: toggleState.isSelected,
162
+ // Server validation is handled at the group level.
163
+ name: undefined,
164
+ validationBehavior: "aria"
165
+ });
166
+ // Update the checkbox group state when realtime validation changes.
167
+ let nativeValidation = (0, $cKEhs$useRef)((0, $cKEhs$DEFAULT_VALIDATION_RESULT));
168
+ let updateValidation = ()=>{
169
+ state.setInvalid(props.value, realtimeValidation.isInvalid ? realtimeValidation : nativeValidation.current);
170
+ };
171
+ (0, $cKEhs$useEffect)(updateValidation);
172
+ // Combine group and checkbox level validation.
173
+ let combinedRealtimeValidation = state.realtimeValidation.isInvalid ? state.realtimeValidation : realtimeValidation;
174
+ let displayValidation = validationBehavior === "native" ? state.displayValidation : combinedRealtimeValidation;
175
+ var _props_isRequired;
129
176
  let res = (0, $406796ff087fe49b$export$e375f10ce42261c5)({
130
177
  ...props,
131
178
  isReadOnly: props.isReadOnly || state.isReadOnly,
132
179
  isDisabled: props.isDisabled || state.isDisabled,
133
- name: props.name || (0, $1ae600c947479353$export$31440636951aa68c).get(state)
180
+ name: props.name || name,
181
+ isRequired: (_props_isRequired = props.isRequired) !== null && _props_isRequired !== void 0 ? _props_isRequired : state.isRequired,
182
+ validationBehavior: validationBehavior,
183
+ [(0, $cKEhs$privateValidationStateProp)]: {
184
+ realtimeValidation: combinedRealtimeValidation,
185
+ displayValidation: displayValidation,
186
+ resetValidation: state.resetValidation,
187
+ commitValidation: state.commitValidation,
188
+ updateValidation (v) {
189
+ nativeValidation.current = v;
190
+ updateValidation();
191
+ }
192
+ }
134
193
  }, toggleState, inputRef);
135
194
  return {
136
195
  ...res,
@@ -138,8 +197,8 @@ function $fba3e38d5ca8983f$export$353b32fc6898d37d(props, state, inputRef) {
138
197
  ...res.inputProps,
139
198
  "aria-describedby": [
140
199
  props["aria-describedby"],
141
- state.isInvalid ? (0, $1ae600c947479353$export$d5679492e2864181).get(state) : null,
142
- (0, $1ae600c947479353$export$a3077e9c93f7360f).get(state)
200
+ state.isInvalid ? errorMessageId : null,
201
+ descriptionId
143
202
  ].filter(Boolean).join(" ") || undefined
144
203
  }
145
204
  };
package/dist/main.js CHANGED
@@ -1,9 +1,12 @@
1
1
  var $k0DcK$react = require("react");
2
+ var $k0DcK$reactariaform = require("@react-aria/form");
3
+ var $k0DcK$reactstatelyform = require("@react-stately/form");
2
4
  var $k0DcK$reactariatoggle = require("@react-aria/toggle");
3
5
  var $k0DcK$reactariautils = require("@react-aria/utils");
4
6
  var $k0DcK$reactarialabel = require("@react-aria/label");
5
7
  var $k0DcK$reactstatelytoggle = require("@react-stately/toggle");
6
8
 
9
+
7
10
  function $parcel$export(e, n, v, s) {
8
11
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
9
12
  }
@@ -33,9 +36,21 @@ $parcel$export(module.exports, "useCheckboxGroupItem", () => $07e03121d6ac83c8$e
33
36
  * governing permissions and limitations under the License.
34
37
  */
35
38
 
39
+
40
+
36
41
  function $468c774d7db917b7$export$e375f10ce42261c5(props, state, inputRef) {
37
- let { inputProps: inputProps, isSelected: isSelected, isPressed: isPressed, isDisabled: isDisabled, isReadOnly: isReadOnly, isInvalid: isInvalid } = (0, $k0DcK$reactariatoggle.useToggle)(props, state, inputRef);
38
- let { isIndeterminate: isIndeterminate } = props;
42
+ // Create validation state here because it doesn't make sense to add to general useToggleState.
43
+ let validationState = (0, $k0DcK$reactstatelyform.useFormValidationState)({
44
+ ...props,
45
+ value: state.isSelected
46
+ });
47
+ let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = validationState.displayValidation;
48
+ let { inputProps: inputProps, isSelected: isSelected, isPressed: isPressed, isDisabled: isDisabled, isReadOnly: isReadOnly } = (0, $k0DcK$reactariatoggle.useToggle)({
49
+ ...props,
50
+ isInvalid: isInvalid
51
+ }, state, inputRef);
52
+ (0, $k0DcK$reactariaform.useFormValidation)(props, validationState, inputRef);
53
+ let { isIndeterminate: isIndeterminate, isRequired: isRequired, validationBehavior: validationBehavior = "aria" } = props;
39
54
  (0, $k0DcK$react.useEffect)(()=>{
40
55
  // indeterminate is a property, but it can only be set via javascript
41
56
  // https://css-tricks.com/indeterminate-checkboxes/
@@ -44,13 +59,17 @@ function $468c774d7db917b7$export$e375f10ce42261c5(props, state, inputRef) {
44
59
  return {
45
60
  inputProps: {
46
61
  ...inputProps,
47
- checked: isSelected
62
+ checked: isSelected,
63
+ "aria-required": isRequired && validationBehavior === "aria" || undefined,
64
+ required: isRequired && validationBehavior === "native"
48
65
  },
49
66
  isSelected: isSelected,
50
67
  isPressed: isPressed,
51
68
  isDisabled: isDisabled,
52
69
  isReadOnly: isReadOnly,
53
- isInvalid: isInvalid
70
+ isInvalid: isInvalid,
71
+ validationErrors: validationErrors,
72
+ validationDetails: validationDetails
54
73
  };
55
74
  }
56
75
 
@@ -75,28 +94,31 @@ function $468c774d7db917b7$export$e375f10ce42261c5(props, state, inputRef) {
75
94
  * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
76
95
  * OF ANY KIND, either express or implied. See the License for the specific language
77
96
  * governing permissions and limitations under the License.
78
- */ const $64fc3370e682155f$export$31440636951aa68c = new WeakMap();
79
- const $64fc3370e682155f$export$a3077e9c93f7360f = new WeakMap();
80
- const $64fc3370e682155f$export$d5679492e2864181 = new WeakMap();
97
+ */ const $64fc3370e682155f$export$ec98120685d4f57d = new WeakMap();
81
98
 
82
99
 
83
100
 
84
101
 
85
102
  function $253685172d17db7d$export$49ff6f28c54f1cbe(props, state) {
86
- let { isDisabled: isDisabled, name: name } = props;
103
+ let { isDisabled: isDisabled, name: name, validationBehavior: validationBehavior = "aria" } = props;
104
+ let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
87
105
  let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $k0DcK$reactarialabel.useField)({
88
106
  ...props,
89
107
  // Checkbox group is not an HTML input element so it
90
108
  // shouldn't be labeled by a <label> element.
91
- labelElementType: "span"
109
+ labelElementType: "span",
110
+ isInvalid: isInvalid,
111
+ errorMessage: props.errorMessage || validationErrors
112
+ });
113
+ (0, $64fc3370e682155f$export$ec98120685d4f57d).set(state, {
114
+ name: name,
115
+ descriptionId: descriptionProps.id,
116
+ errorMessageId: errorMessageProps.id,
117
+ validationBehavior: validationBehavior
92
118
  });
93
- (0, $64fc3370e682155f$export$a3077e9c93f7360f).set(state, descriptionProps.id);
94
- (0, $64fc3370e682155f$export$d5679492e2864181).set(state, errorMessageProps.id);
95
119
  let domProps = (0, $k0DcK$reactariautils.filterDOMProps)(props, {
96
120
  labelable: true
97
121
  });
98
- // Pass name prop from group to all items by attaching to the state.
99
- (0, $64fc3370e682155f$export$31440636951aa68c).set(state, name);
100
122
  return {
101
123
  groupProps: (0, $k0DcK$reactariautils.mergeProps)(domProps, {
102
124
  role: "group",
@@ -105,7 +127,10 @@ function $253685172d17db7d$export$49ff6f28c54f1cbe(props, state) {
105
127
  }),
106
128
  labelProps: labelProps,
107
129
  descriptionProps: descriptionProps,
108
- errorMessageProps: errorMessageProps
130
+ errorMessageProps: errorMessageProps,
131
+ isInvalid: isInvalid,
132
+ validationErrors: validationErrors,
133
+ validationDetails: validationDetails
109
134
  };
110
135
  }
111
136
 
@@ -123,6 +148,8 @@ function $253685172d17db7d$export$49ff6f28c54f1cbe(props, state) {
123
148
  */
124
149
 
125
150
 
151
+
152
+
126
153
  function $07e03121d6ac83c8$export$353b32fc6898d37d(props, state, inputRef) {
127
154
  const toggleState = (0, $k0DcK$reactstatelytoggle.useToggleState)({
128
155
  isReadOnly: props.isReadOnly || state.isReadOnly,
@@ -133,11 +160,44 @@ function $07e03121d6ac83c8$export$353b32fc6898d37d(props, state, inputRef) {
133
160
  if (props.onChange) props.onChange(isSelected);
134
161
  }
135
162
  });
163
+ let { name: name, descriptionId: descriptionId, errorMessageId: errorMessageId, validationBehavior: validationBehavior } = (0, $64fc3370e682155f$export$ec98120685d4f57d).get(state);
164
+ var _props_validationBehavior;
165
+ validationBehavior = (_props_validationBehavior = props.validationBehavior) !== null && _props_validationBehavior !== void 0 ? _props_validationBehavior : validationBehavior;
166
+ // Local validation for this checkbox.
167
+ let { realtimeValidation: realtimeValidation } = (0, $k0DcK$reactstatelyform.useFormValidationState)({
168
+ ...props,
169
+ value: toggleState.isSelected,
170
+ // Server validation is handled at the group level.
171
+ name: undefined,
172
+ validationBehavior: "aria"
173
+ });
174
+ // Update the checkbox group state when realtime validation changes.
175
+ let nativeValidation = (0, $k0DcK$react.useRef)((0, $k0DcK$reactstatelyform.DEFAULT_VALIDATION_RESULT));
176
+ let updateValidation = ()=>{
177
+ state.setInvalid(props.value, realtimeValidation.isInvalid ? realtimeValidation : nativeValidation.current);
178
+ };
179
+ (0, $k0DcK$react.useEffect)(updateValidation);
180
+ // Combine group and checkbox level validation.
181
+ let combinedRealtimeValidation = state.realtimeValidation.isInvalid ? state.realtimeValidation : realtimeValidation;
182
+ let displayValidation = validationBehavior === "native" ? state.displayValidation : combinedRealtimeValidation;
183
+ var _props_isRequired;
136
184
  let res = (0, $468c774d7db917b7$export$e375f10ce42261c5)({
137
185
  ...props,
138
186
  isReadOnly: props.isReadOnly || state.isReadOnly,
139
187
  isDisabled: props.isDisabled || state.isDisabled,
140
- name: props.name || (0, $64fc3370e682155f$export$31440636951aa68c).get(state)
188
+ name: props.name || name,
189
+ isRequired: (_props_isRequired = props.isRequired) !== null && _props_isRequired !== void 0 ? _props_isRequired : state.isRequired,
190
+ validationBehavior: validationBehavior,
191
+ [(0, $k0DcK$reactstatelyform.privateValidationStateProp)]: {
192
+ realtimeValidation: combinedRealtimeValidation,
193
+ displayValidation: displayValidation,
194
+ resetValidation: state.resetValidation,
195
+ commitValidation: state.commitValidation,
196
+ updateValidation (v) {
197
+ nativeValidation.current = v;
198
+ updateValidation();
199
+ }
200
+ }
141
201
  }, toggleState, inputRef);
142
202
  return {
143
203
  ...res,
@@ -145,8 +205,8 @@ function $07e03121d6ac83c8$export$353b32fc6898d37d(props, state, inputRef) {
145
205
  ...res.inputProps,
146
206
  "aria-describedby": [
147
207
  props["aria-describedby"],
148
- state.isInvalid ? (0, $64fc3370e682155f$export$d5679492e2864181).get(state) : null,
149
- (0, $64fc3370e682155f$export$a3077e9c93f7360f).get(state)
208
+ state.isInvalid ? errorMessageId : null,
209
+ descriptionId
150
210
  ].filter(Boolean).join(" ") || undefined
151
211
  }
152
212
  };
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;AA8BM,SAAS,0CAAY,KAAwB,EAAE,KAAkB,EAAE,QAAqC;IAC7G,IAAI,cAAC,UAAU,cAAE,UAAU,aAAE,SAAS,cAAE,UAAU,cAAE,UAAU,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,gCAAQ,EAAE,OAAO,OAAO;IAErG,IAAI,mBAAC,eAAe,EAAC,GAAG;IACxB,CAAA,GAAA,sBAAQ,EAAE;QACR,qEAAqE;QACrE,mDAAmD;QACnD,IAAI,SAAS,SACX,SAAS,QAAQ,gBAAgB;IAErC;IAEA,OAAO;QACL,YAAY;YACV,GAAG,UAAU;YACb,SAAS;QACX;oBACA;mBACA;oBACA;oBACA;mBACA;IACF;AACF;;CDrDC;AEVD;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAIM,MAAM,4CAAqB,IAAI;AAC/B,MAAM,4CAA8B,IAAI;AACxC,MAAM,4CAA+B,IAAI;;CDN/C;;;AA0BM,SAAS,0CAAiB,KAA6B,EAAE,KAAyB;IACvF,IAAI,cAAC,UAAU,QAAE,IAAI,EAAC,GA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,CAAA,GAAA,yCAA0B,EAAE,IAAI;aACjC,CAAC,OAAO,SAAS,KAAK,QAAQ;QACjC;IACF;AACF;;","sources":["packages/@react-aria/checkbox/src/index.ts","packages/@react-aria/checkbox/src/useCheckbox.ts","packages/@react-aria/checkbox/src/useCheckboxGroup.ts","packages/@react-aria/checkbox/src/utils.ts","packages/@react-aria/checkbox/src/useCheckboxGroupItem.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 type {CheckboxAria} from './useCheckbox';\nexport {useCheckbox} from './useCheckbox';\nexport {useCheckboxGroup} from './useCheckboxGroup';\nexport {useCheckboxGroupItem} from './useCheckboxGroupItem';\nexport type {AriaCheckboxGroupItemProps, AriaCheckboxGroupProps, AriaCheckboxProps} from '@react-types/checkbox';\nexport type {CheckboxGroupAria} from './useCheckboxGroup';\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 {AriaCheckboxProps} from '@react-types/checkbox';\nimport {InputHTMLAttributes, RefObject, useEffect} from 'react';\nimport {ToggleState} from '@react-stately/toggle';\nimport {useToggle} from '@react-aria/toggle';\n\nexport interface CheckboxAria {\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Whether the checkbox is selected. */\n isSelected: boolean,\n /** Whether the checkbox is in a pressed state. */\n isPressed: boolean,\n /** Whether the checkbox is disabled. */\n isDisabled: boolean,\n /** Whether the checkbox is read only. */\n isReadOnly: boolean,\n /** Whether the checkbox is invalid. */\n isInvalid: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox component.\n * Checkboxes allow users to select multiple items from a list of individual items, or\n * to mark one individual item as selected.\n * @param props - Props for the checkbox.\n * @param state - State for the checkbox, as returned by `useToggleState`.\n * @param inputRef - A ref for the HTML input element.\n */\nexport function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {\n let {inputProps, isSelected, isPressed, isDisabled, isReadOnly, isInvalid} = useToggle(props, state, inputRef);\n\n let {isIndeterminate} = props;\n useEffect(() => {\n // indeterminate is a property, but it can only be set via javascript\n // https://css-tricks.com/indeterminate-checkboxes/\n if (inputRef.current) {\n inputRef.current.indeterminate = isIndeterminate;\n }\n });\n\n return {\n inputProps: {\n ...inputProps,\n checked: isSelected\n },\n isSelected,\n isPressed,\n isDisabled,\n isReadOnly,\n isInvalid\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 {AriaCheckboxGroupProps} from '@react-types/checkbox';\nimport {checkboxGroupDescriptionIds, checkboxGroupErrorMessageIds, checkboxGroupNames} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {useField} from '@react-aria/label';\n\nexport interface CheckboxGroupAria {\n /** Props for the checkbox group wrapper element. */\n groupProps: DOMAttributes,\n /** Props for the checkbox group's visible label (if any). */\n labelProps: DOMAttributes,\n /** Props for the checkbox group description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the checkbox group error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox group component.\n * Checkbox groups allow users to select multiple items from a list of options.\n * @param props - Props for the checkbox group.\n * @param state - State for the checkbox group, as returned by `useCheckboxGroupState`.\n */\nexport function useCheckboxGroup(props: AriaCheckboxGroupProps, state: CheckboxGroupState): CheckboxGroupAria {\n let {isDisabled, name} = props;\n\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n // Checkbox group is not an HTML input element so it\n // shouldn't be labeled by a <label> element.\n labelElementType: 'span'\n });\n checkboxGroupDescriptionIds.set(state, descriptionProps.id);\n checkboxGroupErrorMessageIds.set(state, errorMessageProps.id);\n\n let domProps = filterDOMProps(props, {labelable: true});\n\n // Pass name prop from group to all items by attaching to the state.\n checkboxGroupNames.set(state, name);\n\n return {\n groupProps: mergeProps(domProps, {\n role: 'group',\n 'aria-disabled': isDisabled || undefined,\n ...fieldProps\n }),\n labelProps,\n descriptionProps,\n errorMessageProps\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 {CheckboxGroupState} from '@react-stately/checkbox';\n\nexport const checkboxGroupNames = new WeakMap<CheckboxGroupState, string>();\nexport const checkboxGroupDescriptionIds = new WeakMap<CheckboxGroupState, string>();\nexport const checkboxGroupErrorMessageIds = new WeakMap<CheckboxGroupState, 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 {AriaCheckboxGroupItemProps} from '@react-types/checkbox';\nimport {CheckboxAria, useCheckbox} from './useCheckbox';\nimport {checkboxGroupDescriptionIds, checkboxGroupErrorMessageIds, checkboxGroupNames} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {RefObject} from 'react';\nimport {useToggleState} from '@react-stately/toggle';\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox component contained within a checkbox group.\n * Checkbox groups allow users to select multiple items from a list of options.\n * @param props - Props for the checkbox.\n * @param state - State for the checkbox, as returned by `useCheckboxGroupState`.\n * @param inputRef - A ref for the HTML input element.\n */\nexport function useCheckboxGroupItem(props: AriaCheckboxGroupItemProps, state: CheckboxGroupState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {\n const toggleState = useToggleState({\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isSelected: state.isSelected(props.value),\n onChange(isSelected) {\n if (isSelected) {\n state.addValue(props.value);\n } else {\n state.removeValue(props.value);\n }\n\n if (props.onChange) {\n props.onChange(isSelected);\n }\n }\n });\n\n let res = useCheckbox({\n ...props,\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isDisabled: props.isDisabled || state.isDisabled,\n name: props.name || checkboxGroupNames.get(state)\n }, toggleState, inputRef);\n\n return {\n ...res,\n inputProps: {\n ...res.inputProps,\n 'aria-describedby': [\n props['aria-describedby'],\n state.isInvalid ? checkboxGroupErrorMessageIds.get(state) : null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EAAE;QAChD,GAAG,KAAK;QACR,OAAO,YAAY,UAAU;QAC7B,mDAAmD;QACnD,MAAM;QACN,oBAAoB;IACtB;IAEA,oEAAoE;IACpE,IAAI,mBAAmB,CAAA,GAAA,mBAAK,EAAE,CAAA,GAAA,iDAAwB;IACtD,IAAI,mBAAmB;QACrB,MAAM,UAAU,CAAC,MAAM,KAAK,EAAE,mBAAmB,SAAS,GAAG,qBAAqB,iBAAiB,OAAO;IAC5G;IAEA,CAAA,GAAA,sBAAQ,EAAE;IAEV,+CAA+C;IAC/C,IAAI,6BAA6B,MAAM,kBAAkB,CAAC,SAAS,GAAG,MAAM,kBAAkB,GAAG;IACjG,IAAI,oBAAoB,uBAAuB,WAAW,MAAM,iBAAiB,GAAG;QAOtE;IALd,IAAI,MAAM,CAAA,GAAA,yCAAU,EAAE;QACpB,GAAG,KAAK;QACR,YAAY,MAAM,UAAU,IAAI,MAAM,UAAU;QAChD,YAAY,MAAM,UAAU,IAAI,MAAM,UAAU;QAChD,MAAM,MAAM,IAAI,IAAI;QACpB,YAAY,CAAA,oBAAA,MAAM,UAAU,cAAhB,+BAAA,oBAAoB,MAAM,UAAU;4BAChD;QACA,CAAC,CAAA,GAAA,kDAAyB,EAAE,EAAE;YAC5B,oBAAoB;+BACpB;YACA,iBAAiB,MAAM,eAAe;YACtC,kBAAkB,MAAM,gBAAgB;YACxC,kBAAiB,CAAC;gBAChB,iBAAiB,OAAO,GAAG;gBAC3B;YACF;QACF;IACF,GAAG,aAAa;IAEhB,OAAO;QACL,GAAG,GAAG;QACN,YAAY;YACV,GAAG,IAAI,UAAU;YACjB,oBAAoB;gBAClB,KAAK,CAAC,mBAAmB;gBACzB,MAAM,SAAS,GAAG,iBAAiB;gBACnC;aACD,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,QAAQ;QACjC;IACF;AACF;;","sources":["packages/@react-aria/checkbox/src/index.ts","packages/@react-aria/checkbox/src/useCheckbox.ts","packages/@react-aria/checkbox/src/useCheckboxGroup.ts","packages/@react-aria/checkbox/src/utils.ts","packages/@react-aria/checkbox/src/useCheckboxGroupItem.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 type {CheckboxAria} from './useCheckbox';\nexport {useCheckbox} from './useCheckbox';\nexport {useCheckboxGroup} from './useCheckboxGroup';\nexport {useCheckboxGroupItem} from './useCheckboxGroupItem';\nexport type {AriaCheckboxGroupItemProps, AriaCheckboxGroupProps, AriaCheckboxProps} from '@react-types/checkbox';\nexport type {CheckboxGroupAria} from './useCheckboxGroup';\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 {AriaCheckboxProps} from '@react-types/checkbox';\nimport {InputHTMLAttributes, RefObject, useEffect} from 'react';\nimport {ToggleState} from '@react-stately/toggle';\nimport {useFormValidation} from '@react-aria/form';\nimport {useFormValidationState} from '@react-stately/form';\nimport {useToggle} from '@react-aria/toggle';\nimport {ValidationResult} from '@react-types/shared';\n\nexport interface CheckboxAria extends ValidationResult {\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Whether the checkbox is selected. */\n isSelected: boolean,\n /** Whether the checkbox is in a pressed state. */\n isPressed: boolean,\n /** Whether the checkbox is disabled. */\n isDisabled: boolean,\n /** Whether the checkbox is read only. */\n isReadOnly: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox component.\n * Checkboxes allow users to select multiple items from a list of individual items, or\n * to mark one individual item as selected.\n * @param props - Props for the checkbox.\n * @param state - State for the checkbox, as returned by `useToggleState`.\n * @param inputRef - A ref for the HTML input element.\n */\nexport function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {\n // Create validation state here because it doesn't make sense to add to general useToggleState.\n let validationState = useFormValidationState({...props, value: state.isSelected});\n let {isInvalid, validationErrors, validationDetails} = validationState.displayValidation;\n let {inputProps, isSelected, isPressed, isDisabled, isReadOnly} = useToggle({\n ...props,\n isInvalid\n }, state, inputRef);\n\n useFormValidation(props, validationState, inputRef);\n\n let {isIndeterminate, isRequired, validationBehavior = 'aria'} = props;\n useEffect(() => {\n // indeterminate is a property, but it can only be set via javascript\n // https://css-tricks.com/indeterminate-checkboxes/\n if (inputRef.current) {\n inputRef.current.indeterminate = isIndeterminate;\n }\n });\n\n return {\n inputProps: {\n ...inputProps,\n checked: isSelected,\n 'aria-required': (isRequired && validationBehavior === 'aria') || undefined,\n required: isRequired && validationBehavior === 'native'\n },\n isSelected,\n isPressed,\n isDisabled,\n isReadOnly,\n isInvalid,\n validationErrors,\n validationDetails\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 {AriaCheckboxGroupProps} from '@react-types/checkbox';\nimport {checkboxGroupData} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {DOMAttributes, ValidationResult} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {useField} from '@react-aria/label';\n\nexport interface CheckboxGroupAria extends ValidationResult {\n /** Props for the checkbox group wrapper element. */\n groupProps: DOMAttributes,\n /** Props for the checkbox group's visible label (if any). */\n labelProps: DOMAttributes,\n /** Props for the checkbox group description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the checkbox group error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox group component.\n * Checkbox groups allow users to select multiple items from a list of options.\n * @param props - Props for the checkbox group.\n * @param state - State for the checkbox group, as returned by `useCheckboxGroupState`.\n */\nexport function useCheckboxGroup(props: AriaCheckboxGroupProps, state: CheckboxGroupState): CheckboxGroupAria {\n let {isDisabled, name, validationBehavior = 'aria'} = props;\n let {isInvalid, validationErrors, validationDetails} = state.displayValidation;\n\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n // Checkbox group is not an HTML input element so it\n // shouldn't be labeled by a <label> element.\n labelElementType: 'span',\n isInvalid,\n errorMessage: props.errorMessage || validationErrors\n });\n\n checkboxGroupData.set(state, {\n name,\n descriptionId: descriptionProps.id,\n errorMessageId: errorMessageProps.id,\n validationBehavior\n });\n\n let domProps = filterDOMProps(props, {labelable: true});\n\n return {\n groupProps: mergeProps(domProps, {\n role: 'group',\n 'aria-disabled': isDisabled || undefined,\n ...fieldProps\n }),\n labelProps,\n descriptionProps,\n errorMessageProps,\n isInvalid,\n validationErrors,\n validationDetails\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 {CheckboxGroupState} from '@react-stately/checkbox';\n\ninterface CheckboxGroupData {\n name: string,\n descriptionId: string,\n errorMessageId: string,\n validationBehavior: 'aria' | 'native'\n}\n\nexport const checkboxGroupData = new WeakMap<CheckboxGroupState, CheckboxGroupData>();\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 {AriaCheckboxGroupItemProps} from '@react-types/checkbox';\nimport {CheckboxAria, useCheckbox} from './useCheckbox';\nimport {checkboxGroupData} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {DEFAULT_VALIDATION_RESULT, privateValidationStateProp, useFormValidationState} from '@react-stately/form';\nimport {RefObject, useEffect, useRef} from 'react';\nimport {useToggleState} from '@react-stately/toggle';\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox component contained within a checkbox group.\n * Checkbox groups allow users to select multiple items from a list of options.\n * @param props - Props for the checkbox.\n * @param state - State for the checkbox, as returned by `useCheckboxGroupState`.\n * @param inputRef - A ref for the HTML input element.\n */\nexport function useCheckboxGroupItem(props: AriaCheckboxGroupItemProps, state: CheckboxGroupState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {\n const toggleState = useToggleState({\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isSelected: state.isSelected(props.value),\n onChange(isSelected) {\n if (isSelected) {\n state.addValue(props.value);\n } else {\n state.removeValue(props.value);\n }\n\n if (props.onChange) {\n props.onChange(isSelected);\n }\n }\n });\n\n let {name, descriptionId, errorMessageId, validationBehavior} = checkboxGroupData.get(state)!;\n validationBehavior = props.validationBehavior ?? validationBehavior;\n\n // Local validation for this checkbox.\n let {realtimeValidation} = useFormValidationState({\n ...props,\n value: toggleState.isSelected,\n // Server validation is handled at the group level.\n name: undefined,\n validationBehavior: 'aria'\n });\n\n // Update the checkbox group state when realtime validation changes.\n let nativeValidation = useRef(DEFAULT_VALIDATION_RESULT);\n let updateValidation = () => {\n state.setInvalid(props.value, realtimeValidation.isInvalid ? realtimeValidation : nativeValidation.current);\n };\n\n useEffect(updateValidation);\n\n // Combine group and checkbox level validation.\n let combinedRealtimeValidation = state.realtimeValidation.isInvalid ? state.realtimeValidation : realtimeValidation;\n let displayValidation = validationBehavior === 'native' ? state.displayValidation : combinedRealtimeValidation;\n\n let res = useCheckbox({\n ...props,\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isDisabled: props.isDisabled || state.isDisabled,\n name: props.name || name,\n isRequired: props.isRequired ?? state.isRequired,\n validationBehavior,\n [privateValidationStateProp]: {\n realtimeValidation: combinedRealtimeValidation,\n displayValidation,\n resetValidation: state.resetValidation,\n commitValidation: state.commitValidation,\n updateValidation(v) {\n nativeValidation.current = v;\n updateValidation();\n }\n }\n }, toggleState, inputRef);\n\n return {\n ...res,\n inputProps: {\n ...res.inputProps,\n 'aria-describedby': [\n props['aria-describedby'],\n state.isInvalid ? errorMessageId : null,\n descriptionId\n ].filter(Boolean).join(' ') || undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,4 +1,6 @@
1
- import {useEffect as $cKEhs$useEffect} from "react";
1
+ import {useEffect as $cKEhs$useEffect, useRef as $cKEhs$useRef} from "react";
2
+ import {useFormValidation as $cKEhs$useFormValidation} from "@react-aria/form";
3
+ import {useFormValidationState as $cKEhs$useFormValidationState, DEFAULT_VALIDATION_RESULT as $cKEhs$DEFAULT_VALIDATION_RESULT, privateValidationStateProp as $cKEhs$privateValidationStateProp} from "@react-stately/form";
2
4
  import {useToggle as $cKEhs$useToggle} from "@react-aria/toggle";
3
5
  import {filterDOMProps as $cKEhs$filterDOMProps, mergeProps as $cKEhs$mergeProps} from "@react-aria/utils";
4
6
  import {useField as $cKEhs$useField} from "@react-aria/label";
@@ -26,9 +28,21 @@ import {useToggleState as $cKEhs$useToggleState} from "@react-stately/toggle";
26
28
  * governing permissions and limitations under the License.
27
29
  */
28
30
 
31
+
32
+
29
33
  function $406796ff087fe49b$export$e375f10ce42261c5(props, state, inputRef) {
30
- let { inputProps: inputProps, isSelected: isSelected, isPressed: isPressed, isDisabled: isDisabled, isReadOnly: isReadOnly, isInvalid: isInvalid } = (0, $cKEhs$useToggle)(props, state, inputRef);
31
- let { isIndeterminate: isIndeterminate } = props;
34
+ // Create validation state here because it doesn't make sense to add to general useToggleState.
35
+ let validationState = (0, $cKEhs$useFormValidationState)({
36
+ ...props,
37
+ value: state.isSelected
38
+ });
39
+ let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = validationState.displayValidation;
40
+ let { inputProps: inputProps, isSelected: isSelected, isPressed: isPressed, isDisabled: isDisabled, isReadOnly: isReadOnly } = (0, $cKEhs$useToggle)({
41
+ ...props,
42
+ isInvalid: isInvalid
43
+ }, state, inputRef);
44
+ (0, $cKEhs$useFormValidation)(props, validationState, inputRef);
45
+ let { isIndeterminate: isIndeterminate, isRequired: isRequired, validationBehavior: validationBehavior = "aria" } = props;
32
46
  (0, $cKEhs$useEffect)(()=>{
33
47
  // indeterminate is a property, but it can only be set via javascript
34
48
  // https://css-tricks.com/indeterminate-checkboxes/
@@ -37,13 +51,17 @@ function $406796ff087fe49b$export$e375f10ce42261c5(props, state, inputRef) {
37
51
  return {
38
52
  inputProps: {
39
53
  ...inputProps,
40
- checked: isSelected
54
+ checked: isSelected,
55
+ "aria-required": isRequired && validationBehavior === "aria" || undefined,
56
+ required: isRequired && validationBehavior === "native"
41
57
  },
42
58
  isSelected: isSelected,
43
59
  isPressed: isPressed,
44
60
  isDisabled: isDisabled,
45
61
  isReadOnly: isReadOnly,
46
- isInvalid: isInvalid
62
+ isInvalid: isInvalid,
63
+ validationErrors: validationErrors,
64
+ validationDetails: validationDetails
47
65
  };
48
66
  }
49
67
 
@@ -68,28 +86,31 @@ function $406796ff087fe49b$export$e375f10ce42261c5(props, state, inputRef) {
68
86
  * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
69
87
  * OF ANY KIND, either express or implied. See the License for the specific language
70
88
  * governing permissions and limitations under the License.
71
- */ const $1ae600c947479353$export$31440636951aa68c = new WeakMap();
72
- const $1ae600c947479353$export$a3077e9c93f7360f = new WeakMap();
73
- const $1ae600c947479353$export$d5679492e2864181 = new WeakMap();
89
+ */ const $1ae600c947479353$export$ec98120685d4f57d = new WeakMap();
74
90
 
75
91
 
76
92
 
77
93
 
78
94
  function $1e9fce0cfacc738b$export$49ff6f28c54f1cbe(props, state) {
79
- let { isDisabled: isDisabled, name: name } = props;
95
+ let { isDisabled: isDisabled, name: name, validationBehavior: validationBehavior = "aria" } = props;
96
+ let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
80
97
  let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $cKEhs$useField)({
81
98
  ...props,
82
99
  // Checkbox group is not an HTML input element so it
83
100
  // shouldn't be labeled by a <label> element.
84
- labelElementType: "span"
101
+ labelElementType: "span",
102
+ isInvalid: isInvalid,
103
+ errorMessage: props.errorMessage || validationErrors
104
+ });
105
+ (0, $1ae600c947479353$export$ec98120685d4f57d).set(state, {
106
+ name: name,
107
+ descriptionId: descriptionProps.id,
108
+ errorMessageId: errorMessageProps.id,
109
+ validationBehavior: validationBehavior
85
110
  });
86
- (0, $1ae600c947479353$export$a3077e9c93f7360f).set(state, descriptionProps.id);
87
- (0, $1ae600c947479353$export$d5679492e2864181).set(state, errorMessageProps.id);
88
111
  let domProps = (0, $cKEhs$filterDOMProps)(props, {
89
112
  labelable: true
90
113
  });
91
- // Pass name prop from group to all items by attaching to the state.
92
- (0, $1ae600c947479353$export$31440636951aa68c).set(state, name);
93
114
  return {
94
115
  groupProps: (0, $cKEhs$mergeProps)(domProps, {
95
116
  role: "group",
@@ -98,7 +119,10 @@ function $1e9fce0cfacc738b$export$49ff6f28c54f1cbe(props, state) {
98
119
  }),
99
120
  labelProps: labelProps,
100
121
  descriptionProps: descriptionProps,
101
- errorMessageProps: errorMessageProps
122
+ errorMessageProps: errorMessageProps,
123
+ isInvalid: isInvalid,
124
+ validationErrors: validationErrors,
125
+ validationDetails: validationDetails
102
126
  };
103
127
  }
104
128
 
@@ -116,6 +140,8 @@ function $1e9fce0cfacc738b$export$49ff6f28c54f1cbe(props, state) {
116
140
  */
117
141
 
118
142
 
143
+
144
+
119
145
  function $fba3e38d5ca8983f$export$353b32fc6898d37d(props, state, inputRef) {
120
146
  const toggleState = (0, $cKEhs$useToggleState)({
121
147
  isReadOnly: props.isReadOnly || state.isReadOnly,
@@ -126,11 +152,44 @@ function $fba3e38d5ca8983f$export$353b32fc6898d37d(props, state, inputRef) {
126
152
  if (props.onChange) props.onChange(isSelected);
127
153
  }
128
154
  });
155
+ let { name: name, descriptionId: descriptionId, errorMessageId: errorMessageId, validationBehavior: validationBehavior } = (0, $1ae600c947479353$export$ec98120685d4f57d).get(state);
156
+ var _props_validationBehavior;
157
+ validationBehavior = (_props_validationBehavior = props.validationBehavior) !== null && _props_validationBehavior !== void 0 ? _props_validationBehavior : validationBehavior;
158
+ // Local validation for this checkbox.
159
+ let { realtimeValidation: realtimeValidation } = (0, $cKEhs$useFormValidationState)({
160
+ ...props,
161
+ value: toggleState.isSelected,
162
+ // Server validation is handled at the group level.
163
+ name: undefined,
164
+ validationBehavior: "aria"
165
+ });
166
+ // Update the checkbox group state when realtime validation changes.
167
+ let nativeValidation = (0, $cKEhs$useRef)((0, $cKEhs$DEFAULT_VALIDATION_RESULT));
168
+ let updateValidation = ()=>{
169
+ state.setInvalid(props.value, realtimeValidation.isInvalid ? realtimeValidation : nativeValidation.current);
170
+ };
171
+ (0, $cKEhs$useEffect)(updateValidation);
172
+ // Combine group and checkbox level validation.
173
+ let combinedRealtimeValidation = state.realtimeValidation.isInvalid ? state.realtimeValidation : realtimeValidation;
174
+ let displayValidation = validationBehavior === "native" ? state.displayValidation : combinedRealtimeValidation;
175
+ var _props_isRequired;
129
176
  let res = (0, $406796ff087fe49b$export$e375f10ce42261c5)({
130
177
  ...props,
131
178
  isReadOnly: props.isReadOnly || state.isReadOnly,
132
179
  isDisabled: props.isDisabled || state.isDisabled,
133
- name: props.name || (0, $1ae600c947479353$export$31440636951aa68c).get(state)
180
+ name: props.name || name,
181
+ isRequired: (_props_isRequired = props.isRequired) !== null && _props_isRequired !== void 0 ? _props_isRequired : state.isRequired,
182
+ validationBehavior: validationBehavior,
183
+ [(0, $cKEhs$privateValidationStateProp)]: {
184
+ realtimeValidation: combinedRealtimeValidation,
185
+ displayValidation: displayValidation,
186
+ resetValidation: state.resetValidation,
187
+ commitValidation: state.commitValidation,
188
+ updateValidation (v) {
189
+ nativeValidation.current = v;
190
+ updateValidation();
191
+ }
192
+ }
134
193
  }, toggleState, inputRef);
135
194
  return {
136
195
  ...res,
@@ -138,8 +197,8 @@ function $fba3e38d5ca8983f$export$353b32fc6898d37d(props, state, inputRef) {
138
197
  ...res.inputProps,
139
198
  "aria-describedby": [
140
199
  props["aria-describedby"],
141
- state.isInvalid ? (0, $1ae600c947479353$export$d5679492e2864181).get(state) : null,
142
- (0, $1ae600c947479353$export$a3077e9c93f7360f).get(state)
200
+ state.isInvalid ? errorMessageId : null,
201
+ descriptionId
143
202
  ].filter(Boolean).join(" ") || undefined
144
203
  }
145
204
  };
@@ -1 +1 @@
1
- {"mappings":";;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;AA8BM,SAAS,0CAAY,KAAwB,EAAE,KAAkB,EAAE,QAAqC;IAC7G,IAAI,cAAC,UAAU,cAAE,U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AA,qBAAa,EAAE;QACjC,YAAY,MAAM,cAAc,MAAM;QACtC,YAAY,MAAM,WAAW,MAAM;QACnC,UAAS,UAAU;YACjB,IAAI,YACF,MAAM,SAAS,MAAM;iBAErB,MAAM,YAAY,MAAM;YAG1B,IAAI,MAAM,UACR,MAAM,SAAS;QAEnB;IACF;IAEA,IAAI,MAAM,CAAA,GAAA,yCAAU,EAAE;QACpB,GAAG,KAAK;QACR,YAAY,MAAM,cAAc,MAAM;QACtC,YAAY,MAAM,cAAc,MAAM;QACtC,MAAM,MAAM,QAAQ,CAAA,GAAA,yCAAiB,EAAE,IAAI;IAC7C,GAAG,aAAa;IAEhB,OAAO;QACL,GAAG,GAAG;QACN,YAAY;YACV,GAAG,IAAI,UAAU;YACjB,oBAAoB;gBAClB,KAAK,CAAC,mBAAmB;gBACzB,MAAM,YAAY,CAAA,GAAA,yCAA2B,EAAE,IAAI,SAAS;gBAC5D,CAAA,GAAA,yCAA0B,EAAE,IAAI;aACjC,CAAC,OAAO,SAAS,KAAK,QAAQ;QACjC;IACF;AACF;;","sources":["packages/@react-aria/checkbox/src/index.ts","packages/@react-aria/checkbox/src/useCheckbox.ts","packages/@react-aria/checkbox/src/useCheckboxGroup.ts","packages/@react-aria/checkbox/src/utils.ts","packages/@react-aria/checkbox/src/useCheckboxGroupItem.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 type {CheckboxAria} from './useCheckbox';\nexport {useCheckbox} from './useCheckbox';\nexport {useCheckboxGroup} from './useCheckboxGroup';\nexport {useCheckboxGroupItem} from './useCheckboxGroupItem';\nexport type {AriaCheckboxGroupItemProps, AriaCheckboxGroupProps, AriaCheckboxProps} from '@react-types/checkbox';\nexport type {CheckboxGroupAria} from './useCheckboxGroup';\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 {AriaCheckboxProps} from '@react-types/checkbox';\nimport {InputHTMLAttributes, RefObject, useEffect} from 'react';\nimport {ToggleState} from '@react-stately/toggle';\nimport {useToggle} from '@react-aria/toggle';\n\nexport interface CheckboxAria {\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Whether the checkbox is selected. */\n isSelected: boolean,\n /** Whether the checkbox is in a pressed state. */\n isPressed: boolean,\n /** Whether the checkbox is disabled. */\n isDisabled: boolean,\n /** Whether the checkbox is read only. */\n isReadOnly: boolean,\n /** Whether the checkbox is invalid. */\n isInvalid: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox component.\n * Checkboxes allow users to select multiple items from a list of individual items, or\n * to mark one individual item as selected.\n * @param props - Props for the checkbox.\n * @param state - State for the checkbox, as returned by `useToggleState`.\n * @param inputRef - A ref for the HTML input element.\n */\nexport function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {\n let {inputProps, isSelected, isPressed, isDisabled, isReadOnly, isInvalid} = useToggle(props, state, inputRef);\n\n let {isIndeterminate} = props;\n useEffect(() => {\n // indeterminate is a property, but it can only be set via javascript\n // https://css-tricks.com/indeterminate-checkboxes/\n if (inputRef.current) {\n inputRef.current.indeterminate = isIndeterminate;\n }\n });\n\n return {\n inputProps: {\n ...inputProps,\n checked: isSelected\n },\n isSelected,\n isPressed,\n isDisabled,\n isReadOnly,\n isInvalid\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 {AriaCheckboxGroupProps} from '@react-types/checkbox';\nimport {checkboxGroupDescriptionIds, checkboxGroupErrorMessageIds, checkboxGroupNames} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {useField} from '@react-aria/label';\n\nexport interface CheckboxGroupAria {\n /** Props for the checkbox group wrapper element. */\n groupProps: DOMAttributes,\n /** Props for the checkbox group's visible label (if any). */\n labelProps: DOMAttributes,\n /** Props for the checkbox group description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the checkbox group error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox group component.\n * Checkbox groups allow users to select multiple items from a list of options.\n * @param props - Props for the checkbox group.\n * @param state - State for the checkbox group, as returned by `useCheckboxGroupState`.\n */\nexport function useCheckboxGroup(props: AriaCheckboxGroupProps, state: CheckboxGroupState): CheckboxGroupAria {\n let {isDisabled, name} = props;\n\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n // Checkbox group is not an HTML input element so it\n // shouldn't be labeled by a <label> element.\n labelElementType: 'span'\n });\n checkboxGroupDescriptionIds.set(state, descriptionProps.id);\n checkboxGroupErrorMessageIds.set(state, errorMessageProps.id);\n\n let domProps = filterDOMProps(props, {labelable: true});\n\n // Pass name prop from group to all items by attaching to the state.\n checkboxGroupNames.set(state, name);\n\n return {\n groupProps: mergeProps(domProps, {\n role: 'group',\n 'aria-disabled': isDisabled || undefined,\n ...fieldProps\n }),\n labelProps,\n descriptionProps,\n errorMessageProps\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 {CheckboxGroupState} from '@react-stately/checkbox';\n\nexport const checkboxGroupNames = new WeakMap<CheckboxGroupState, string>();\nexport const checkboxGroupDescriptionIds = new WeakMap<CheckboxGroupState, string>();\nexport const checkboxGroupErrorMessageIds = new WeakMap<CheckboxGroupState, 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 {AriaCheckboxGroupItemProps} from '@react-types/checkbox';\nimport {CheckboxAria, useCheckbox} from './useCheckbox';\nimport {checkboxGroupDescriptionIds, checkboxGroupErrorMessageIds, checkboxGroupNames} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {RefObject} from 'react';\nimport {useToggleState} from '@react-stately/toggle';\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox component contained within a checkbox group.\n * Checkbox groups allow users to select multiple items from a list of options.\n * @param props - Props for the checkbox.\n * @param state - State for the checkbox, as returned by `useCheckboxGroupState`.\n * @param inputRef - A ref for the HTML input element.\n */\nexport function useCheckboxGroupItem(props: AriaCheckboxGroupItemProps, state: CheckboxGroupState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {\n const toggleState = useToggleState({\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isSelected: state.isSelected(props.value),\n onChange(isSelected) {\n if (isSelected) {\n state.addValue(props.value);\n } else {\n state.removeValue(props.value);\n }\n\n if (props.onChange) {\n props.onChange(isSelected);\n }\n }\n });\n\n let res = useCheckbox({\n ...props,\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isDisabled: props.isDisabled || state.isDisabled,\n name: props.name || checkboxGroupNames.get(state)\n }, toggleState, inputRef);\n\n return {\n ...res,\n inputProps: {\n ...res.inputProps,\n 'aria-describedby': [\n props['aria-describedby'],\n state.isInvalid ? checkboxGroupErrorMessageIds.get(state) : null,\n checkboxGroupDescriptionIds.get(state)\n ].filter(Boolean).join(' ') || undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;;AA+BM,SAAS,0CAAY,KAAwB,EAAE,KAAkB,EAAE,QAAqC;IAC7G,+FAA+F;IAC/F,IAAI,kBAAkB,CAAA,GAAA,6BAAqB,EAAE;QAAC,GAAG,KAAK;QAAE,OAAO,MAAM,UAAU;IAAA;IAC/E,IAAI,aAAC,SAAS,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,gBAAgB,iBAAiB;IACxF,IAAI,cAAC,UAAU,cAAE,UAAU,aAAE,SAAS,cAAE,UAAU,cAAE,UAAU,EAAC,GAAG,CAAA,GAAA,gBAAQ,EAAE;QAC1E,GAAG,KAAK;mBACR;IACF,GAAG,OAAO;IAEV,CAAA,GAAA,wBAAgB,EAAE,OAAO,iBAAiB;IAE1C,IAAI,mBAAC,eAAe,cAAE,UAAU,sBAAE,qBAA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AM,UAAU,cAAhB,+BAAA,oBAAoB,MAAM,UAAU;4BAChD;QACA,CAAC,CAAA,GAAA,iCAAyB,EAAE,EAAE;YAC5B,oBAAoB;+BACpB;YACA,iBAAiB,MAAM,eAAe;YACtC,kBAAkB,MAAM,gBAAgB;YACxC,kBAAiB,CAAC;gBAChB,iBAAiB,OAAO,GAAG;gBAC3B;YACF;QACF;IACF,GAAG,aAAa;IAEhB,OAAO;QACL,GAAG,GAAG;QACN,YAAY;YACV,GAAG,IAAI,UAAU;YACjB,oBAAoB;gBAClB,KAAK,CAAC,mBAAmB;gBACzB,MAAM,SAAS,GAAG,iBAAiB;gBACnC;aACD,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,QAAQ;QACjC;IACF;AACF;;","sources":["packages/@react-aria/checkbox/src/index.ts","packages/@react-aria/checkbox/src/useCheckbox.ts","packages/@react-aria/checkbox/src/useCheckboxGroup.ts","packages/@react-aria/checkbox/src/utils.ts","packages/@react-aria/checkbox/src/useCheckboxGroupItem.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 type {CheckboxAria} from './useCheckbox';\nexport {useCheckbox} from './useCheckbox';\nexport {useCheckboxGroup} from './useCheckboxGroup';\nexport {useCheckboxGroupItem} from './useCheckboxGroupItem';\nexport type {AriaCheckboxGroupItemProps, AriaCheckboxGroupProps, AriaCheckboxProps} from '@react-types/checkbox';\nexport type {CheckboxGroupAria} from './useCheckboxGroup';\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 {AriaCheckboxProps} from '@react-types/checkbox';\nimport {InputHTMLAttributes, RefObject, useEffect} from 'react';\nimport {ToggleState} from '@react-stately/toggle';\nimport {useFormValidation} from '@react-aria/form';\nimport {useFormValidationState} from '@react-stately/form';\nimport {useToggle} from '@react-aria/toggle';\nimport {ValidationResult} from '@react-types/shared';\n\nexport interface CheckboxAria extends ValidationResult {\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Whether the checkbox is selected. */\n isSelected: boolean,\n /** Whether the checkbox is in a pressed state. */\n isPressed: boolean,\n /** Whether the checkbox is disabled. */\n isDisabled: boolean,\n /** Whether the checkbox is read only. */\n isReadOnly: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox component.\n * Checkboxes allow users to select multiple items from a list of individual items, or\n * to mark one individual item as selected.\n * @param props - Props for the checkbox.\n * @param state - State for the checkbox, as returned by `useToggleState`.\n * @param inputRef - A ref for the HTML input element.\n */\nexport function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {\n // Create validation state here because it doesn't make sense to add to general useToggleState.\n let validationState = useFormValidationState({...props, value: state.isSelected});\n let {isInvalid, validationErrors, validationDetails} = validationState.displayValidation;\n let {inputProps, isSelected, isPressed, isDisabled, isReadOnly} = useToggle({\n ...props,\n isInvalid\n }, state, inputRef);\n\n useFormValidation(props, validationState, inputRef);\n\n let {isIndeterminate, isRequired, validationBehavior = 'aria'} = props;\n useEffect(() => {\n // indeterminate is a property, but it can only be set via javascript\n // https://css-tricks.com/indeterminate-checkboxes/\n if (inputRef.current) {\n inputRef.current.indeterminate = isIndeterminate;\n }\n });\n\n return {\n inputProps: {\n ...inputProps,\n checked: isSelected,\n 'aria-required': (isRequired && validationBehavior === 'aria') || undefined,\n required: isRequired && validationBehavior === 'native'\n },\n isSelected,\n isPressed,\n isDisabled,\n isReadOnly,\n isInvalid,\n validationErrors,\n validationDetails\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 {AriaCheckboxGroupProps} from '@react-types/checkbox';\nimport {checkboxGroupData} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {DOMAttributes, ValidationResult} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {useField} from '@react-aria/label';\n\nexport interface CheckboxGroupAria extends ValidationResult {\n /** Props for the checkbox group wrapper element. */\n groupProps: DOMAttributes,\n /** Props for the checkbox group's visible label (if any). */\n labelProps: DOMAttributes,\n /** Props for the checkbox group description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the checkbox group error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox group component.\n * Checkbox groups allow users to select multiple items from a list of options.\n * @param props - Props for the checkbox group.\n * @param state - State for the checkbox group, as returned by `useCheckboxGroupState`.\n */\nexport function useCheckboxGroup(props: AriaCheckboxGroupProps, state: CheckboxGroupState): CheckboxGroupAria {\n let {isDisabled, name, validationBehavior = 'aria'} = props;\n let {isInvalid, validationErrors, validationDetails} = state.displayValidation;\n\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n // Checkbox group is not an HTML input element so it\n // shouldn't be labeled by a <label> element.\n labelElementType: 'span',\n isInvalid,\n errorMessage: props.errorMessage || validationErrors\n });\n\n checkboxGroupData.set(state, {\n name,\n descriptionId: descriptionProps.id,\n errorMessageId: errorMessageProps.id,\n validationBehavior\n });\n\n let domProps = filterDOMProps(props, {labelable: true});\n\n return {\n groupProps: mergeProps(domProps, {\n role: 'group',\n 'aria-disabled': isDisabled || undefined,\n ...fieldProps\n }),\n labelProps,\n descriptionProps,\n errorMessageProps,\n isInvalid,\n validationErrors,\n validationDetails\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 {CheckboxGroupState} from '@react-stately/checkbox';\n\ninterface CheckboxGroupData {\n name: string,\n descriptionId: string,\n errorMessageId: string,\n validationBehavior: 'aria' | 'native'\n}\n\nexport const checkboxGroupData = new WeakMap<CheckboxGroupState, CheckboxGroupData>();\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 {AriaCheckboxGroupItemProps} from '@react-types/checkbox';\nimport {CheckboxAria, useCheckbox} from './useCheckbox';\nimport {checkboxGroupData} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {DEFAULT_VALIDATION_RESULT, privateValidationStateProp, useFormValidationState} from '@react-stately/form';\nimport {RefObject, useEffect, useRef} from 'react';\nimport {useToggleState} from '@react-stately/toggle';\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox component contained within a checkbox group.\n * Checkbox groups allow users to select multiple items from a list of options.\n * @param props - Props for the checkbox.\n * @param state - State for the checkbox, as returned by `useCheckboxGroupState`.\n * @param inputRef - A ref for the HTML input element.\n */\nexport function useCheckboxGroupItem(props: AriaCheckboxGroupItemProps, state: CheckboxGroupState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {\n const toggleState = useToggleState({\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isSelected: state.isSelected(props.value),\n onChange(isSelected) {\n if (isSelected) {\n state.addValue(props.value);\n } else {\n state.removeValue(props.value);\n }\n\n if (props.onChange) {\n props.onChange(isSelected);\n }\n }\n });\n\n let {name, descriptionId, errorMessageId, validationBehavior} = checkboxGroupData.get(state)!;\n validationBehavior = props.validationBehavior ?? validationBehavior;\n\n // Local validation for this checkbox.\n let {realtimeValidation} = useFormValidationState({\n ...props,\n value: toggleState.isSelected,\n // Server validation is handled at the group level.\n name: undefined,\n validationBehavior: 'aria'\n });\n\n // Update the checkbox group state when realtime validation changes.\n let nativeValidation = useRef(DEFAULT_VALIDATION_RESULT);\n let updateValidation = () => {\n state.setInvalid(props.value, realtimeValidation.isInvalid ? realtimeValidation : nativeValidation.current);\n };\n\n useEffect(updateValidation);\n\n // Combine group and checkbox level validation.\n let combinedRealtimeValidation = state.realtimeValidation.isInvalid ? state.realtimeValidation : realtimeValidation;\n let displayValidation = validationBehavior === 'native' ? state.displayValidation : combinedRealtimeValidation;\n\n let res = useCheckbox({\n ...props,\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isDisabled: props.isDisabled || state.isDisabled,\n name: props.name || name,\n isRequired: props.isRequired ?? state.isRequired,\n validationBehavior,\n [privateValidationStateProp]: {\n realtimeValidation: combinedRealtimeValidation,\n displayValidation,\n resetValidation: state.resetValidation,\n commitValidation: state.commitValidation,\n updateValidation(v) {\n nativeValidation.current = v;\n updateValidation();\n }\n }\n }, toggleState, inputRef);\n\n return {\n ...res,\n inputProps: {\n ...res.inputProps,\n 'aria-describedby': [\n props['aria-describedby'],\n state.isInvalid ? errorMessageId : null,\n descriptionId\n ].filter(Boolean).join(' ') || undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { AriaCheckboxProps, AriaCheckboxGroupProps, AriaCheckboxGroupItemProps } from "@react-types/checkbox";
2
2
  import { InputHTMLAttributes, RefObject } from "react";
3
3
  import { ToggleState } from "@react-stately/toggle";
4
+ import { ValidationResult, DOMAttributes } from "@react-types/shared";
4
5
  import { CheckboxGroupState } from "@react-stately/checkbox";
5
- import { DOMAttributes } from "@react-types/shared";
6
- export interface CheckboxAria {
6
+ export interface CheckboxAria extends ValidationResult {
7
7
  /** Props for the input element. */
8
8
  inputProps: InputHTMLAttributes<HTMLInputElement>;
9
9
  /** Whether the checkbox is selected. */
@@ -14,8 +14,6 @@ export interface CheckboxAria {
14
14
  isDisabled: boolean;
15
15
  /** Whether the checkbox is read only. */
16
16
  isReadOnly: boolean;
17
- /** Whether the checkbox is invalid. */
18
- isInvalid: boolean;
19
17
  }
20
18
  /**
21
19
  * Provides the behavior and accessibility implementation for a checkbox component.
@@ -26,7 +24,7 @@ export interface CheckboxAria {
26
24
  * @param inputRef - A ref for the HTML input element.
27
25
  */
28
26
  export function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputRef: RefObject<HTMLInputElement>): CheckboxAria;
29
- export interface CheckboxGroupAria {
27
+ export interface CheckboxGroupAria extends ValidationResult {
30
28
  /** Props for the checkbox group wrapper element. */
31
29
  groupProps: DOMAttributes;
32
30
  /** Props for the checkbox group's visible label (if any). */
@@ -1 +1 @@
1
- {"mappings":";;;;;AAiBA;IACE,mCAAmC;IACnC,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAClD,wCAAwC;IACxC,UAAU,EAAE,OAAO,CAAC;IACpB,kDAAkD;IAClD,SAAS,EAAE,OAAO,CAAC;IACnB,wCAAwC;IACxC,UAAU,EAAE,OAAO,CAAC;IACpB,yCAAyC;IACzC,UAAU,EAAE,OAAO,CAAC;IACpB,uCAAuC;IACvC,SAAS,EAAE,OAAO,CAAA;CACnB;AAED;;;;;;;GAOG;AACH,4BAA4B,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,gBAAgB,CAAC,GAAG,YAAY,CAuB7H;AE5CD;IACE,oDAAoD;IACpD,UAAU,EAAE,aAAa,CAAC;IAC1B,6DAA6D;IAC7D,UAAU,EAAE,aAAa,CAAC;IAC1B,gEAAgE;IAChE,gBAAgB,EAAE,aAAa,CAAC;IAChC,kEAAkE;IAClE,iBAAiB,EAAE,aAAa,CAAA;CACjC;AAED;;;;;GAKG;AACH,iCAAiC,KAAK,EAAE,sBAAsB,EAAE,KAAK,EAAE,kBAAkB,GAAG,iBAAiB,CA2B5G;AC5CD;;;;;;GAMG;AACH,qCAAqC,KAAK,EAAE,0BAA0B,EAAE,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,UAAU,gBAAgB,CAAC,GAAG,YAAY,CAmCtJ;AC9CD,YAAY,EAAC,0BAA0B,EAAE,sBAAsB,EAAE,iBAAiB,EAAC,MAAM,uBAAuB,CAAC","sources":["packages/@react-aria/checkbox/src/packages/@react-aria/checkbox/src/useCheckbox.ts","packages/@react-aria/checkbox/src/packages/@react-aria/checkbox/src/utils.ts","packages/@react-aria/checkbox/src/packages/@react-aria/checkbox/src/useCheckboxGroup.ts","packages/@react-aria/checkbox/src/packages/@react-aria/checkbox/src/useCheckboxGroupItem.ts","packages/@react-aria/checkbox/src/packages/@react-aria/checkbox/src/index.ts","packages/@react-aria/checkbox/src/index.ts"],"sourcesContent":[null,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 type {CheckboxAria} from './useCheckbox';\nexport {useCheckbox} from './useCheckbox';\nexport {useCheckboxGroup} from './useCheckboxGroup';\nexport {useCheckboxGroupItem} from './useCheckboxGroupItem';\nexport type {AriaCheckboxGroupItemProps, AriaCheckboxGroupProps, AriaCheckboxProps} from '@react-types/checkbox';\nexport type {CheckboxGroupAria} from './useCheckboxGroup';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;;;;AAoBA,6BAA8B,SAAQ,gBAAgB;IACpD,mCAAmC;IACnC,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAClD,wCAAwC;IACxC,UAAU,EAAE,OAAO,CAAC;IACpB,kDAAkD;IAClD,SAAS,EAAE,OAAO,CAAC;IACnB,wCAAwC;IACxC,UAAU,EAAE,OAAO,CAAC;IACpB,yCAAyC;IACzC,UAAU,EAAE,OAAO,CAAA;CACpB;AAED;;;;;;;GAOG;AACH,4BAA4B,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,gBAAgB,CAAC,GAAG,YAAY,CAmC7H;AEzDD,kCAAmC,SAAQ,gBAAgB;IACzD,oDAAoD;IACpD,UAAU,EAAE,aAAa,CAAC;IAC1B,6DAA6D;IAC7D,UAAU,EAAE,aAAa,CAAC;IAC1B,gEAAgE;IAChE,gBAAgB,EAAE,aAAa,CAAC;IAChC,kEAAkE;IAClE,iBAAiB,EAAE,aAAa,CAAA;CACjC;AAED;;;;;GAKG;AACH,iCAAiC,KAAK,EAAE,sBAAsB,EAAE,KAAK,EAAE,kBAAkB,GAAG,iBAAiB,CAmC5G;ACnDD;;;;;;GAMG;AACH,qCAAqC,KAAK,EAAE,0BAA0B,EAAE,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,UAAU,gBAAgB,CAAC,GAAG,YAAY,CAuEtJ;ACnFD,YAAY,EAAC,0BAA0B,EAAE,sBAAsB,EAAE,iBAAiB,EAAC,MAAM,uBAAuB,CAAC","sources":["packages/@react-aria/checkbox/src/packages/@react-aria/checkbox/src/useCheckbox.ts","packages/@react-aria/checkbox/src/packages/@react-aria/checkbox/src/utils.ts","packages/@react-aria/checkbox/src/packages/@react-aria/checkbox/src/useCheckboxGroup.ts","packages/@react-aria/checkbox/src/packages/@react-aria/checkbox/src/useCheckboxGroupItem.ts","packages/@react-aria/checkbox/src/packages/@react-aria/checkbox/src/index.ts","packages/@react-aria/checkbox/src/index.ts"],"sourcesContent":[null,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 type {CheckboxAria} from './useCheckbox';\nexport {useCheckbox} from './useCheckbox';\nexport {useCheckboxGroup} from './useCheckboxGroup';\nexport {useCheckboxGroupItem} from './useCheckboxGroupItem';\nexport type {AriaCheckboxGroupItemProps, AriaCheckboxGroupProps, AriaCheckboxProps} from '@react-types/checkbox';\nexport type {CheckboxGroupAria} from './useCheckboxGroup';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/checkbox",
3
- "version": "3.11.2",
3
+ "version": "3.12.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,13 +22,15 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-aria/label": "^3.7.2",
26
- "@react-aria/toggle": "^3.8.2",
27
- "@react-aria/utils": "^3.21.1",
28
- "@react-stately/checkbox": "^3.5.1",
29
- "@react-stately/toggle": "^3.6.3",
30
- "@react-types/checkbox": "^3.5.2",
31
- "@react-types/shared": "^3.21.0",
25
+ "@react-aria/form": "^3.0.0",
26
+ "@react-aria/label": "^3.7.3",
27
+ "@react-aria/toggle": "^3.9.0",
28
+ "@react-aria/utils": "^3.22.0",
29
+ "@react-stately/checkbox": "^3.6.0",
30
+ "@react-stately/form": "^3.0.0",
31
+ "@react-stately/toggle": "^3.7.0",
32
+ "@react-types/checkbox": "^3.6.0",
33
+ "@react-types/shared": "^3.22.0",
32
34
  "@swc/helpers": "^0.5.0"
33
35
  },
34
36
  "peerDependencies": {
@@ -37,5 +39,5 @@
37
39
  "publishConfig": {
38
40
  "access": "public"
39
41
  },
40
- "gitHead": "3ecf62dcceea437cb12df1851636dd491bb6591c"
42
+ "gitHead": "9ce2f674eab2cc8912800d3162dcf00a1ce94274"
41
43
  }
@@ -13,9 +13,12 @@
13
13
  import {AriaCheckboxProps} from '@react-types/checkbox';
14
14
  import {InputHTMLAttributes, RefObject, useEffect} from 'react';
15
15
  import {ToggleState} from '@react-stately/toggle';
16
+ import {useFormValidation} from '@react-aria/form';
17
+ import {useFormValidationState} from '@react-stately/form';
16
18
  import {useToggle} from '@react-aria/toggle';
19
+ import {ValidationResult} from '@react-types/shared';
17
20
 
18
- export interface CheckboxAria {
21
+ export interface CheckboxAria extends ValidationResult {
19
22
  /** Props for the input element. */
20
23
  inputProps: InputHTMLAttributes<HTMLInputElement>,
21
24
  /** Whether the checkbox is selected. */
@@ -25,9 +28,7 @@ export interface CheckboxAria {
25
28
  /** Whether the checkbox is disabled. */
26
29
  isDisabled: boolean,
27
30
  /** Whether the checkbox is read only. */
28
- isReadOnly: boolean,
29
- /** Whether the checkbox is invalid. */
30
- isInvalid: boolean
31
+ isReadOnly: boolean
31
32
  }
32
33
 
33
34
  /**
@@ -39,9 +40,17 @@ export interface CheckboxAria {
39
40
  * @param inputRef - A ref for the HTML input element.
40
41
  */
41
42
  export function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {
42
- let {inputProps, isSelected, isPressed, isDisabled, isReadOnly, isInvalid} = useToggle(props, state, inputRef);
43
+ // Create validation state here because it doesn't make sense to add to general useToggleState.
44
+ let validationState = useFormValidationState({...props, value: state.isSelected});
45
+ let {isInvalid, validationErrors, validationDetails} = validationState.displayValidation;
46
+ let {inputProps, isSelected, isPressed, isDisabled, isReadOnly} = useToggle({
47
+ ...props,
48
+ isInvalid
49
+ }, state, inputRef);
50
+
51
+ useFormValidation(props, validationState, inputRef);
43
52
 
44
- let {isIndeterminate} = props;
53
+ let {isIndeterminate, isRequired, validationBehavior = 'aria'} = props;
45
54
  useEffect(() => {
46
55
  // indeterminate is a property, but it can only be set via javascript
47
56
  // https://css-tricks.com/indeterminate-checkboxes/
@@ -53,12 +62,16 @@ export function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputR
53
62
  return {
54
63
  inputProps: {
55
64
  ...inputProps,
56
- checked: isSelected
65
+ checked: isSelected,
66
+ 'aria-required': (isRequired && validationBehavior === 'aria') || undefined,
67
+ required: isRequired && validationBehavior === 'native'
57
68
  },
58
69
  isSelected,
59
70
  isPressed,
60
71
  isDisabled,
61
72
  isReadOnly,
62
- isInvalid
73
+ isInvalid,
74
+ validationErrors,
75
+ validationDetails
63
76
  };
64
77
  }
@@ -11,13 +11,13 @@
11
11
  */
12
12
 
13
13
  import {AriaCheckboxGroupProps} from '@react-types/checkbox';
14
- import {checkboxGroupDescriptionIds, checkboxGroupErrorMessageIds, checkboxGroupNames} from './utils';
14
+ import {checkboxGroupData} from './utils';
15
15
  import {CheckboxGroupState} from '@react-stately/checkbox';
16
- import {DOMAttributes} from '@react-types/shared';
16
+ import {DOMAttributes, ValidationResult} from '@react-types/shared';
17
17
  import {filterDOMProps, mergeProps} from '@react-aria/utils';
18
18
  import {useField} from '@react-aria/label';
19
19
 
20
- export interface CheckboxGroupAria {
20
+ export interface CheckboxGroupAria extends ValidationResult {
21
21
  /** Props for the checkbox group wrapper element. */
22
22
  groupProps: DOMAttributes,
23
23
  /** Props for the checkbox group's visible label (if any). */
@@ -35,21 +35,26 @@ export interface CheckboxGroupAria {
35
35
  * @param state - State for the checkbox group, as returned by `useCheckboxGroupState`.
36
36
  */
37
37
  export function useCheckboxGroup(props: AriaCheckboxGroupProps, state: CheckboxGroupState): CheckboxGroupAria {
38
- let {isDisabled, name} = props;
38
+ let {isDisabled, name, validationBehavior = 'aria'} = props;
39
+ let {isInvalid, validationErrors, validationDetails} = state.displayValidation;
39
40
 
40
41
  let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({
41
42
  ...props,
42
43
  // Checkbox group is not an HTML input element so it
43
44
  // shouldn't be labeled by a <label> element.
44
- labelElementType: 'span'
45
+ labelElementType: 'span',
46
+ isInvalid,
47
+ errorMessage: props.errorMessage || validationErrors
45
48
  });
46
- checkboxGroupDescriptionIds.set(state, descriptionProps.id);
47
- checkboxGroupErrorMessageIds.set(state, errorMessageProps.id);
48
49
 
49
- let domProps = filterDOMProps(props, {labelable: true});
50
+ checkboxGroupData.set(state, {
51
+ name,
52
+ descriptionId: descriptionProps.id,
53
+ errorMessageId: errorMessageProps.id,
54
+ validationBehavior
55
+ });
50
56
 
51
- // Pass name prop from group to all items by attaching to the state.
52
- checkboxGroupNames.set(state, name);
57
+ let domProps = filterDOMProps(props, {labelable: true});
53
58
 
54
59
  return {
55
60
  groupProps: mergeProps(domProps, {
@@ -59,6 +64,9 @@ export function useCheckboxGroup(props: AriaCheckboxGroupProps, state: CheckboxG
59
64
  }),
60
65
  labelProps,
61
66
  descriptionProps,
62
- errorMessageProps
67
+ errorMessageProps,
68
+ isInvalid,
69
+ validationErrors,
70
+ validationDetails
63
71
  };
64
72
  }
@@ -12,9 +12,10 @@
12
12
 
13
13
  import {AriaCheckboxGroupItemProps} from '@react-types/checkbox';
14
14
  import {CheckboxAria, useCheckbox} from './useCheckbox';
15
- import {checkboxGroupDescriptionIds, checkboxGroupErrorMessageIds, checkboxGroupNames} from './utils';
15
+ import {checkboxGroupData} from './utils';
16
16
  import {CheckboxGroupState} from '@react-stately/checkbox';
17
- import {RefObject} from 'react';
17
+ import {DEFAULT_VALIDATION_RESULT, privateValidationStateProp, useFormValidationState} from '@react-stately/form';
18
+ import {RefObject, useEffect, useRef} from 'react';
18
19
  import {useToggleState} from '@react-stately/toggle';
19
20
 
20
21
  /**
@@ -41,11 +42,47 @@ export function useCheckboxGroupItem(props: AriaCheckboxGroupItemProps, state: C
41
42
  }
42
43
  });
43
44
 
45
+ let {name, descriptionId, errorMessageId, validationBehavior} = checkboxGroupData.get(state)!;
46
+ validationBehavior = props.validationBehavior ?? validationBehavior;
47
+
48
+ // Local validation for this checkbox.
49
+ let {realtimeValidation} = useFormValidationState({
50
+ ...props,
51
+ value: toggleState.isSelected,
52
+ // Server validation is handled at the group level.
53
+ name: undefined,
54
+ validationBehavior: 'aria'
55
+ });
56
+
57
+ // Update the checkbox group state when realtime validation changes.
58
+ let nativeValidation = useRef(DEFAULT_VALIDATION_RESULT);
59
+ let updateValidation = () => {
60
+ state.setInvalid(props.value, realtimeValidation.isInvalid ? realtimeValidation : nativeValidation.current);
61
+ };
62
+
63
+ useEffect(updateValidation);
64
+
65
+ // Combine group and checkbox level validation.
66
+ let combinedRealtimeValidation = state.realtimeValidation.isInvalid ? state.realtimeValidation : realtimeValidation;
67
+ let displayValidation = validationBehavior === 'native' ? state.displayValidation : combinedRealtimeValidation;
68
+
44
69
  let res = useCheckbox({
45
70
  ...props,
46
71
  isReadOnly: props.isReadOnly || state.isReadOnly,
47
72
  isDisabled: props.isDisabled || state.isDisabled,
48
- name: props.name || checkboxGroupNames.get(state)
73
+ name: props.name || name,
74
+ isRequired: props.isRequired ?? state.isRequired,
75
+ validationBehavior,
76
+ [privateValidationStateProp]: {
77
+ realtimeValidation: combinedRealtimeValidation,
78
+ displayValidation,
79
+ resetValidation: state.resetValidation,
80
+ commitValidation: state.commitValidation,
81
+ updateValidation(v) {
82
+ nativeValidation.current = v;
83
+ updateValidation();
84
+ }
85
+ }
49
86
  }, toggleState, inputRef);
50
87
 
51
88
  return {
@@ -54,8 +91,8 @@ export function useCheckboxGroupItem(props: AriaCheckboxGroupItemProps, state: C
54
91
  ...res.inputProps,
55
92
  'aria-describedby': [
56
93
  props['aria-describedby'],
57
- state.isInvalid ? checkboxGroupErrorMessageIds.get(state) : null,
58
- checkboxGroupDescriptionIds.get(state)
94
+ state.isInvalid ? errorMessageId : null,
95
+ descriptionId
59
96
  ].filter(Boolean).join(' ') || undefined
60
97
  }
61
98
  };
package/src/utils.ts CHANGED
@@ -12,6 +12,11 @@
12
12
 
13
13
  import {CheckboxGroupState} from '@react-stately/checkbox';
14
14
 
15
- export const checkboxGroupNames = new WeakMap<CheckboxGroupState, string>();
16
- export const checkboxGroupDescriptionIds = new WeakMap<CheckboxGroupState, string>();
17
- export const checkboxGroupErrorMessageIds = new WeakMap<CheckboxGroupState, string>();
15
+ interface CheckboxGroupData {
16
+ name: string,
17
+ descriptionId: string,
18
+ errorMessageId: string,
19
+ validationBehavior: 'aria' | 'native'
20
+ }
21
+
22
+ export const checkboxGroupData = new WeakMap<CheckboxGroupState, CheckboxGroupData>();