@react-aria/checkbox 3.12.0 → 3.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/import.mjs CHANGED
@@ -4,6 +4,7 @@ import {useFormValidationState as $cKEhs$useFormValidationState, DEFAULT_VALIDAT
4
4
  import {useToggle as $cKEhs$useToggle} from "@react-aria/toggle";
5
5
  import {filterDOMProps as $cKEhs$filterDOMProps, mergeProps as $cKEhs$mergeProps} from "@react-aria/utils";
6
6
  import {useField as $cKEhs$useField} from "@react-aria/label";
7
+ import {useFocusWithin as $cKEhs$useFocusWithin} from "@react-aria/interactions";
7
8
  import {useToggleState as $cKEhs$useToggleState} from "@react-stately/toggle";
8
9
 
9
10
  /*
@@ -37,7 +38,7 @@ function $406796ff087fe49b$export$e375f10ce42261c5(props, state, inputRef) {
37
38
  value: state.isSelected
38
39
  });
39
40
  let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = validationState.displayValidation;
40
- let { inputProps: inputProps, isSelected: isSelected, isPressed: isPressed, isDisabled: isDisabled, isReadOnly: isReadOnly } = (0, $cKEhs$useToggle)({
41
+ let { labelProps: labelProps, inputProps: inputProps, isSelected: isSelected, isPressed: isPressed, isDisabled: isDisabled, isReadOnly: isReadOnly } = (0, $cKEhs$useToggle)({
41
42
  ...props,
42
43
  isInvalid: isInvalid
43
44
  }, state, inputRef);
@@ -46,9 +47,10 @@ function $406796ff087fe49b$export$e375f10ce42261c5(props, state, inputRef) {
46
47
  (0, $cKEhs$useEffect)(()=>{
47
48
  // indeterminate is a property, but it can only be set via javascript
48
49
  // https://css-tricks.com/indeterminate-checkboxes/
49
- if (inputRef.current) inputRef.current.indeterminate = isIndeterminate;
50
+ if (inputRef.current) inputRef.current.indeterminate = !!isIndeterminate;
50
51
  });
51
52
  return {
53
+ labelProps: labelProps,
52
54
  inputProps: {
53
55
  ...inputProps,
54
56
  checked: isSelected,
@@ -91,6 +93,7 @@ function $406796ff087fe49b$export$e375f10ce42261c5(props, state, inputRef) {
91
93
 
92
94
 
93
95
 
96
+
94
97
  function $1e9fce0cfacc738b$export$49ff6f28c54f1cbe(props, state) {
95
98
  let { isDisabled: isDisabled, name: name, validationBehavior: validationBehavior = "aria" } = props;
96
99
  let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
@@ -111,11 +114,17 @@ function $1e9fce0cfacc738b$export$49ff6f28c54f1cbe(props, state) {
111
114
  let domProps = (0, $cKEhs$filterDOMProps)(props, {
112
115
  labelable: true
113
116
  });
117
+ let { focusWithinProps: focusWithinProps } = (0, $cKEhs$useFocusWithin)({
118
+ onBlurWithin: props.onBlur,
119
+ onFocusWithin: props.onFocus,
120
+ onFocusWithinChange: props.onFocusChange
121
+ });
114
122
  return {
115
123
  groupProps: (0, $cKEhs$mergeProps)(domProps, {
116
124
  role: "group",
117
125
  "aria-disabled": isDisabled || undefined,
118
- ...fieldProps
126
+ ...fieldProps,
127
+ ...focusWithinProps
119
128
  }),
120
129
  labelProps: labelProps,
121
130
  descriptionProps: descriptionProps,
package/dist/main.js CHANGED
@@ -4,6 +4,7 @@ var $k0DcK$reactstatelyform = require("@react-stately/form");
4
4
  var $k0DcK$reactariatoggle = require("@react-aria/toggle");
5
5
  var $k0DcK$reactariautils = require("@react-aria/utils");
6
6
  var $k0DcK$reactarialabel = require("@react-aria/label");
7
+ var $k0DcK$reactariainteractions = require("@react-aria/interactions");
7
8
  var $k0DcK$reactstatelytoggle = require("@react-stately/toggle");
8
9
 
9
10
 
@@ -45,7 +46,7 @@ function $468c774d7db917b7$export$e375f10ce42261c5(props, state, inputRef) {
45
46
  value: state.isSelected
46
47
  });
47
48
  let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = validationState.displayValidation;
48
- let { inputProps: inputProps, isSelected: isSelected, isPressed: isPressed, isDisabled: isDisabled, isReadOnly: isReadOnly } = (0, $k0DcK$reactariatoggle.useToggle)({
49
+ let { labelProps: labelProps, inputProps: inputProps, isSelected: isSelected, isPressed: isPressed, isDisabled: isDisabled, isReadOnly: isReadOnly } = (0, $k0DcK$reactariatoggle.useToggle)({
49
50
  ...props,
50
51
  isInvalid: isInvalid
51
52
  }, state, inputRef);
@@ -54,9 +55,10 @@ function $468c774d7db917b7$export$e375f10ce42261c5(props, state, inputRef) {
54
55
  (0, $k0DcK$react.useEffect)(()=>{
55
56
  // indeterminate is a property, but it can only be set via javascript
56
57
  // https://css-tricks.com/indeterminate-checkboxes/
57
- if (inputRef.current) inputRef.current.indeterminate = isIndeterminate;
58
+ if (inputRef.current) inputRef.current.indeterminate = !!isIndeterminate;
58
59
  });
59
60
  return {
61
+ labelProps: labelProps,
60
62
  inputProps: {
61
63
  ...inputProps,
62
64
  checked: isSelected,
@@ -99,6 +101,7 @@ function $468c774d7db917b7$export$e375f10ce42261c5(props, state, inputRef) {
99
101
 
100
102
 
101
103
 
104
+
102
105
  function $253685172d17db7d$export$49ff6f28c54f1cbe(props, state) {
103
106
  let { isDisabled: isDisabled, name: name, validationBehavior: validationBehavior = "aria" } = props;
104
107
  let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
@@ -119,11 +122,17 @@ function $253685172d17db7d$export$49ff6f28c54f1cbe(props, state) {
119
122
  let domProps = (0, $k0DcK$reactariautils.filterDOMProps)(props, {
120
123
  labelable: true
121
124
  });
125
+ let { focusWithinProps: focusWithinProps } = (0, $k0DcK$reactariainteractions.useFocusWithin)({
126
+ onBlurWithin: props.onBlur,
127
+ onFocusWithin: props.onFocus,
128
+ onFocusWithinChange: props.onFocusChange
129
+ });
122
130
  return {
123
131
  groupProps: (0, $k0DcK$reactariautils.mergeProps)(domProps, {
124
132
  role: "group",
125
133
  "aria-disabled": isDisabled || undefined,
126
- ...fieldProps
134
+ ...fieldProps,
135
+ ...focusWithinProps
127
136
  }),
128
137
  labelProps: labelProps,
129
138
  descriptionProps: descriptionProps,
package/dist/main.js.map CHANGED
@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AAoB;IACtB;IAEA,oEAAoE;IACpE,IAAI,mBAAmB,CAAA,GAAA,mBAAK,EAAE,CAAA,GAAA,iDAAwB;IACtD,IAAI,mBAAmB;QACrB,MAAM,UAAU,CAAC,MAAM,KAAK,EAAE,mBAAmB,SAAS,GAAG,qBAAqB,iBAAiB,OAAO;IAC5G;IAEA,CAAA,GAAA,sBAAQ,EAAE;IAEV,+CAA+C;IAC/C,IAAI,6BAA6B,MAAM,kBAAkB,CAAC,SAAS,GAAG,MAAM,kBAAkB,GAAG;IACjG,IAAI,oBAAoB,uBAAuB,WAAW,MAAM,iBAAiB,GAAG;QAOtE;IALd,IAAI,MAAM,CAAA,GAAA,yCAAU,EAAE;QACpB,GAAG,KAAK;QACR,YAAY,MAAM,UAAU,IAAI,MAAM,UAAU;QAChD,YAAY,MAAM,UAAU,IAAI,MAAM,UAAU;QAChD,MAAM,MAAM,IAAI,IAAI;QACpB,YAAY,CAAA,oBAAA,MAAM,UAAU,cAAhB,+BAAA,oBAAoB,MAAM,UAAU;4BAChD;QACA,CAAC,CAAA,GAAA,kDAAyB,EAAE,EAAE;YAC5B,oBAAoB;+BACpB;YACA,iBAAiB,MAAM,eAAe;YACtC,kBAAkB,MAAM,gBAAgB;YACxC,kBAAiB,CAAC;gBAChB,iBAAiB,OAAO,GAAG;gBAC3B;YACF;QACF;IACF,GAAG,aAAa;IAEhB,OAAO;QACL,GAAG,GAAG;QACN,YAAY;YACV,GAAG,IAAI,UAAU;YACjB,oBAAoB;gBAClB,KAAK,CAAC,mBAAmB;gBACzB,MAAM,SAAS,GAAG,iBAAiB;gBACnC;aACD,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,QAAQ;QACjC;IACF;AACF;;","sources":["packages/@react-aria/checkbox/src/index.ts","packages/@react-aria/checkbox/src/useCheckbox.ts","packages/@react-aria/checkbox/src/useCheckboxGroup.ts","packages/@react-aria/checkbox/src/utils.ts","packages/@react-aria/checkbox/src/useCheckboxGroupItem.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport type {CheckboxAria} from './useCheckbox';\nexport {useCheckbox} from './useCheckbox';\nexport {useCheckboxGroup} from './useCheckboxGroup';\nexport {useCheckboxGroupItem} from './useCheckboxGroupItem';\nexport type {AriaCheckboxGroupItemProps, AriaCheckboxGroupProps, AriaCheckboxProps} from '@react-types/checkbox';\nexport type {CheckboxGroupAria} from './useCheckboxGroup';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaCheckboxProps} from '@react-types/checkbox';\nimport {InputHTMLAttributes, RefObject, useEffect} from 'react';\nimport {ToggleState} from '@react-stately/toggle';\nimport {useFormValidation} from '@react-aria/form';\nimport {useFormValidationState} from '@react-stately/form';\nimport {useToggle} from '@react-aria/toggle';\nimport {ValidationResult} from '@react-types/shared';\n\nexport interface CheckboxAria extends ValidationResult {\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Whether the checkbox is selected. */\n isSelected: boolean,\n /** Whether the checkbox is in a pressed state. */\n isPressed: boolean,\n /** Whether the checkbox is disabled. */\n isDisabled: boolean,\n /** Whether the checkbox is read only. */\n isReadOnly: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox component.\n * Checkboxes allow users to select multiple items from a list of individual items, or\n * to mark one individual item as selected.\n * @param props - Props for the checkbox.\n * @param state - State for the checkbox, as returned by `useToggleState`.\n * @param inputRef - A ref for the HTML input element.\n */\nexport function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {\n // Create validation state here because it doesn't make sense to add to general useToggleState.\n let validationState = useFormValidationState({...props, value: state.isSelected});\n let {isInvalid, validationErrors, validationDetails} = validationState.displayValidation;\n let {inputProps, isSelected, isPressed, isDisabled, isReadOnly} = useToggle({\n ...props,\n isInvalid\n }, state, inputRef);\n\n useFormValidation(props, validationState, inputRef);\n\n let {isIndeterminate, isRequired, validationBehavior = 'aria'} = props;\n useEffect(() => {\n // indeterminate is a property, but it can only be set via javascript\n // https://css-tricks.com/indeterminate-checkboxes/\n if (inputRef.current) {\n inputRef.current.indeterminate = isIndeterminate;\n }\n });\n\n return {\n inputProps: {\n ...inputProps,\n checked: isSelected,\n 'aria-required': (isRequired && validationBehavior === 'aria') || undefined,\n required: isRequired && validationBehavior === 'native'\n },\n isSelected,\n isPressed,\n isDisabled,\n isReadOnly,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaCheckboxGroupProps} from '@react-types/checkbox';\nimport {checkboxGroupData} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {DOMAttributes, ValidationResult} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {useField} from '@react-aria/label';\n\nexport interface CheckboxGroupAria extends ValidationResult {\n /** Props for the checkbox group wrapper element. */\n groupProps: DOMAttributes,\n /** Props for the checkbox group's visible label (if any). */\n labelProps: DOMAttributes,\n /** Props for the checkbox group description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the checkbox group error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox group component.\n * Checkbox groups allow users to select multiple items from a list of options.\n * @param props - Props for the checkbox group.\n * @param state - State for the checkbox group, as returned by `useCheckboxGroupState`.\n */\nexport function useCheckboxGroup(props: AriaCheckboxGroupProps, state: CheckboxGroupState): CheckboxGroupAria {\n let {isDisabled, name, validationBehavior = 'aria'} = props;\n let {isInvalid, validationErrors, validationDetails} = state.displayValidation;\n\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n // Checkbox group is not an HTML input element so it\n // shouldn't be labeled by a <label> element.\n labelElementType: 'span',\n isInvalid,\n errorMessage: props.errorMessage || validationErrors\n });\n\n checkboxGroupData.set(state, {\n name,\n descriptionId: descriptionProps.id,\n errorMessageId: errorMessageProps.id,\n validationBehavior\n });\n\n let domProps = filterDOMProps(props, {labelable: true});\n\n return {\n groupProps: mergeProps(domProps, {\n role: 'group',\n 'aria-disabled': isDisabled || undefined,\n ...fieldProps\n }),\n labelProps,\n descriptionProps,\n errorMessageProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CheckboxGroupState} from '@react-stately/checkbox';\n\ninterface CheckboxGroupData {\n name: string,\n descriptionId: string,\n errorMessageId: string,\n validationBehavior: 'aria' | 'native'\n}\n\nexport const checkboxGroupData = new WeakMap<CheckboxGroupState, CheckboxGroupData>();\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaCheckboxGroupItemProps} from '@react-types/checkbox';\nimport {CheckboxAria, useCheckbox} from './useCheckbox';\nimport {checkboxGroupData} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {DEFAULT_VALIDATION_RESULT, privateValidationStateProp, useFormValidationState} from '@react-stately/form';\nimport {RefObject, useEffect, useRef} from 'react';\nimport {useToggleState} from '@react-stately/toggle';\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox component contained within a checkbox group.\n * Checkbox groups allow users to select multiple items from a list of options.\n * @param props - Props for the checkbox.\n * @param state - State for the checkbox, as returned by `useCheckboxGroupState`.\n * @param inputRef - A ref for the HTML input element.\n */\nexport function useCheckboxGroupItem(props: AriaCheckboxGroupItemProps, state: CheckboxGroupState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {\n const toggleState = useToggleState({\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isSelected: state.isSelected(props.value),\n onChange(isSelected) {\n if (isSelected) {\n state.addValue(props.value);\n } else {\n state.removeValue(props.value);\n }\n\n if (props.onChange) {\n props.onChange(isSelected);\n }\n }\n });\n\n let {name, descriptionId, errorMessageId, validationBehavior} = checkboxGroupData.get(state)!;\n validationBehavior = props.validationBehavior ?? validationBehavior;\n\n // Local validation for this checkbox.\n let {realtimeValidation} = useFormValidationState({\n ...props,\n value: toggleState.isSelected,\n // Server validation is handled at the group level.\n name: undefined,\n validationBehavior: 'aria'\n });\n\n // Update the checkbox group state when realtime validation changes.\n let nativeValidation = useRef(DEFAULT_VALIDATION_RESULT);\n let updateValidation = () => {\n state.setInvalid(props.value, realtimeValidation.isInvalid ? realtimeValidation : nativeValidation.current);\n };\n\n useEffect(updateValidation);\n\n // Combine group and checkbox level validation.\n let combinedRealtimeValidation = state.realtimeValidation.isInvalid ? state.realtimeValidation : realtimeValidation;\n let displayValidation = validationBehavior === 'native' ? state.displayValidation : combinedRealtimeValidation;\n\n let res = useCheckbox({\n ...props,\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isDisabled: props.isDisabled || state.isDisabled,\n name: props.name || name,\n isRequired: props.isRequired ?? state.isRequired,\n validationBehavior,\n [privateValidationStateProp]: {\n realtimeValidation: combinedRealtimeValidation,\n displayValidation,\n resetValidation: state.resetValidation,\n commitValidation: state.commitValidation,\n updateValidation(v) {\n nativeValidation.current = v;\n updateValidation();\n }\n }\n }, toggleState, inputRef);\n\n return {\n ...res,\n inputProps: {\n ...res.inputProps,\n 'aria-describedby': [\n props['aria-describedby'],\n state.isInvalid ? errorMessageId : null,\n descriptionId\n ].filter(Boolean).join(' ') || undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
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,UAA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AEA,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';\nimport {useFocusWithin} from '@react-aria/interactions';\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 let {focusWithinProps} = useFocusWithin({\n onBlurWithin: props.onBlur,\n onFocusWithin: props.onFocus,\n onFocusWithinChange: props.onFocusChange\n });\n\n return {\n groupProps: mergeProps(domProps, {\n role: 'group',\n 'aria-disabled': isDisabled || undefined,\n ...fieldProps,\n ...focusWithinProps\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
@@ -4,6 +4,7 @@ import {useFormValidationState as $cKEhs$useFormValidationState, DEFAULT_VALIDAT
4
4
  import {useToggle as $cKEhs$useToggle} from "@react-aria/toggle";
5
5
  import {filterDOMProps as $cKEhs$filterDOMProps, mergeProps as $cKEhs$mergeProps} from "@react-aria/utils";
6
6
  import {useField as $cKEhs$useField} from "@react-aria/label";
7
+ import {useFocusWithin as $cKEhs$useFocusWithin} from "@react-aria/interactions";
7
8
  import {useToggleState as $cKEhs$useToggleState} from "@react-stately/toggle";
8
9
 
9
10
  /*
@@ -37,7 +38,7 @@ function $406796ff087fe49b$export$e375f10ce42261c5(props, state, inputRef) {
37
38
  value: state.isSelected
38
39
  });
39
40
  let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = validationState.displayValidation;
40
- let { inputProps: inputProps, isSelected: isSelected, isPressed: isPressed, isDisabled: isDisabled, isReadOnly: isReadOnly } = (0, $cKEhs$useToggle)({
41
+ let { labelProps: labelProps, inputProps: inputProps, isSelected: isSelected, isPressed: isPressed, isDisabled: isDisabled, isReadOnly: isReadOnly } = (0, $cKEhs$useToggle)({
41
42
  ...props,
42
43
  isInvalid: isInvalid
43
44
  }, state, inputRef);
@@ -46,9 +47,10 @@ function $406796ff087fe49b$export$e375f10ce42261c5(props, state, inputRef) {
46
47
  (0, $cKEhs$useEffect)(()=>{
47
48
  // indeterminate is a property, but it can only be set via javascript
48
49
  // https://css-tricks.com/indeterminate-checkboxes/
49
- if (inputRef.current) inputRef.current.indeterminate = isIndeterminate;
50
+ if (inputRef.current) inputRef.current.indeterminate = !!isIndeterminate;
50
51
  });
51
52
  return {
53
+ labelProps: labelProps,
52
54
  inputProps: {
53
55
  ...inputProps,
54
56
  checked: isSelected,
@@ -91,6 +93,7 @@ function $406796ff087fe49b$export$e375f10ce42261c5(props, state, inputRef) {
91
93
 
92
94
 
93
95
 
96
+
94
97
  function $1e9fce0cfacc738b$export$49ff6f28c54f1cbe(props, state) {
95
98
  let { isDisabled: isDisabled, name: name, validationBehavior: validationBehavior = "aria" } = props;
96
99
  let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
@@ -111,11 +114,17 @@ function $1e9fce0cfacc738b$export$49ff6f28c54f1cbe(props, state) {
111
114
  let domProps = (0, $cKEhs$filterDOMProps)(props, {
112
115
  labelable: true
113
116
  });
117
+ let { focusWithinProps: focusWithinProps } = (0, $cKEhs$useFocusWithin)({
118
+ onBlurWithin: props.onBlur,
119
+ onFocusWithin: props.onFocus,
120
+ onFocusWithinChange: props.onFocusChange
121
+ });
114
122
  return {
115
123
  groupProps: (0, $cKEhs$mergeProps)(domProps, {
116
124
  role: "group",
117
125
  "aria-disabled": isDisabled || undefined,
118
- ...fieldProps
126
+ ...fieldProps,
127
+ ...focusWithinProps
119
128
  }),
120
129
  labelProps: labelProps,
121
130
  descriptionProps: descriptionProps,
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;;AA+BM,SAAS,0CAAY,KAAwB,EAAE,KAAkB,EAAE,QAAqC;IAC7G,+FAA+F;IAC/F,IAAI,kBAAkB,CAAA,GAAA,6BAAqB,EAAE;QAAC,GAAG,KAAK;QAAE,OAAO,MAAM,UAAU;IAAA;IAC/E,IAAI,aAAC,SAAS,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,gBAAgB,iBAAiB;IACxF,IAAI,cAAC,UAAU,cAAE,UAAU,aAAE,SAAS,cAAE,UAAU,cAAE,UAAU,EAAC,GAAG,CAAA,GAAA,gBAAQ,EAAE;QAC1E,GAAG,KAAK;mBACR;IACF,GAAG,OAAO;IAEV,CAAA,GAAA,wBAAgB,EAAE,OAAO,iBAAiB;IAE1C,IAAI,mBAAC,eAAe,cAAE,UAAU,sBAAE,qBAAqB,QAAO,GAAG;IACjE,CAAA,GAAA,gBAAQ,EAAE;QACR,qEAAqE;QACrE,mDAAmD;QACnD,IAAI,SAAS,OAAO,EAClB,SAAS,OAAO,CAAC,aAAa,GAAG;IAErC;IAEA,OAAO;QACL,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;;CDlEC;AEVD;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAWM,MAAM,4CAAoB,IAAI;;CDXpC;;;AA0BM,SAAS,0CAAiB,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,SAAS,IAAI,CAAC,QAAQ;QACjC;IACF;AACF;;","sources":["packages/@react-aria/checkbox/src/index.ts","packages/@react-aria/checkbox/src/useCheckbox.ts","packages/@react-aria/checkbox/src/useCheckboxGroup.ts","packages/@react-aria/checkbox/src/utils.ts","packages/@react-aria/checkbox/src/useCheckboxGroupItem.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport type {CheckboxAria} from './useCheckbox';\nexport {useCheckbox} from './useCheckbox';\nexport {useCheckboxGroup} from './useCheckboxGroup';\nexport {useCheckboxGroupItem} from './useCheckboxGroupItem';\nexport type {AriaCheckboxGroupItemProps, AriaCheckboxGroupProps, AriaCheckboxProps} from '@react-types/checkbox';\nexport type {CheckboxGroupAria} from './useCheckboxGroup';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaCheckboxProps} from '@react-types/checkbox';\nimport {InputHTMLAttributes, RefObject, useEffect} from 'react';\nimport {ToggleState} from '@react-stately/toggle';\nimport {useFormValidation} from '@react-aria/form';\nimport {useFormValidationState} from '@react-stately/form';\nimport {useToggle} from '@react-aria/toggle';\nimport {ValidationResult} from '@react-types/shared';\n\nexport interface CheckboxAria extends ValidationResult {\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Whether the checkbox is selected. */\n isSelected: boolean,\n /** Whether the checkbox is in a pressed state. */\n isPressed: boolean,\n /** Whether the checkbox is disabled. */\n isDisabled: boolean,\n /** Whether the checkbox is read only. */\n isReadOnly: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox component.\n * Checkboxes allow users to select multiple items from a list of individual items, or\n * to mark one individual item as selected.\n * @param props - Props for the checkbox.\n * @param state - State for the checkbox, as returned by `useToggleState`.\n * @param inputRef - A ref for the HTML input element.\n */\nexport function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {\n // Create validation state here because it doesn't make sense to add to general useToggleState.\n let validationState = useFormValidationState({...props, value: state.isSelected});\n let {isInvalid, validationErrors, validationDetails} = validationState.displayValidation;\n let {inputProps, isSelected, isPressed, isDisabled, isReadOnly} = useToggle({\n ...props,\n isInvalid\n }, state, inputRef);\n\n useFormValidation(props, validationState, inputRef);\n\n let {isIndeterminate, isRequired, validationBehavior = 'aria'} = props;\n useEffect(() => {\n // indeterminate is a property, but it can only be set via javascript\n // https://css-tricks.com/indeterminate-checkboxes/\n if (inputRef.current) {\n inputRef.current.indeterminate = isIndeterminate;\n }\n });\n\n return {\n inputProps: {\n ...inputProps,\n checked: isSelected,\n 'aria-required': (isRequired && validationBehavior === 'aria') || undefined,\n required: isRequired && validationBehavior === 'native'\n },\n isSelected,\n isPressed,\n isDisabled,\n isReadOnly,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaCheckboxGroupProps} from '@react-types/checkbox';\nimport {checkboxGroupData} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {DOMAttributes, ValidationResult} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {useField} from '@react-aria/label';\n\nexport interface CheckboxGroupAria extends ValidationResult {\n /** Props for the checkbox group wrapper element. */\n groupProps: DOMAttributes,\n /** Props for the checkbox group's visible label (if any). */\n labelProps: DOMAttributes,\n /** Props for the checkbox group description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the checkbox group error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox group component.\n * Checkbox groups allow users to select multiple items from a list of options.\n * @param props - Props for the checkbox group.\n * @param state - State for the checkbox group, as returned by `useCheckboxGroupState`.\n */\nexport function useCheckboxGroup(props: AriaCheckboxGroupProps, state: CheckboxGroupState): CheckboxGroupAria {\n let {isDisabled, name, validationBehavior = 'aria'} = props;\n let {isInvalid, validationErrors, validationDetails} = state.displayValidation;\n\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n // Checkbox group is not an HTML input element so it\n // shouldn't be labeled by a <label> element.\n labelElementType: 'span',\n isInvalid,\n errorMessage: props.errorMessage || validationErrors\n });\n\n checkboxGroupData.set(state, {\n name,\n descriptionId: descriptionProps.id,\n errorMessageId: errorMessageProps.id,\n validationBehavior\n });\n\n let domProps = filterDOMProps(props, {labelable: true});\n\n return {\n groupProps: mergeProps(domProps, {\n role: 'group',\n 'aria-disabled': isDisabled || undefined,\n ...fieldProps\n }),\n labelProps,\n descriptionProps,\n errorMessageProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CheckboxGroupState} from '@react-stately/checkbox';\n\ninterface CheckboxGroupData {\n name: string,\n descriptionId: string,\n errorMessageId: string,\n validationBehavior: 'aria' | 'native'\n}\n\nexport const checkboxGroupData = new WeakMap<CheckboxGroupState, CheckboxGroupData>();\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaCheckboxGroupItemProps} from '@react-types/checkbox';\nimport {CheckboxAria, useCheckbox} from './useCheckbox';\nimport {checkboxGroupData} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {DEFAULT_VALIDATION_RESULT, privateValidationStateProp, useFormValidationState} from '@react-stately/form';\nimport {RefObject, useEffect, useRef} from 'react';\nimport {useToggleState} from '@react-stately/toggle';\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox component contained within a checkbox group.\n * Checkbox groups allow users to select multiple items from a list of options.\n * @param props - Props for the checkbox.\n * @param state - State for the checkbox, as returned by `useCheckboxGroupState`.\n * @param inputRef - A ref for the HTML input element.\n */\nexport function useCheckboxGroupItem(props: AriaCheckboxGroupItemProps, state: CheckboxGroupState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {\n const toggleState = useToggleState({\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isSelected: state.isSelected(props.value),\n onChange(isSelected) {\n if (isSelected) {\n state.addValue(props.value);\n } else {\n state.removeValue(props.value);\n }\n\n if (props.onChange) {\n props.onChange(isSelected);\n }\n }\n });\n\n let {name, descriptionId, errorMessageId, validationBehavior} = checkboxGroupData.get(state)!;\n validationBehavior = props.validationBehavior ?? validationBehavior;\n\n // Local validation for this checkbox.\n let {realtimeValidation} = useFormValidationState({\n ...props,\n value: toggleState.isSelected,\n // Server validation is handled at the group level.\n name: undefined,\n validationBehavior: 'aria'\n });\n\n // Update the checkbox group state when realtime validation changes.\n let nativeValidation = useRef(DEFAULT_VALIDATION_RESULT);\n let updateValidation = () => {\n state.setInvalid(props.value, realtimeValidation.isInvalid ? realtimeValidation : nativeValidation.current);\n };\n\n useEffect(updateValidation);\n\n // Combine group and checkbox level validation.\n let combinedRealtimeValidation = state.realtimeValidation.isInvalid ? state.realtimeValidation : realtimeValidation;\n let displayValidation = validationBehavior === 'native' ? state.displayValidation : combinedRealtimeValidation;\n\n let res = useCheckbox({\n ...props,\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isDisabled: props.isDisabled || state.isDisabled,\n name: props.name || name,\n isRequired: props.isRequired ?? state.isRequired,\n validationBehavior,\n [privateValidationStateProp]: {\n realtimeValidation: combinedRealtimeValidation,\n displayValidation,\n resetValidation: state.resetValidation,\n commitValidation: state.commitValidation,\n updateValidation(v) {\n nativeValidation.current = v;\n updateValidation();\n }\n }\n }, toggleState, inputRef);\n\n return {\n ...res,\n inputProps: {\n ...res.inputProps,\n 'aria-describedby': [\n props['aria-describedby'],\n state.isInvalid ? errorMessageId : null,\n descriptionId\n ].filter(Boolean).join(' ') || undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;;AAiCM,SAAS,0CAAY,KAAwB,EAAE,KAAkB,EAAE,QAAqC;IAC7G,+FAA+F;IAC/F,IAAI,kBAAkB,CAAA,GAAA,6BAAqB,E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AAoB;IACtB;IAEA,oEAAoE;IACpE,IAAI,mBAAmB,CAAA,GAAA,aAAK,EAAE,CAAA,GAAA,gCAAwB;IACtD,IAAI,mBAAmB;QACrB,MAAM,UAAU,CAAC,MAAM,KAAK,EAAE,mBAAmB,SAAS,GAAG,qBAAqB,iBAAiB,OAAO;IAC5G;IAEA,CAAA,GAAA,gBAAQ,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,iCAAyB,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';\nimport {useFocusWithin} from '@react-aria/interactions';\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 let {focusWithinProps} = useFocusWithin({\n onBlurWithin: props.onBlur,\n onFocusWithin: props.onFocus,\n onFocusWithinChange: props.onFocusChange\n });\n\n return {\n groupProps: mergeProps(domProps, {\n role: 'group',\n 'aria-disabled': isDisabled || undefined,\n ...fieldProps,\n ...focusWithinProps\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
4
  import { ValidationResult, DOMAttributes } from "@react-types/shared";
5
5
  import { CheckboxGroupState } from "@react-stately/checkbox";
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. */
@@ -1 +1 @@
1
- {"mappings":";;;;;AAoBA,6BAA8B,SAAQ,gBAAgB;IACpD,mCAAmC;IACnC,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAClD,wCAAwC;IACxC,UAAU,EAAE,OAAO,CAAC;IACpB,kDAAkD;IAClD,SAAS,EAAE,OAAO,CAAC;IACnB,wCAAwC;IACxC,UAAU,EAAE,OAAO,CAAC;IACpB,yCAAyC;IACzC,UAAU,EAAE,OAAO,CAAA;CACpB;AAED;;;;;;;GAOG;AACH,4BAA4B,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,gBAAgB,CAAC,GAAG,YAAY,CAmC7H;AEzDD,kCAAmC,SAAQ,gBAAgB;IACzD,oDAAoD;IACpD,UAAU,EAAE,aAAa,CAAC;IAC1B,6DAA6D;IAC7D,UAAU,EAAE,aAAa,CAAC;IAC1B,gEAAgE;IAChE,gBAAgB,EAAE,aAAa,CAAC;IAChC,kEAAkE;IAClE,iBAAiB,EAAE,aAAa,CAAA;CACjC;AAED;;;;;GAKG;AACH,iCAAiC,KAAK,EAAE,sBAAsB,EAAE,KAAK,EAAE,kBAAkB,GAAG,iBAAiB,CAmC5G;ACnDD;;;;;;GAMG;AACH,qCAAqC,KAAK,EAAE,0BAA0B,EAAE,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,UAAU,gBAAgB,CAAC,GAAG,YAAY,CAuEtJ;ACnFD,YAAY,EAAC,0BAA0B,EAAE,sBAAsB,EAAE,iBAAiB,EAAC,MAAM,uBAAuB,CAAC","sources":["packages/@react-aria/checkbox/src/packages/@react-aria/checkbox/src/useCheckbox.ts","packages/@react-aria/checkbox/src/packages/@react-aria/checkbox/src/utils.ts","packages/@react-aria/checkbox/src/packages/@react-aria/checkbox/src/useCheckboxGroup.ts","packages/@react-aria/checkbox/src/packages/@react-aria/checkbox/src/useCheckboxGroupItem.ts","packages/@react-aria/checkbox/src/packages/@react-aria/checkbox/src/index.ts","packages/@react-aria/checkbox/src/index.ts"],"sourcesContent":[null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport type {CheckboxAria} from './useCheckbox';\nexport {useCheckbox} from './useCheckbox';\nexport {useCheckboxGroup} from './useCheckboxGroup';\nexport {useCheckboxGroupItem} from './useCheckboxGroupItem';\nexport type {AriaCheckboxGroupItemProps, AriaCheckboxGroupProps, AriaCheckboxProps} from '@react-types/checkbox';\nexport type {CheckboxGroupAria} from './useCheckboxGroup';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
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;AE3DD,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,CA0C5G;AC1DD;;;;;;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.12.0",
3
+ "version": "3.14.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,14 +22,15 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-aria/form": "^3.0.0",
26
- "@react-aria/label": "^3.7.3",
27
- "@react-aria/toggle": "^3.9.0",
28
- "@react-aria/utils": "^3.22.0",
29
- "@react-stately/checkbox": "^3.6.0",
25
+ "@react-aria/form": "^3.0.2",
26
+ "@react-aria/interactions": "^3.21.0",
27
+ "@react-aria/label": "^3.7.5",
28
+ "@react-aria/toggle": "^3.10.1",
29
+ "@react-aria/utils": "^3.23.1",
30
+ "@react-stately/checkbox": "^3.6.2",
30
31
  "@react-stately/form": "^3.0.0",
31
- "@react-stately/toggle": "^3.7.0",
32
- "@react-types/checkbox": "^3.6.0",
32
+ "@react-stately/toggle": "^3.7.1",
33
+ "@react-types/checkbox": "^3.7.0",
33
34
  "@react-types/shared": "^3.22.0",
34
35
  "@swc/helpers": "^0.5.0"
35
36
  },
@@ -39,5 +40,5 @@
39
40
  "publishConfig": {
40
41
  "access": "public"
41
42
  },
42
- "gitHead": "9ce2f674eab2cc8912800d3162dcf00a1ce94274"
43
+ "gitHead": "f040ff62678e6a31375b96c05396df0bae660350"
43
44
  }
@@ -11,7 +11,7 @@
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
16
  import {useFormValidation} from '@react-aria/form';
17
17
  import {useFormValidationState} from '@react-stately/form';
@@ -19,6 +19,8 @@ import {useToggle} from '@react-aria/toggle';
19
19
  import {ValidationResult} from '@react-types/shared';
20
20
 
21
21
  export interface CheckboxAria extends ValidationResult {
22
+ /** Props for the label wrapper element. */
23
+ labelProps: LabelHTMLAttributes<HTMLLabelElement>,
22
24
  /** Props for the input element. */
23
25
  inputProps: InputHTMLAttributes<HTMLInputElement>,
24
26
  /** Whether the checkbox is selected. */
@@ -43,7 +45,7 @@ export function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputR
43
45
  // Create validation state here because it doesn't make sense to add to general useToggleState.
44
46
  let validationState = useFormValidationState({...props, value: state.isSelected});
45
47
  let {isInvalid, validationErrors, validationDetails} = validationState.displayValidation;
46
- let {inputProps, isSelected, isPressed, isDisabled, isReadOnly} = useToggle({
48
+ let {labelProps, inputProps, isSelected, isPressed, isDisabled, isReadOnly} = useToggle({
47
49
  ...props,
48
50
  isInvalid
49
51
  }, state, inputRef);
@@ -55,11 +57,12 @@ export function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputR
55
57
  // indeterminate is a property, but it can only be set via javascript
56
58
  // https://css-tricks.com/indeterminate-checkboxes/
57
59
  if (inputRef.current) {
58
- inputRef.current.indeterminate = isIndeterminate;
60
+ inputRef.current.indeterminate = !!isIndeterminate;
59
61
  }
60
62
  });
61
63
 
62
64
  return {
65
+ labelProps,
63
66
  inputProps: {
64
67
  ...inputProps,
65
68
  checked: isSelected,
@@ -16,6 +16,7 @@ import {CheckboxGroupState} from '@react-stately/checkbox';
16
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
+ import {useFocusWithin} from '@react-aria/interactions';
19
20
 
20
21
  export interface CheckboxGroupAria extends ValidationResult {
21
22
  /** Props for the checkbox group wrapper element. */
@@ -56,11 +57,18 @@ export function useCheckboxGroup(props: AriaCheckboxGroupProps, state: CheckboxG
56
57
 
57
58
  let domProps = filterDOMProps(props, {labelable: true});
58
59
 
60
+ let {focusWithinProps} = useFocusWithin({
61
+ onBlurWithin: props.onBlur,
62
+ onFocusWithin: props.onFocus,
63
+ onFocusWithinChange: props.onFocusChange
64
+ });
65
+
59
66
  return {
60
67
  groupProps: mergeProps(domProps, {
61
68
  role: 'group',
62
69
  'aria-disabled': isDisabled || undefined,
63
- ...fieldProps
70
+ ...fieldProps,
71
+ ...focusWithinProps
64
72
  }),
65
73
  labelProps,
66
74
  descriptionProps,
@@ -17,6 +17,7 @@ import {CheckboxGroupState} from '@react-stately/checkbox';
17
17
  import {DEFAULT_VALIDATION_RESULT, privateValidationStateProp, useFormValidationState} from '@react-stately/form';
18
18
  import {RefObject, useEffect, useRef} from 'react';
19
19
  import {useToggleState} from '@react-stately/toggle';
20
+ import {ValidationResult} from '@react-types/shared';
20
21
 
21
22
  /**
22
23
  * Provides the behavior and accessibility implementation for a checkbox component contained within a checkbox group.
@@ -78,7 +79,7 @@ export function useCheckboxGroupItem(props: AriaCheckboxGroupItemProps, state: C
78
79
  displayValidation,
79
80
  resetValidation: state.resetValidation,
80
81
  commitValidation: state.commitValidation,
81
- updateValidation(v) {
82
+ updateValidation(v: ValidationResult) {
82
83
  nativeValidation.current = v;
83
84
  updateValidation();
84
85
  }
package/src/utils.ts CHANGED
@@ -13,9 +13,9 @@
13
13
  import {CheckboxGroupState} from '@react-stately/checkbox';
14
14
 
15
15
  interface CheckboxGroupData {
16
- name: string,
17
- descriptionId: string,
18
- errorMessageId: string,
16
+ name?: string,
17
+ descriptionId?: string,
18
+ errorMessageId?: string,
19
19
  validationBehavior: 'aria' | 'native'
20
20
  }
21
21