@react-aria/checkbox 3.11.2 → 3.13.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 +79 -19
- package/dist/main.js +79 -18
- package/dist/main.js.map +1 -1
- package/dist/module.js +79 -19
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +6 -6
- package/dist/types.d.ts.map +1 -1
- package/package.json +11 -9
- package/src/useCheckbox.ts +26 -10
- package/src/useCheckboxGroup.ts +19 -11
- package/src/useCheckboxGroupItem.ts +43 -5
- package/src/utils.ts +8 -3
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,24 +28,41 @@ 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
|
-
|
|
31
|
-
let
|
|
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 { labelProps: labelProps, 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/
|
|
35
|
-
if (inputRef.current) inputRef.current.indeterminate = isIndeterminate;
|
|
49
|
+
if (inputRef.current) inputRef.current.indeterminate = !!isIndeterminate;
|
|
36
50
|
});
|
|
37
51
|
return {
|
|
52
|
+
labelProps: labelProps,
|
|
38
53
|
inputProps: {
|
|
39
54
|
...inputProps,
|
|
40
|
-
checked: isSelected
|
|
55
|
+
checked: isSelected,
|
|
56
|
+
"aria-required": isRequired && validationBehavior === "aria" || undefined,
|
|
57
|
+
required: isRequired && validationBehavior === "native"
|
|
41
58
|
},
|
|
42
59
|
isSelected: isSelected,
|
|
43
60
|
isPressed: isPressed,
|
|
44
61
|
isDisabled: isDisabled,
|
|
45
62
|
isReadOnly: isReadOnly,
|
|
46
|
-
isInvalid: isInvalid
|
|
63
|
+
isInvalid: isInvalid,
|
|
64
|
+
validationErrors: validationErrors,
|
|
65
|
+
validationDetails: validationDetails
|
|
47
66
|
};
|
|
48
67
|
}
|
|
49
68
|
|
|
@@ -68,28 +87,31 @@ function $406796ff087fe49b$export$e375f10ce42261c5(props, state, inputRef) {
|
|
|
68
87
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
69
88
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
70
89
|
* governing permissions and limitations under the License.
|
|
71
|
-
*/ const $1ae600c947479353$export$
|
|
72
|
-
const $1ae600c947479353$export$a3077e9c93f7360f = new WeakMap();
|
|
73
|
-
const $1ae600c947479353$export$d5679492e2864181 = new WeakMap();
|
|
90
|
+
*/ const $1ae600c947479353$export$ec98120685d4f57d = new WeakMap();
|
|
74
91
|
|
|
75
92
|
|
|
76
93
|
|
|
77
94
|
|
|
78
95
|
function $1e9fce0cfacc738b$export$49ff6f28c54f1cbe(props, state) {
|
|
79
|
-
let { isDisabled: isDisabled, name: name } = props;
|
|
96
|
+
let { isDisabled: isDisabled, name: name, validationBehavior: validationBehavior = "aria" } = props;
|
|
97
|
+
let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
|
|
80
98
|
let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $cKEhs$useField)({
|
|
81
99
|
...props,
|
|
82
100
|
// Checkbox group is not an HTML input element so it
|
|
83
101
|
// shouldn't be labeled by a <label> element.
|
|
84
|
-
labelElementType: "span"
|
|
102
|
+
labelElementType: "span",
|
|
103
|
+
isInvalid: isInvalid,
|
|
104
|
+
errorMessage: props.errorMessage || validationErrors
|
|
105
|
+
});
|
|
106
|
+
(0, $1ae600c947479353$export$ec98120685d4f57d).set(state, {
|
|
107
|
+
name: name,
|
|
108
|
+
descriptionId: descriptionProps.id,
|
|
109
|
+
errorMessageId: errorMessageProps.id,
|
|
110
|
+
validationBehavior: validationBehavior
|
|
85
111
|
});
|
|
86
|
-
(0, $1ae600c947479353$export$a3077e9c93f7360f).set(state, descriptionProps.id);
|
|
87
|
-
(0, $1ae600c947479353$export$d5679492e2864181).set(state, errorMessageProps.id);
|
|
88
112
|
let domProps = (0, $cKEhs$filterDOMProps)(props, {
|
|
89
113
|
labelable: true
|
|
90
114
|
});
|
|
91
|
-
// Pass name prop from group to all items by attaching to the state.
|
|
92
|
-
(0, $1ae600c947479353$export$31440636951aa68c).set(state, name);
|
|
93
115
|
return {
|
|
94
116
|
groupProps: (0, $cKEhs$mergeProps)(domProps, {
|
|
95
117
|
role: "group",
|
|
@@ -98,7 +120,10 @@ function $1e9fce0cfacc738b$export$49ff6f28c54f1cbe(props, state) {
|
|
|
98
120
|
}),
|
|
99
121
|
labelProps: labelProps,
|
|
100
122
|
descriptionProps: descriptionProps,
|
|
101
|
-
errorMessageProps: errorMessageProps
|
|
123
|
+
errorMessageProps: errorMessageProps,
|
|
124
|
+
isInvalid: isInvalid,
|
|
125
|
+
validationErrors: validationErrors,
|
|
126
|
+
validationDetails: validationDetails
|
|
102
127
|
};
|
|
103
128
|
}
|
|
104
129
|
|
|
@@ -116,6 +141,8 @@ function $1e9fce0cfacc738b$export$49ff6f28c54f1cbe(props, state) {
|
|
|
116
141
|
*/
|
|
117
142
|
|
|
118
143
|
|
|
144
|
+
|
|
145
|
+
|
|
119
146
|
function $fba3e38d5ca8983f$export$353b32fc6898d37d(props, state, inputRef) {
|
|
120
147
|
const toggleState = (0, $cKEhs$useToggleState)({
|
|
121
148
|
isReadOnly: props.isReadOnly || state.isReadOnly,
|
|
@@ -126,11 +153,44 @@ function $fba3e38d5ca8983f$export$353b32fc6898d37d(props, state, inputRef) {
|
|
|
126
153
|
if (props.onChange) props.onChange(isSelected);
|
|
127
154
|
}
|
|
128
155
|
});
|
|
156
|
+
let { name: name, descriptionId: descriptionId, errorMessageId: errorMessageId, validationBehavior: validationBehavior } = (0, $1ae600c947479353$export$ec98120685d4f57d).get(state);
|
|
157
|
+
var _props_validationBehavior;
|
|
158
|
+
validationBehavior = (_props_validationBehavior = props.validationBehavior) !== null && _props_validationBehavior !== void 0 ? _props_validationBehavior : validationBehavior;
|
|
159
|
+
// Local validation for this checkbox.
|
|
160
|
+
let { realtimeValidation: realtimeValidation } = (0, $cKEhs$useFormValidationState)({
|
|
161
|
+
...props,
|
|
162
|
+
value: toggleState.isSelected,
|
|
163
|
+
// Server validation is handled at the group level.
|
|
164
|
+
name: undefined,
|
|
165
|
+
validationBehavior: "aria"
|
|
166
|
+
});
|
|
167
|
+
// Update the checkbox group state when realtime validation changes.
|
|
168
|
+
let nativeValidation = (0, $cKEhs$useRef)((0, $cKEhs$DEFAULT_VALIDATION_RESULT));
|
|
169
|
+
let updateValidation = ()=>{
|
|
170
|
+
state.setInvalid(props.value, realtimeValidation.isInvalid ? realtimeValidation : nativeValidation.current);
|
|
171
|
+
};
|
|
172
|
+
(0, $cKEhs$useEffect)(updateValidation);
|
|
173
|
+
// Combine group and checkbox level validation.
|
|
174
|
+
let combinedRealtimeValidation = state.realtimeValidation.isInvalid ? state.realtimeValidation : realtimeValidation;
|
|
175
|
+
let displayValidation = validationBehavior === "native" ? state.displayValidation : combinedRealtimeValidation;
|
|
176
|
+
var _props_isRequired;
|
|
129
177
|
let res = (0, $406796ff087fe49b$export$e375f10ce42261c5)({
|
|
130
178
|
...props,
|
|
131
179
|
isReadOnly: props.isReadOnly || state.isReadOnly,
|
|
132
180
|
isDisabled: props.isDisabled || state.isDisabled,
|
|
133
|
-
name: props.name ||
|
|
181
|
+
name: props.name || name,
|
|
182
|
+
isRequired: (_props_isRequired = props.isRequired) !== null && _props_isRequired !== void 0 ? _props_isRequired : state.isRequired,
|
|
183
|
+
validationBehavior: validationBehavior,
|
|
184
|
+
[(0, $cKEhs$privateValidationStateProp)]: {
|
|
185
|
+
realtimeValidation: combinedRealtimeValidation,
|
|
186
|
+
displayValidation: displayValidation,
|
|
187
|
+
resetValidation: state.resetValidation,
|
|
188
|
+
commitValidation: state.commitValidation,
|
|
189
|
+
updateValidation (v) {
|
|
190
|
+
nativeValidation.current = v;
|
|
191
|
+
updateValidation();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
134
194
|
}, toggleState, inputRef);
|
|
135
195
|
return {
|
|
136
196
|
...res,
|
|
@@ -138,8 +198,8 @@ function $fba3e38d5ca8983f$export$353b32fc6898d37d(props, state, inputRef) {
|
|
|
138
198
|
...res.inputProps,
|
|
139
199
|
"aria-describedby": [
|
|
140
200
|
props["aria-describedby"],
|
|
141
|
-
state.isInvalid ?
|
|
142
|
-
|
|
201
|
+
state.isInvalid ? errorMessageId : null,
|
|
202
|
+
descriptionId
|
|
143
203
|
].filter(Boolean).join(" ") || undefined
|
|
144
204
|
}
|
|
145
205
|
};
|
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,24 +36,41 @@ $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
|
-
|
|
38
|
-
let
|
|
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 { labelProps: labelProps, 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/
|
|
42
|
-
if (inputRef.current) inputRef.current.indeterminate = isIndeterminate;
|
|
57
|
+
if (inputRef.current) inputRef.current.indeterminate = !!isIndeterminate;
|
|
43
58
|
});
|
|
44
59
|
return {
|
|
60
|
+
labelProps: labelProps,
|
|
45
61
|
inputProps: {
|
|
46
62
|
...inputProps,
|
|
47
|
-
checked: isSelected
|
|
63
|
+
checked: isSelected,
|
|
64
|
+
"aria-required": isRequired && validationBehavior === "aria" || undefined,
|
|
65
|
+
required: isRequired && validationBehavior === "native"
|
|
48
66
|
},
|
|
49
67
|
isSelected: isSelected,
|
|
50
68
|
isPressed: isPressed,
|
|
51
69
|
isDisabled: isDisabled,
|
|
52
70
|
isReadOnly: isReadOnly,
|
|
53
|
-
isInvalid: isInvalid
|
|
71
|
+
isInvalid: isInvalid,
|
|
72
|
+
validationErrors: validationErrors,
|
|
73
|
+
validationDetails: validationDetails
|
|
54
74
|
};
|
|
55
75
|
}
|
|
56
76
|
|
|
@@ -75,28 +95,31 @@ function $468c774d7db917b7$export$e375f10ce42261c5(props, state, inputRef) {
|
|
|
75
95
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
76
96
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
77
97
|
* governing permissions and limitations under the License.
|
|
78
|
-
*/ const $64fc3370e682155f$export$
|
|
79
|
-
const $64fc3370e682155f$export$a3077e9c93f7360f = new WeakMap();
|
|
80
|
-
const $64fc3370e682155f$export$d5679492e2864181 = new WeakMap();
|
|
98
|
+
*/ const $64fc3370e682155f$export$ec98120685d4f57d = new WeakMap();
|
|
81
99
|
|
|
82
100
|
|
|
83
101
|
|
|
84
102
|
|
|
85
103
|
function $253685172d17db7d$export$49ff6f28c54f1cbe(props, state) {
|
|
86
|
-
let { isDisabled: isDisabled, name: name } = props;
|
|
104
|
+
let { isDisabled: isDisabled, name: name, validationBehavior: validationBehavior = "aria" } = props;
|
|
105
|
+
let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
|
|
87
106
|
let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $k0DcK$reactarialabel.useField)({
|
|
88
107
|
...props,
|
|
89
108
|
// Checkbox group is not an HTML input element so it
|
|
90
109
|
// shouldn't be labeled by a <label> element.
|
|
91
|
-
labelElementType: "span"
|
|
110
|
+
labelElementType: "span",
|
|
111
|
+
isInvalid: isInvalid,
|
|
112
|
+
errorMessage: props.errorMessage || validationErrors
|
|
113
|
+
});
|
|
114
|
+
(0, $64fc3370e682155f$export$ec98120685d4f57d).set(state, {
|
|
115
|
+
name: name,
|
|
116
|
+
descriptionId: descriptionProps.id,
|
|
117
|
+
errorMessageId: errorMessageProps.id,
|
|
118
|
+
validationBehavior: validationBehavior
|
|
92
119
|
});
|
|
93
|
-
(0, $64fc3370e682155f$export$a3077e9c93f7360f).set(state, descriptionProps.id);
|
|
94
|
-
(0, $64fc3370e682155f$export$d5679492e2864181).set(state, errorMessageProps.id);
|
|
95
120
|
let domProps = (0, $k0DcK$reactariautils.filterDOMProps)(props, {
|
|
96
121
|
labelable: true
|
|
97
122
|
});
|
|
98
|
-
// Pass name prop from group to all items by attaching to the state.
|
|
99
|
-
(0, $64fc3370e682155f$export$31440636951aa68c).set(state, name);
|
|
100
123
|
return {
|
|
101
124
|
groupProps: (0, $k0DcK$reactariautils.mergeProps)(domProps, {
|
|
102
125
|
role: "group",
|
|
@@ -105,7 +128,10 @@ function $253685172d17db7d$export$49ff6f28c54f1cbe(props, state) {
|
|
|
105
128
|
}),
|
|
106
129
|
labelProps: labelProps,
|
|
107
130
|
descriptionProps: descriptionProps,
|
|
108
|
-
errorMessageProps: errorMessageProps
|
|
131
|
+
errorMessageProps: errorMessageProps,
|
|
132
|
+
isInvalid: isInvalid,
|
|
133
|
+
validationErrors: validationErrors,
|
|
134
|
+
validationDetails: validationDetails
|
|
109
135
|
};
|
|
110
136
|
}
|
|
111
137
|
|
|
@@ -123,6 +149,8 @@ function $253685172d17db7d$export$49ff6f28c54f1cbe(props, state) {
|
|
|
123
149
|
*/
|
|
124
150
|
|
|
125
151
|
|
|
152
|
+
|
|
153
|
+
|
|
126
154
|
function $07e03121d6ac83c8$export$353b32fc6898d37d(props, state, inputRef) {
|
|
127
155
|
const toggleState = (0, $k0DcK$reactstatelytoggle.useToggleState)({
|
|
128
156
|
isReadOnly: props.isReadOnly || state.isReadOnly,
|
|
@@ -133,11 +161,44 @@ function $07e03121d6ac83c8$export$353b32fc6898d37d(props, state, inputRef) {
|
|
|
133
161
|
if (props.onChange) props.onChange(isSelected);
|
|
134
162
|
}
|
|
135
163
|
});
|
|
164
|
+
let { name: name, descriptionId: descriptionId, errorMessageId: errorMessageId, validationBehavior: validationBehavior } = (0, $64fc3370e682155f$export$ec98120685d4f57d).get(state);
|
|
165
|
+
var _props_validationBehavior;
|
|
166
|
+
validationBehavior = (_props_validationBehavior = props.validationBehavior) !== null && _props_validationBehavior !== void 0 ? _props_validationBehavior : validationBehavior;
|
|
167
|
+
// Local validation for this checkbox.
|
|
168
|
+
let { realtimeValidation: realtimeValidation } = (0, $k0DcK$reactstatelyform.useFormValidationState)({
|
|
169
|
+
...props,
|
|
170
|
+
value: toggleState.isSelected,
|
|
171
|
+
// Server validation is handled at the group level.
|
|
172
|
+
name: undefined,
|
|
173
|
+
validationBehavior: "aria"
|
|
174
|
+
});
|
|
175
|
+
// Update the checkbox group state when realtime validation changes.
|
|
176
|
+
let nativeValidation = (0, $k0DcK$react.useRef)((0, $k0DcK$reactstatelyform.DEFAULT_VALIDATION_RESULT));
|
|
177
|
+
let updateValidation = ()=>{
|
|
178
|
+
state.setInvalid(props.value, realtimeValidation.isInvalid ? realtimeValidation : nativeValidation.current);
|
|
179
|
+
};
|
|
180
|
+
(0, $k0DcK$react.useEffect)(updateValidation);
|
|
181
|
+
// Combine group and checkbox level validation.
|
|
182
|
+
let combinedRealtimeValidation = state.realtimeValidation.isInvalid ? state.realtimeValidation : realtimeValidation;
|
|
183
|
+
let displayValidation = validationBehavior === "native" ? state.displayValidation : combinedRealtimeValidation;
|
|
184
|
+
var _props_isRequired;
|
|
136
185
|
let res = (0, $468c774d7db917b7$export$e375f10ce42261c5)({
|
|
137
186
|
...props,
|
|
138
187
|
isReadOnly: props.isReadOnly || state.isReadOnly,
|
|
139
188
|
isDisabled: props.isDisabled || state.isDisabled,
|
|
140
|
-
name: props.name ||
|
|
189
|
+
name: props.name || name,
|
|
190
|
+
isRequired: (_props_isRequired = props.isRequired) !== null && _props_isRequired !== void 0 ? _props_isRequired : state.isRequired,
|
|
191
|
+
validationBehavior: validationBehavior,
|
|
192
|
+
[(0, $k0DcK$reactstatelyform.privateValidationStateProp)]: {
|
|
193
|
+
realtimeValidation: combinedRealtimeValidation,
|
|
194
|
+
displayValidation: displayValidation,
|
|
195
|
+
resetValidation: state.resetValidation,
|
|
196
|
+
commitValidation: state.commitValidation,
|
|
197
|
+
updateValidation (v) {
|
|
198
|
+
nativeValidation.current = v;
|
|
199
|
+
updateValidation();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
141
202
|
}, toggleState, inputRef);
|
|
142
203
|
return {
|
|
143
204
|
...res,
|
|
@@ -145,8 +206,8 @@ function $07e03121d6ac83c8$export$353b32fc6898d37d(props, state, inputRef) {
|
|
|
145
206
|
...res.inputProps,
|
|
146
207
|
"aria-describedby": [
|
|
147
208
|
props["aria-describedby"],
|
|
148
|
-
state.isInvalid ?
|
|
149
|
-
|
|
209
|
+
state.isInvalid ? errorMessageId : null,
|
|
210
|
+
descriptionId
|
|
150
211
|
].filter(Boolean).join(" ") || undefined
|
|
151
212
|
}
|
|
152
213
|
};
|
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,GAAG;IAEzB,IAAI,cAAC,UAAU,cAAE,UAAU,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,CAAA,GAAA,8BAAO,EAAE;QAC3E,GAAG,KAAK;QACR,oDAAoD;QACpD,6CAA6C;QAC7C,kBAAkB;IACpB;IACA,CAAA,GAAA,yCAA0B,EAAE,IAAI,OAAO,iBAAiB;IACxD,CAAA,GAAA,yCAA2B,EAAE,IAAI,OAAO,kBAAkB;IAE1D,IAAI,WAAW,CAAA,GAAA,oCAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,oEAAoE;IACpE,CAAA,GAAA,yCAAiB,EAAE,IAAI,OAAO;IAE9B,OAAO;QACL,YAAY,CAAA,GAAA,gCAAS,EAAE,UAAU;YAC/B,MAAM;YACN,iBAAiB,cAAc;YAC/B,GAAG,UAAU;QACf;oBACA;0BACA;2BACA;IACF;AACF;;;AE/DA;;;;;;;;;;CAUC;;;AAgBM,SAAS,0CAAqB,KAAiC,EAAE,KAAyB,EAAE,QAAqC;IACtI,MAAM,cAAc,CAAA,GAAA,wCAAa,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":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;;AAiCM,SAAS,0CAAY,KAAwB,EAAE,KAAkB,EAAE,QAAqC;IAC7G,+FAA+F;IAC/F,IAAI,kBAAkB,CAAA,GAAA,8CAAqB,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,cAAE,UAAU,aAAE,SAAS,cAAE,UAAU,cAAE,UAAU,EAAC,GAAG,CAAA,GAAA,gCAAQ,EAAE;QACtF,GAAG,KAAK;mBACR;IACF,GAAG,OAAO;IAEV,CAAA,GAAA,sCAAgB,EAAE,OAAO,iBAAiB;IAE1C,IAAI,mBAAC,eAAe,cAAE,UAAU,sBAAE,qBAAqB,QAAO,GAAG;IACjE,CAAA,GAAA,sBAAQ,EAAE;QACR,qEAAqE;QACrE,mDAAmD;QACnD,IAAI,SAAS,OAAO,EAClB,SAAS,OAAO,CAAC,aAAa,GAAG,CAAC,CAAC;IAEvC;IAEA,OAAO;oBACL;QACA,YAAY;YACV,GAAG,UAAU;YACb,SAAS;YACT,iBAAiB,AAAC,cAAc,uBAAuB,UAAW;YAClE,UAAU,cAAc,uBAAuB;QACjD;oBACA;mBACA;oBACA;oBACA;mBACA;0BACA;2BACA;IACF;AACF;;CDrEC;AEVD;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAWM,MAAM,4CAAoB,IAAI;;CDXpC;;;AA0BM,SAAS,0CAAiB,KAA6B,EAAE,KAAyB;IACvF,IAAI,cAAC,UAAU,QAAE,IAAI,sBAAE,qBAAqB,QAAO,GAAG;IACtD,IAAI,aAAC,SAAS,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,MAAM,iBAAiB;IAE9E,IAAI,cAAC,UAAU,cAAE,UAAU,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,CAAA,GAAA,8BAAO,EAAE;QAC3E,GAAG,KAAK;QACR,oDAAoD;QACpD,6CAA6C;QAC7C,kBAAkB;mBAClB;QACA,cAAc,MAAM,YAAY,IAAI;IACtC;IAEA,CAAA,GAAA,yCAAgB,EAAE,GAAG,CAAC,OAAO;cAC3B;QACA,eAAe,iBAAiB,EAAE;QAClC,gBAAgB,kBAAkB,EAAE;4BACpC;IACF;IAEA,IAAI,WAAW,CAAA,GAAA,oCAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,OAAO;QACL,YAAY,CAAA,GAAA,gCAAS,EAAE,UAAU;YAC/B,MAAM;YACN,iBAAiB,cAAc;YAC/B,GAAG,UAAU;QACf;oBACA;0BACA;2BACA;mBACA;0BACA;2BACA;IACF;AACF;;;AEvEA;;;;;;;;;;CAUC;;;;;AAkBM,SAAS,0CAAqB,KAAiC,EAAE,KAAyB,EAAE,QAAqC;IACtI,MAAM,cAAc,CAAA,GAAA,wCAAa,EAAE;QACjC,YAAY,MAAM,UAAU,IAAI,MAAM,UAAU;QAChD,YAAY,MAAM,UAAU,CAAC,MAAM,KAAK;QACxC,UAAS,UAAU;YACjB,IAAI,YACF,MAAM,QAAQ,CAAC,MAAM,KAAK;iBAE1B,MAAM,WAAW,CAAC,MAAM,KAAK;YAG/B,IAAI,MAAM,QAAQ,EAChB,MAAM,QAAQ,CAAC;QAEnB;IACF;IAEA,IAAI,QAAC,IAAI,iBAAE,aAAa,kBAAE,cAAc,sBAAE,kBAAkB,EAAC,GAAG,CAAA,GAAA,yCAAgB,EAAE,GAAG,CAAC;QACjE;IAArB,qBAAqB,CAAA,4BAAA,MAAM,kBAAkB,cAAxB,uCAAA,4BAA4B;IAEjD,sCAAsC;IACtC,IAAI,sBAAC,kBAAkB,EAAC,GAAG,CAAA,GAAA,8CAAqB,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,CAAmB;gBAClC,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, LabelHTMLAttributes, 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 label wrapper element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>,\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 {labelProps, 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 labelProps,\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';\nimport {ValidationResult} from '@react-types/shared';\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: ValidationResult) {\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,24 +28,41 @@ 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
|
-
|
|
31
|
-
let
|
|
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 { labelProps: labelProps, 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/
|
|
35
|
-
if (inputRef.current) inputRef.current.indeterminate = isIndeterminate;
|
|
49
|
+
if (inputRef.current) inputRef.current.indeterminate = !!isIndeterminate;
|
|
36
50
|
});
|
|
37
51
|
return {
|
|
52
|
+
labelProps: labelProps,
|
|
38
53
|
inputProps: {
|
|
39
54
|
...inputProps,
|
|
40
|
-
checked: isSelected
|
|
55
|
+
checked: isSelected,
|
|
56
|
+
"aria-required": isRequired && validationBehavior === "aria" || undefined,
|
|
57
|
+
required: isRequired && validationBehavior === "native"
|
|
41
58
|
},
|
|
42
59
|
isSelected: isSelected,
|
|
43
60
|
isPressed: isPressed,
|
|
44
61
|
isDisabled: isDisabled,
|
|
45
62
|
isReadOnly: isReadOnly,
|
|
46
|
-
isInvalid: isInvalid
|
|
63
|
+
isInvalid: isInvalid,
|
|
64
|
+
validationErrors: validationErrors,
|
|
65
|
+
validationDetails: validationDetails
|
|
47
66
|
};
|
|
48
67
|
}
|
|
49
68
|
|
|
@@ -68,28 +87,31 @@ function $406796ff087fe49b$export$e375f10ce42261c5(props, state, inputRef) {
|
|
|
68
87
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
69
88
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
70
89
|
* governing permissions and limitations under the License.
|
|
71
|
-
*/ const $1ae600c947479353$export$
|
|
72
|
-
const $1ae600c947479353$export$a3077e9c93f7360f = new WeakMap();
|
|
73
|
-
const $1ae600c947479353$export$d5679492e2864181 = new WeakMap();
|
|
90
|
+
*/ const $1ae600c947479353$export$ec98120685d4f57d = new WeakMap();
|
|
74
91
|
|
|
75
92
|
|
|
76
93
|
|
|
77
94
|
|
|
78
95
|
function $1e9fce0cfacc738b$export$49ff6f28c54f1cbe(props, state) {
|
|
79
|
-
let { isDisabled: isDisabled, name: name } = props;
|
|
96
|
+
let { isDisabled: isDisabled, name: name, validationBehavior: validationBehavior = "aria" } = props;
|
|
97
|
+
let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
|
|
80
98
|
let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $cKEhs$useField)({
|
|
81
99
|
...props,
|
|
82
100
|
// Checkbox group is not an HTML input element so it
|
|
83
101
|
// shouldn't be labeled by a <label> element.
|
|
84
|
-
labelElementType: "span"
|
|
102
|
+
labelElementType: "span",
|
|
103
|
+
isInvalid: isInvalid,
|
|
104
|
+
errorMessage: props.errorMessage || validationErrors
|
|
105
|
+
});
|
|
106
|
+
(0, $1ae600c947479353$export$ec98120685d4f57d).set(state, {
|
|
107
|
+
name: name,
|
|
108
|
+
descriptionId: descriptionProps.id,
|
|
109
|
+
errorMessageId: errorMessageProps.id,
|
|
110
|
+
validationBehavior: validationBehavior
|
|
85
111
|
});
|
|
86
|
-
(0, $1ae600c947479353$export$a3077e9c93f7360f).set(state, descriptionProps.id);
|
|
87
|
-
(0, $1ae600c947479353$export$d5679492e2864181).set(state, errorMessageProps.id);
|
|
88
112
|
let domProps = (0, $cKEhs$filterDOMProps)(props, {
|
|
89
113
|
labelable: true
|
|
90
114
|
});
|
|
91
|
-
// Pass name prop from group to all items by attaching to the state.
|
|
92
|
-
(0, $1ae600c947479353$export$31440636951aa68c).set(state, name);
|
|
93
115
|
return {
|
|
94
116
|
groupProps: (0, $cKEhs$mergeProps)(domProps, {
|
|
95
117
|
role: "group",
|
|
@@ -98,7 +120,10 @@ function $1e9fce0cfacc738b$export$49ff6f28c54f1cbe(props, state) {
|
|
|
98
120
|
}),
|
|
99
121
|
labelProps: labelProps,
|
|
100
122
|
descriptionProps: descriptionProps,
|
|
101
|
-
errorMessageProps: errorMessageProps
|
|
123
|
+
errorMessageProps: errorMessageProps,
|
|
124
|
+
isInvalid: isInvalid,
|
|
125
|
+
validationErrors: validationErrors,
|
|
126
|
+
validationDetails: validationDetails
|
|
102
127
|
};
|
|
103
128
|
}
|
|
104
129
|
|
|
@@ -116,6 +141,8 @@ function $1e9fce0cfacc738b$export$49ff6f28c54f1cbe(props, state) {
|
|
|
116
141
|
*/
|
|
117
142
|
|
|
118
143
|
|
|
144
|
+
|
|
145
|
+
|
|
119
146
|
function $fba3e38d5ca8983f$export$353b32fc6898d37d(props, state, inputRef) {
|
|
120
147
|
const toggleState = (0, $cKEhs$useToggleState)({
|
|
121
148
|
isReadOnly: props.isReadOnly || state.isReadOnly,
|
|
@@ -126,11 +153,44 @@ function $fba3e38d5ca8983f$export$353b32fc6898d37d(props, state, inputRef) {
|
|
|
126
153
|
if (props.onChange) props.onChange(isSelected);
|
|
127
154
|
}
|
|
128
155
|
});
|
|
156
|
+
let { name: name, descriptionId: descriptionId, errorMessageId: errorMessageId, validationBehavior: validationBehavior } = (0, $1ae600c947479353$export$ec98120685d4f57d).get(state);
|
|
157
|
+
var _props_validationBehavior;
|
|
158
|
+
validationBehavior = (_props_validationBehavior = props.validationBehavior) !== null && _props_validationBehavior !== void 0 ? _props_validationBehavior : validationBehavior;
|
|
159
|
+
// Local validation for this checkbox.
|
|
160
|
+
let { realtimeValidation: realtimeValidation } = (0, $cKEhs$useFormValidationState)({
|
|
161
|
+
...props,
|
|
162
|
+
value: toggleState.isSelected,
|
|
163
|
+
// Server validation is handled at the group level.
|
|
164
|
+
name: undefined,
|
|
165
|
+
validationBehavior: "aria"
|
|
166
|
+
});
|
|
167
|
+
// Update the checkbox group state when realtime validation changes.
|
|
168
|
+
let nativeValidation = (0, $cKEhs$useRef)((0, $cKEhs$DEFAULT_VALIDATION_RESULT));
|
|
169
|
+
let updateValidation = ()=>{
|
|
170
|
+
state.setInvalid(props.value, realtimeValidation.isInvalid ? realtimeValidation : nativeValidation.current);
|
|
171
|
+
};
|
|
172
|
+
(0, $cKEhs$useEffect)(updateValidation);
|
|
173
|
+
// Combine group and checkbox level validation.
|
|
174
|
+
let combinedRealtimeValidation = state.realtimeValidation.isInvalid ? state.realtimeValidation : realtimeValidation;
|
|
175
|
+
let displayValidation = validationBehavior === "native" ? state.displayValidation : combinedRealtimeValidation;
|
|
176
|
+
var _props_isRequired;
|
|
129
177
|
let res = (0, $406796ff087fe49b$export$e375f10ce42261c5)({
|
|
130
178
|
...props,
|
|
131
179
|
isReadOnly: props.isReadOnly || state.isReadOnly,
|
|
132
180
|
isDisabled: props.isDisabled || state.isDisabled,
|
|
133
|
-
name: props.name ||
|
|
181
|
+
name: props.name || name,
|
|
182
|
+
isRequired: (_props_isRequired = props.isRequired) !== null && _props_isRequired !== void 0 ? _props_isRequired : state.isRequired,
|
|
183
|
+
validationBehavior: validationBehavior,
|
|
184
|
+
[(0, $cKEhs$privateValidationStateProp)]: {
|
|
185
|
+
realtimeValidation: combinedRealtimeValidation,
|
|
186
|
+
displayValidation: displayValidation,
|
|
187
|
+
resetValidation: state.resetValidation,
|
|
188
|
+
commitValidation: state.commitValidation,
|
|
189
|
+
updateValidation (v) {
|
|
190
|
+
nativeValidation.current = v;
|
|
191
|
+
updateValidation();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
134
194
|
}, toggleState, inputRef);
|
|
135
195
|
return {
|
|
136
196
|
...res,
|
|
@@ -138,8 +198,8 @@ function $fba3e38d5ca8983f$export$353b32fc6898d37d(props, state, inputRef) {
|
|
|
138
198
|
...res.inputProps,
|
|
139
199
|
"aria-describedby": [
|
|
140
200
|
props["aria-describedby"],
|
|
141
|
-
state.isInvalid ?
|
|
142
|
-
|
|
201
|
+
state.isInvalid ? errorMessageId : null,
|
|
202
|
+
descriptionId
|
|
143
203
|
].filter(Boolean).join(" ") || undefined
|
|
144
204
|
}
|
|
145
205
|
};
|
package/dist/module.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,gBAAQ,EAAE,OAAO,OAAO;IAErG,IAAI,mBAAC,eAAe,EAAC,GAAG;IACxB,CAAA,GAAA,gBAAQ,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,GAAG;IAEzB,IAAI,cAAC,UAAU,cAAE,UAAU,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;QAC3E,GAAG,KAAK;QACR,oDAAoD;QACpD,6CAA6C;QAC7C,kBAAkB;IACpB;IACA,CAAA,GAAA,yCAA0B,EAAE,IAAI,OAAO,iBAAiB;IACxD,CAAA,GAAA,yCAA2B,EAAE,IAAI,OAAO,kBAAkB;IAE1D,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,oEAAoE;IACpE,CAAA,GAAA,yCAAiB,EAAE,IAAI,OAAO;IAE9B,OAAO;QACL,YAAY,CAAA,GAAA,iBAAS,EAAE,UAAU;YAC/B,MAAM;YACN,iBAAiB,cAAc;YAC/B,GAAG,UAAU;QACf;oBACA;0BACA;2BACA;IACF;AACF;;;AE/DA;;;;;;;;;;CAUC;;;AAgBM,SAAS,0CAAqB,KAAiC,EAAE,KAAyB,EAAE,QAAqC;IACtI,MAAM,cAAc,CAAA,GAAA,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":"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","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, LabelHTMLAttributes, 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 label wrapper element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>,\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 {labelProps, 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 labelProps,\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';\nimport {ValidationResult} from '@react-types/shared';\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: ValidationResult) {\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,11 @@
|
|
|
1
1
|
import { AriaCheckboxProps, AriaCheckboxGroupProps, AriaCheckboxGroupItemProps } from "@react-types/checkbox";
|
|
2
|
-
import { InputHTMLAttributes, RefObject } from "react";
|
|
2
|
+
import { InputHTMLAttributes, LabelHTMLAttributes, 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
|
-
|
|
6
|
-
|
|
6
|
+
export interface CheckboxAria extends ValidationResult {
|
|
7
|
+
/** Props for the label wrapper element. */
|
|
8
|
+
labelProps: LabelHTMLAttributes<HTMLLabelElement>;
|
|
7
9
|
/** Props for the input element. */
|
|
8
10
|
inputProps: InputHTMLAttributes<HTMLInputElement>;
|
|
9
11
|
/** Whether the checkbox is selected. */
|
|
@@ -14,8 +16,6 @@ export interface CheckboxAria {
|
|
|
14
16
|
isDisabled: boolean;
|
|
15
17
|
/** Whether the checkbox is read only. */
|
|
16
18
|
isReadOnly: boolean;
|
|
17
|
-
/** Whether the checkbox is invalid. */
|
|
18
|
-
isInvalid: boolean;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Provides the behavior and accessibility implementation for a checkbox component.
|
|
@@ -26,7 +26,7 @@ export interface CheckboxAria {
|
|
|
26
26
|
* @param inputRef - A ref for the HTML input element.
|
|
27
27
|
*/
|
|
28
28
|
export function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputRef: RefObject<HTMLInputElement>): CheckboxAria;
|
|
29
|
-
export interface CheckboxGroupAria {
|
|
29
|
+
export interface CheckboxGroupAria extends ValidationResult {
|
|
30
30
|
/** Props for the checkbox group wrapper element. */
|
|
31
31
|
groupProps: DOMAttributes;
|
|
32
32
|
/** Props for the checkbox group's visible label (if any). */
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;
|
|
1
|
+
{"mappings":";;;;;AAoBA,6BAA8B,SAAQ,gBAAgB;IACpD,2CAA2C;IAC3C,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAClD,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,CAoC7H;AE5DD,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;AClDD;;;;;;GAMG;AACH,qCAAqC,KAAK,EAAE,0BAA0B,EAAE,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,UAAU,gBAAgB,CAAC,GAAG,YAAY,CAuEtJ;ACpFD,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.
|
|
3
|
+
"version": "3.13.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/
|
|
26
|
-
"@react-aria/
|
|
27
|
-
"@react-aria/
|
|
28
|
-
"@react-
|
|
29
|
-
"@react-stately/
|
|
30
|
-
"@react-
|
|
31
|
-
"@react-
|
|
25
|
+
"@react-aria/form": "^3.0.1",
|
|
26
|
+
"@react-aria/label": "^3.7.4",
|
|
27
|
+
"@react-aria/toggle": "^3.10.0",
|
|
28
|
+
"@react-aria/utils": "^3.23.0",
|
|
29
|
+
"@react-stately/checkbox": "^3.6.1",
|
|
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": "
|
|
42
|
+
"gitHead": "86b38c87868ce7f262e0df905e5ac4eb2653791d"
|
|
41
43
|
}
|
package/src/useCheckbox.ts
CHANGED
|
@@ -11,11 +11,16 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import {AriaCheckboxProps} from '@react-types/checkbox';
|
|
14
|
-
import {InputHTMLAttributes, RefObject, useEffect} from 'react';
|
|
14
|
+
import {InputHTMLAttributes, LabelHTMLAttributes, 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 {
|
|
22
|
+
/** Props for the label wrapper element. */
|
|
23
|
+
labelProps: LabelHTMLAttributes<HTMLLabelElement>,
|
|
19
24
|
/** Props for the input element. */
|
|
20
25
|
inputProps: InputHTMLAttributes<HTMLInputElement>,
|
|
21
26
|
/** Whether the checkbox is selected. */
|
|
@@ -25,9 +30,7 @@ export interface CheckboxAria {
|
|
|
25
30
|
/** Whether the checkbox is disabled. */
|
|
26
31
|
isDisabled: boolean,
|
|
27
32
|
/** Whether the checkbox is read only. */
|
|
28
|
-
isReadOnly: boolean
|
|
29
|
-
/** Whether the checkbox is invalid. */
|
|
30
|
-
isInvalid: boolean
|
|
33
|
+
isReadOnly: boolean
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
/**
|
|
@@ -39,26 +42,39 @@ export interface CheckboxAria {
|
|
|
39
42
|
* @param inputRef - A ref for the HTML input element.
|
|
40
43
|
*/
|
|
41
44
|
export function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {
|
|
42
|
-
|
|
45
|
+
// Create validation state here because it doesn't make sense to add to general useToggleState.
|
|
46
|
+
let validationState = useFormValidationState({...props, value: state.isSelected});
|
|
47
|
+
let {isInvalid, validationErrors, validationDetails} = validationState.displayValidation;
|
|
48
|
+
let {labelProps, inputProps, isSelected, isPressed, isDisabled, isReadOnly} = useToggle({
|
|
49
|
+
...props,
|
|
50
|
+
isInvalid
|
|
51
|
+
}, state, inputRef);
|
|
52
|
+
|
|
53
|
+
useFormValidation(props, validationState, inputRef);
|
|
43
54
|
|
|
44
|
-
let {isIndeterminate} = props;
|
|
55
|
+
let {isIndeterminate, isRequired, validationBehavior = 'aria'} = props;
|
|
45
56
|
useEffect(() => {
|
|
46
57
|
// indeterminate is a property, but it can only be set via javascript
|
|
47
58
|
// https://css-tricks.com/indeterminate-checkboxes/
|
|
48
59
|
if (inputRef.current) {
|
|
49
|
-
inputRef.current.indeterminate = isIndeterminate;
|
|
60
|
+
inputRef.current.indeterminate = !!isIndeterminate;
|
|
50
61
|
}
|
|
51
62
|
});
|
|
52
63
|
|
|
53
64
|
return {
|
|
65
|
+
labelProps,
|
|
54
66
|
inputProps: {
|
|
55
67
|
...inputProps,
|
|
56
|
-
checked: isSelected
|
|
68
|
+
checked: isSelected,
|
|
69
|
+
'aria-required': (isRequired && validationBehavior === 'aria') || undefined,
|
|
70
|
+
required: isRequired && validationBehavior === 'native'
|
|
57
71
|
},
|
|
58
72
|
isSelected,
|
|
59
73
|
isPressed,
|
|
60
74
|
isDisabled,
|
|
61
75
|
isReadOnly,
|
|
62
|
-
isInvalid
|
|
76
|
+
isInvalid,
|
|
77
|
+
validationErrors,
|
|
78
|
+
validationDetails
|
|
63
79
|
};
|
|
64
80
|
}
|
package/src/useCheckboxGroup.ts
CHANGED
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import {AriaCheckboxGroupProps} from '@react-types/checkbox';
|
|
14
|
-
import {
|
|
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
|
-
|
|
50
|
+
checkboxGroupData.set(state, {
|
|
51
|
+
name,
|
|
52
|
+
descriptionId: descriptionProps.id,
|
|
53
|
+
errorMessageId: errorMessageProps.id,
|
|
54
|
+
validationBehavior
|
|
55
|
+
});
|
|
50
56
|
|
|
51
|
-
|
|
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,10 +12,12 @@
|
|
|
12
12
|
|
|
13
13
|
import {AriaCheckboxGroupItemProps} from '@react-types/checkbox';
|
|
14
14
|
import {CheckboxAria, useCheckbox} from './useCheckbox';
|
|
15
|
-
import {
|
|
15
|
+
import {checkboxGroupData} from './utils';
|
|
16
16
|
import {CheckboxGroupState} from '@react-stately/checkbox';
|
|
17
|
-
import {
|
|
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';
|
|
20
|
+
import {ValidationResult} from '@react-types/shared';
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* Provides the behavior and accessibility implementation for a checkbox component contained within a checkbox group.
|
|
@@ -41,11 +43,47 @@ export function useCheckboxGroupItem(props: AriaCheckboxGroupItemProps, state: C
|
|
|
41
43
|
}
|
|
42
44
|
});
|
|
43
45
|
|
|
46
|
+
let {name, descriptionId, errorMessageId, validationBehavior} = checkboxGroupData.get(state)!;
|
|
47
|
+
validationBehavior = props.validationBehavior ?? validationBehavior;
|
|
48
|
+
|
|
49
|
+
// Local validation for this checkbox.
|
|
50
|
+
let {realtimeValidation} = useFormValidationState({
|
|
51
|
+
...props,
|
|
52
|
+
value: toggleState.isSelected,
|
|
53
|
+
// Server validation is handled at the group level.
|
|
54
|
+
name: undefined,
|
|
55
|
+
validationBehavior: 'aria'
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Update the checkbox group state when realtime validation changes.
|
|
59
|
+
let nativeValidation = useRef(DEFAULT_VALIDATION_RESULT);
|
|
60
|
+
let updateValidation = () => {
|
|
61
|
+
state.setInvalid(props.value, realtimeValidation.isInvalid ? realtimeValidation : nativeValidation.current);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
useEffect(updateValidation);
|
|
65
|
+
|
|
66
|
+
// Combine group and checkbox level validation.
|
|
67
|
+
let combinedRealtimeValidation = state.realtimeValidation.isInvalid ? state.realtimeValidation : realtimeValidation;
|
|
68
|
+
let displayValidation = validationBehavior === 'native' ? state.displayValidation : combinedRealtimeValidation;
|
|
69
|
+
|
|
44
70
|
let res = useCheckbox({
|
|
45
71
|
...props,
|
|
46
72
|
isReadOnly: props.isReadOnly || state.isReadOnly,
|
|
47
73
|
isDisabled: props.isDisabled || state.isDisabled,
|
|
48
|
-
name: props.name ||
|
|
74
|
+
name: props.name || name,
|
|
75
|
+
isRequired: props.isRequired ?? state.isRequired,
|
|
76
|
+
validationBehavior,
|
|
77
|
+
[privateValidationStateProp]: {
|
|
78
|
+
realtimeValidation: combinedRealtimeValidation,
|
|
79
|
+
displayValidation,
|
|
80
|
+
resetValidation: state.resetValidation,
|
|
81
|
+
commitValidation: state.commitValidation,
|
|
82
|
+
updateValidation(v: ValidationResult) {
|
|
83
|
+
nativeValidation.current = v;
|
|
84
|
+
updateValidation();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
49
87
|
}, toggleState, inputRef);
|
|
50
88
|
|
|
51
89
|
return {
|
|
@@ -54,8 +92,8 @@ export function useCheckboxGroupItem(props: AriaCheckboxGroupItemProps, state: C
|
|
|
54
92
|
...res.inputProps,
|
|
55
93
|
'aria-describedby': [
|
|
56
94
|
props['aria-describedby'],
|
|
57
|
-
state.isInvalid ?
|
|
58
|
-
|
|
95
|
+
state.isInvalid ? errorMessageId : null,
|
|
96
|
+
descriptionId
|
|
59
97
|
].filter(Boolean).join(' ') || undefined
|
|
60
98
|
}
|
|
61
99
|
};
|
package/src/utils.ts
CHANGED
|
@@ -12,6 +12,11 @@
|
|
|
12
12
|
|
|
13
13
|
import {CheckboxGroupState} from '@react-stately/checkbox';
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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>();
|