@react-aria/checkbox 3.16.1 → 3.16.2
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/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;AAsBA,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,GAAG,IAAI,CAAC,GAAG,YAAY,
|
|
1
|
+
{"mappings":";;;;;AAsBA,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,GAAG,IAAI,CAAC,GAAG,YAAY,CA0DpI;AEnFD,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,CA2C5G;AC3DD;;;;;;GAMG;AACH,qCAAqC,KAAK,EAAE,0BAA0B,EAAE,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,UAAU,gBAAgB,GAAG,IAAI,CAAC,GAAG,YAAY,CAyE7J;ACtFD,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/dist/useCheckbox.main.js
CHANGED
|
@@ -56,7 +56,11 @@ function $468c774d7db917b7$export$e375f10ce42261c5(props, state, inputRef) {
|
|
|
56
56
|
}
|
|
57
57
|
});
|
|
58
58
|
return {
|
|
59
|
-
labelProps: (0, $ar5WQ$reactariautils.mergeProps)(labelProps, pressProps)
|
|
59
|
+
labelProps: (0, $ar5WQ$reactariautils.mergeProps)(labelProps, pressProps, (0, $ar5WQ$react.useMemo)(()=>({
|
|
60
|
+
// Prevent label from being focused when mouse down on it.
|
|
61
|
+
// Note, this does not prevent the input from being focused in the `click` event.
|
|
62
|
+
onMouseDown: (e)=>e.preventDefault()
|
|
63
|
+
}), [])),
|
|
60
64
|
inputProps: {
|
|
61
65
|
...inputProps,
|
|
62
66
|
checked: isSelected,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAmCM,SAAS,0CAAY,KAAwB,EAAE,KAAkB,EAAE,QAA4C;IACpH,+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,GA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qCAAO,EAAE;QAC1B,YAAY,cAAc;QAC1B;YACE,mBAAmB;YACnB,IAAI,EAAC,CAAC,CAAA,GAAA,kDAAyB,EAAE,EAAE,oBAAoB,EAAC,GAAG;YAE3D,IAAI,oBAAC,gBAAgB,EAAC,GAAG,uBACvB,uBACA;YAEF;QACF;IACF;IAEA,OAAO;QACL,YAAY,CAAA,GAAA,gCAAS,EACnB,YACA,YACA,CAAA,GAAA,oBAAM,EAAE,IAAO,CAAA;gBACb,0DAA0D;gBAC1D,iFAAiF;gBACjF,aAAa,CAAA,IAAK,EAAE,cAAc;YACpC,CAAA,GAAI,EAAE;QACR,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","sources":["packages/@react-aria/checkbox/src/useCheckbox.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaCheckboxProps} from '@react-types/checkbox';\nimport {InputHTMLAttributes, LabelHTMLAttributes, useEffect, useMemo} from 'react';\nimport {mergeProps} from '@react-aria/utils';\nimport {privateValidationStateProp, useFormValidationState} from '@react-stately/form';\nimport {RefObject, ValidationResult} from '@react-types/shared';\nimport {ToggleState} from '@react-stately/toggle';\nimport {useFormValidation} from '@react-aria/form';\nimport {usePress} from '@react-aria/interactions';\nimport {useToggle} from '@react-aria/toggle';\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 | null>): 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 // Reset validation state on label press for checkbox with a hidden input.\n let {pressProps} = usePress({\n isDisabled: isDisabled || isReadOnly,\n onPress() {\n // @ts-expect-error\n let {[privateValidationStateProp]: groupValidationState} = props;\n\n let {commitValidation} = groupValidationState\n ? groupValidationState\n : validationState;\n\n commitValidation();\n }\n });\n\n return {\n labelProps: mergeProps(\n labelProps,\n pressProps,\n useMemo(() => ({\n // Prevent label from being focused when mouse down on it.\n // Note, this does not prevent the input from being focused in the `click` event.\n onMouseDown: e => e.preventDefault()\n }), [])),\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"],"names":[],"version":3,"file":"useCheckbox.main.js.map"}
|
package/dist/useCheckbox.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {useEffect as $jNP0e$useEffect} from "react";
|
|
1
|
+
import {useEffect as $jNP0e$useEffect, useMemo as $jNP0e$useMemo} from "react";
|
|
2
2
|
import {mergeProps as $jNP0e$mergeProps} from "@react-aria/utils";
|
|
3
3
|
import {useFormValidationState as $jNP0e$useFormValidationState, privateValidationStateProp as $jNP0e$privateValidationStateProp} from "@react-stately/form";
|
|
4
4
|
import {useFormValidation as $jNP0e$useFormValidation} from "@react-aria/form";
|
|
@@ -50,7 +50,11 @@ function $406796ff087fe49b$export$e375f10ce42261c5(props, state, inputRef) {
|
|
|
50
50
|
}
|
|
51
51
|
});
|
|
52
52
|
return {
|
|
53
|
-
labelProps: (0, $jNP0e$mergeProps)(labelProps, pressProps)
|
|
53
|
+
labelProps: (0, $jNP0e$mergeProps)(labelProps, pressProps, (0, $jNP0e$useMemo)(()=>({
|
|
54
|
+
// Prevent label from being focused when mouse down on it.
|
|
55
|
+
// Note, this does not prevent the input from being focused in the `click` event.
|
|
56
|
+
onMouseDown: (e)=>e.preventDefault()
|
|
57
|
+
}), [])),
|
|
54
58
|
inputProps: {
|
|
55
59
|
...inputProps,
|
|
56
60
|
checked: isSelected,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {useEffect as $jNP0e$useEffect} from "react";
|
|
1
|
+
import {useEffect as $jNP0e$useEffect, useMemo as $jNP0e$useMemo} from "react";
|
|
2
2
|
import {mergeProps as $jNP0e$mergeProps} from "@react-aria/utils";
|
|
3
3
|
import {useFormValidationState as $jNP0e$useFormValidationState, privateValidationStateProp as $jNP0e$privateValidationStateProp} from "@react-stately/form";
|
|
4
4
|
import {useFormValidation as $jNP0e$useFormValidation} from "@react-aria/form";
|
|
@@ -50,7 +50,11 @@ function $406796ff087fe49b$export$e375f10ce42261c5(props, state, inputRef) {
|
|
|
50
50
|
}
|
|
51
51
|
});
|
|
52
52
|
return {
|
|
53
|
-
labelProps: (0, $jNP0e$mergeProps)(labelProps, pressProps)
|
|
53
|
+
labelProps: (0, $jNP0e$mergeProps)(labelProps, pressProps, (0, $jNP0e$useMemo)(()=>({
|
|
54
|
+
// Prevent label from being focused when mouse down on it.
|
|
55
|
+
// Note, this does not prevent the input from being focused in the `click` event.
|
|
56
|
+
onMouseDown: (e)=>e.preventDefault()
|
|
57
|
+
}), [])),
|
|
54
58
|
inputProps: {
|
|
55
59
|
...inputProps,
|
|
56
60
|
checked: isSelected,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAmCM,SAAS,0CAAY,KAAwB,EAAE,KAAkB,EAAE,QAA4C;IACpH,+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,cAAE,UAAU,aAAE,SAAS,cAAE,UAAU,cAAE,UAAU,EAAC,GAAG,CAAA,GAAA,gBAAQ,EAAE;QACtF,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,CAAC,CAAC;IAEvC;IAEA,0EAA0E;IAC1E,IAAI,c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,GAAG,uBACvB,uBACA;YAEF;QACF;IACF;IAEA,OAAO;QACL,YAAY,CAAA,GAAA,iBAAS,EACnB,YACA,YACA,CAAA,GAAA,cAAM,EAAE,IAAO,CAAA;gBACb,0DAA0D;gBAC1D,iFAAiF;gBACjF,aAAa,CAAA,IAAK,EAAE,cAAc;YACpC,CAAA,GAAI,EAAE;QACR,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","sources":["packages/@react-aria/checkbox/src/useCheckbox.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaCheckboxProps} from '@react-types/checkbox';\nimport {InputHTMLAttributes, LabelHTMLAttributes, useEffect, useMemo} from 'react';\nimport {mergeProps} from '@react-aria/utils';\nimport {privateValidationStateProp, useFormValidationState} from '@react-stately/form';\nimport {RefObject, ValidationResult} from '@react-types/shared';\nimport {ToggleState} from '@react-stately/toggle';\nimport {useFormValidation} from '@react-aria/form';\nimport {usePress} from '@react-aria/interactions';\nimport {useToggle} from '@react-aria/toggle';\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 | null>): 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 // Reset validation state on label press for checkbox with a hidden input.\n let {pressProps} = usePress({\n isDisabled: isDisabled || isReadOnly,\n onPress() {\n // @ts-expect-error\n let {[privateValidationStateProp]: groupValidationState} = props;\n\n let {commitValidation} = groupValidationState\n ? groupValidationState\n : validationState;\n\n commitValidation();\n }\n });\n\n return {\n labelProps: mergeProps(\n labelProps,\n pressProps,\n useMemo(() => ({\n // Prevent label from being focused when mouse down on it.\n // Note, this does not prevent the input from being focused in the `click` event.\n onMouseDown: e => e.preventDefault()\n }), [])),\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"],"names":[],"version":3,"file":"useCheckbox.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/checkbox",
|
|
3
|
-
"version": "3.16.
|
|
3
|
+
"version": "3.16.2",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -26,16 +26,16 @@
|
|
|
26
26
|
"url": "https://github.com/adobe/react-spectrum"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@react-aria/form": "^3.1.
|
|
30
|
-
"@react-aria/interactions": "^3.25.
|
|
31
|
-
"@react-aria/label": "^3.7.
|
|
32
|
-
"@react-aria/toggle": "^3.12.
|
|
33
|
-
"@react-aria/utils": "^3.
|
|
34
|
-
"@react-stately/checkbox": "^3.7.
|
|
35
|
-
"@react-stately/form": "^3.2.
|
|
36
|
-
"@react-stately/toggle": "^3.9.
|
|
37
|
-
"@react-types/checkbox": "^3.10.
|
|
38
|
-
"@react-types/shared": "^3.32.
|
|
29
|
+
"@react-aria/form": "^3.1.2",
|
|
30
|
+
"@react-aria/interactions": "^3.25.6",
|
|
31
|
+
"@react-aria/label": "^3.7.22",
|
|
32
|
+
"@react-aria/toggle": "^3.12.2",
|
|
33
|
+
"@react-aria/utils": "^3.31.0",
|
|
34
|
+
"@react-stately/checkbox": "^3.7.2",
|
|
35
|
+
"@react-stately/form": "^3.2.2",
|
|
36
|
+
"@react-stately/toggle": "^3.9.2",
|
|
37
|
+
"@react-types/checkbox": "^3.10.2",
|
|
38
|
+
"@react-types/shared": "^3.32.1",
|
|
39
39
|
"@swc/helpers": "^0.5.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "0bda51183baa23306342af32a82012ea0fe0f2dc"
|
|
49
49
|
}
|
package/src/useCheckbox.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import {AriaCheckboxProps} from '@react-types/checkbox';
|
|
14
|
-
import {InputHTMLAttributes, LabelHTMLAttributes, useEffect} from 'react';
|
|
14
|
+
import {InputHTMLAttributes, LabelHTMLAttributes, useEffect, useMemo} from 'react';
|
|
15
15
|
import {mergeProps} from '@react-aria/utils';
|
|
16
16
|
import {privateValidationStateProp, useFormValidationState} from '@react-stately/form';
|
|
17
17
|
import {RefObject, ValidationResult} from '@react-types/shared';
|
|
@@ -69,17 +69,24 @@ export function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputR
|
|
|
69
69
|
onPress() {
|
|
70
70
|
// @ts-expect-error
|
|
71
71
|
let {[privateValidationStateProp]: groupValidationState} = props;
|
|
72
|
-
|
|
72
|
+
|
|
73
73
|
let {commitValidation} = groupValidationState
|
|
74
74
|
? groupValidationState
|
|
75
75
|
: validationState;
|
|
76
|
-
|
|
76
|
+
|
|
77
77
|
commitValidation();
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
return {
|
|
82
|
-
labelProps: mergeProps(
|
|
82
|
+
labelProps: mergeProps(
|
|
83
|
+
labelProps,
|
|
84
|
+
pressProps,
|
|
85
|
+
useMemo(() => ({
|
|
86
|
+
// Prevent label from being focused when mouse down on it.
|
|
87
|
+
// Note, this does not prevent the input from being focused in the `click` event.
|
|
88
|
+
onMouseDown: e => e.preventDefault()
|
|
89
|
+
}), [])),
|
|
83
90
|
inputProps: {
|
|
84
91
|
...inputProps,
|
|
85
92
|
checked: isSelected,
|