@react-aria/toggle 3.10.11 → 3.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;
|
|
1
|
+
{"mappings":";;;;AAmBA;IACE,+CAA+C;IAC/C,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAClD,+CAA+C;IAC/C,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAClD,sCAAsC;IACtC,UAAU,EAAE,OAAO,CAAC;IACpB,gDAAgD;IAChD,SAAS,EAAE,OAAO,CAAC;IACnB,sCAAsC;IACtC,UAAU,EAAE,OAAO,CAAC;IACpB,uCAAuC;IACvC,UAAU,EAAE,OAAO,CAAC;IACpB,qCAAqC;IACrC,SAAS,EAAE,OAAO,CAAA;CACnB;AAED;;GAEG;AACH,0BAA0B,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,UAAU,gBAAgB,GAAG,IAAI,CAAC,GAAG,UAAU,CAkEzH;AC5FD,YAAY,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAC","sources":["packages/@react-aria/toggle/src/packages/@react-aria/toggle/src/useToggle.ts","packages/@react-aria/toggle/src/packages/@react-aria/toggle/src/index.ts","packages/@react-aria/toggle/src/index.ts"],"sourcesContent":[null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useToggle} from './useToggle';\nexport type {AriaToggleProps} from '@react-types/checkbox';\nexport type {ToggleAria} from './useToggle';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/dist/useToggle.main.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
var $2jyrz$reactariautils = require("@react-aria/utils");
|
|
2
|
-
var $2jyrz$reactariafocus = require("@react-aria/focus");
|
|
3
2
|
var $2jyrz$reactariainteractions = require("@react-aria/interactions");
|
|
4
3
|
|
|
5
4
|
|
|
@@ -20,7 +19,6 @@ $parcel$export(module.exports, "useToggle", () => $ee1b638d33c90dcc$export$cbe85
|
|
|
20
19
|
* governing permissions and limitations under the License.
|
|
21
20
|
*/
|
|
22
21
|
|
|
23
|
-
|
|
24
22
|
function $ee1b638d33c90dcc$export$cbe85ee05b554577(props, state, ref) {
|
|
25
23
|
let { isDisabled: isDisabled = false, isReadOnly: isReadOnly = false, value: value, name: name, children: children, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, validationState: validationState = 'valid', isInvalid: isInvalid } = props;
|
|
26
24
|
let onChange = (e)=>{
|
|
@@ -32,18 +30,20 @@ function $ee1b638d33c90dcc$export$cbe85ee05b554577(props, state, ref) {
|
|
|
32
30
|
let hasChildren = children != null;
|
|
33
31
|
let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;
|
|
34
32
|
if (!hasChildren && !hasAriaLabel) console.warn('If you do not provide children, you must specify an aria-label for accessibility');
|
|
35
|
-
//
|
|
33
|
+
// Handle press state for keyboard interactions and cases where labelProps is not used.
|
|
36
34
|
let { pressProps: pressProps, isPressed: isPressed } = (0, $2jyrz$reactariainteractions.usePress)({
|
|
37
35
|
isDisabled: isDisabled
|
|
38
36
|
});
|
|
39
|
-
//
|
|
37
|
+
// Handle press state on the label.
|
|
40
38
|
let { pressProps: labelProps, isPressed: isLabelPressed } = (0, $2jyrz$reactariainteractions.usePress)({
|
|
41
|
-
isDisabled: isDisabled || isReadOnly,
|
|
42
39
|
onPress () {
|
|
40
|
+
var _ref_current;
|
|
43
41
|
state.toggle();
|
|
44
|
-
|
|
42
|
+
(_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.focus();
|
|
43
|
+
},
|
|
44
|
+
isDisabled: isDisabled || isReadOnly
|
|
45
45
|
});
|
|
46
|
-
let { focusableProps: focusableProps } = (0, $2jyrz$
|
|
46
|
+
let { focusableProps: focusableProps } = (0, $2jyrz$reactariainteractions.useFocusable)(props, ref);
|
|
47
47
|
let interactions = (0, $2jyrz$reactariautils.mergeProps)(pressProps, focusableProps);
|
|
48
48
|
let domProps = (0, $2jyrz$reactariautils.filterDOMProps)(props, {
|
|
49
49
|
labelable: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AA6BM,SAAS,0CAAU,KAAsB,EAAE,KAAkB,EAAE,GAAuC;IAC3G,IAAI,cACF,aAAa,mBACb,aAAa,cACb,KAAK,QACL,IAAI,YACJ,QAAQ,EACR,cAAc,SAAS,EACvB,mBAAmB,cAAc,mBACjC,kBAAkB,oBAClB,SAAS,EACV,GAAG;IAEJ,IAAI,WAAW,CAAC;QACd,iFAAiF;QACjF,wEAAwE;QACxE,EAAE,eAAe;QACjB,MAAM,WAAW,CAAC,EAAE,MAAM,CAAC,OAAO;IACpC;IAEA,IAAI,cAAc,YAAY;IAC9B,IAAI,eAAe,aAAa,QAAQ,kBAAkB;IAC1D,IAAI,CAAC,eAAe,CAAC,cACnB,QAAQ,IAAI,CAAC;IAGf,uFAAuF;IACvF,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,qCAAO,EAAE;oBACrC;IACF;IAEA,mCAAmC;IACnC,IAAI,EAAC,YAAY,UAAU,EAAE,WAAW,cAAc,EAAC,GAAG,CAAA,GAAA,qCAAO,EAAE;QACjE;gBAEE;YADA,MAAM,MAAM;aACZ,eAAA,IAAI,OAAO,cAAX,mCAAA,aAAa,KAAK;QACpB;QACA,YAAY,cAAc;IAC5B;IAEA,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,yCAAW,EAAE,OAAO;IAC3C,IAAI,eAAe,CAAA,GAAA,gCAAS,EAAE,YAAY;IAC1C,IAAI,WAAW,CAAA,GAAA,oCAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,CAAA,GAAA,kCAAW,EAAE,KAAK,MAAM,UAAU,EAAE,MAAM,WAAW;IAErD,OAAO;QACL,YAAY,CAAA,GAAA,gCAAS,EAAE,YAAY;YAAC,SAAS,CAAA,IAAK,EAAE,cAAc;QAAE;QACpE,YAAY,CAAA,GAAA,gCAAS,EAAE,UAAU;YAC/B,gBAAgB,aAAa,oBAAoB,aAAa;YAC9D,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,iBAAiB,KAAK,CAAC,gBAAgB;YACvC,iBAAiB,cAAc;sBAC/B;YACA,UAAU;YACV,GAAI,SAAS,OAAO,CAAC,IAAI;uBAAC;YAAK,CAAC;kBAChC;YACA,MAAM;YACN,GAAG,YAAY;QACjB;QACA,YAAY,MAAM,UAAU;QAC5B,WAAW,aAAa;oBACxB;oBACA;QACA,WAAW,aAAa,oBAAoB;IAC9C;AACF","sources":["packages/@react-aria/toggle/src/useToggle.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 {AriaToggleProps} from '@react-types/checkbox';\nimport {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';\nimport {InputHTMLAttributes, LabelHTMLAttributes} from 'react';\nimport {RefObject} from '@react-types/shared';\nimport {ToggleState} from '@react-stately/toggle';\nimport {useFocusable, usePress} from '@react-aria/interactions';\n\nexport interface ToggleAria {\n /** Props to be spread on the label element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>,\n /** Props to be spread on the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Whether the toggle is selected. */\n isSelected: boolean,\n /** Whether the toggle is in a pressed state. */\n isPressed: boolean,\n /** Whether the toggle is disabled. */\n isDisabled: boolean,\n /** Whether the toggle is read only. */\n isReadOnly: boolean,\n /** Whether the toggle is invalid. */\n isInvalid: boolean\n}\n\n/**\n * Handles interactions for toggle elements, e.g. Checkboxes and Switches.\n */\nexport function useToggle(props: AriaToggleProps, state: ToggleState, ref: RefObject<HTMLInputElement | null>): ToggleAria {\n let {\n isDisabled = false,\n isReadOnly = false,\n value,\n name,\n children,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledby,\n validationState = 'valid',\n isInvalid\n } = props;\n\n let onChange = (e) => {\n // since we spread props on label, onChange will end up there as well as in here.\n // so we have to stop propagation at the lowest level that we care about\n e.stopPropagation();\n state.setSelected(e.target.checked);\n };\n\n let hasChildren = children != null;\n let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;\n if (!hasChildren && !hasAriaLabel) {\n console.warn('If you do not provide children, you must specify an aria-label for accessibility');\n }\n\n // Handle press state for keyboard interactions and cases where labelProps is not used.\n let {pressProps, isPressed} = usePress({\n isDisabled\n });\n\n // Handle press state on the label.\n let {pressProps: labelProps, isPressed: isLabelPressed} = usePress({\n onPress() {\n state.toggle();\n ref.current?.focus();\n },\n isDisabled: isDisabled || isReadOnly\n });\n\n let {focusableProps} = useFocusable(props, ref);\n let interactions = mergeProps(pressProps, focusableProps);\n let domProps = filterDOMProps(props, {labelable: true});\n\n useFormReset(ref, state.isSelected, state.setSelected);\n\n return {\n labelProps: mergeProps(labelProps, {onClick: e => e.preventDefault()}),\n inputProps: mergeProps(domProps, {\n 'aria-invalid': isInvalid || validationState === 'invalid' || undefined,\n 'aria-errormessage': props['aria-errormessage'],\n 'aria-controls': props['aria-controls'],\n 'aria-readonly': isReadOnly || undefined,\n onChange,\n disabled: isDisabled,\n ...(value == null ? {} : {value}),\n name,\n type: 'checkbox',\n ...interactions\n }),\n isSelected: state.isSelected,\n isPressed: isPressed || isLabelPressed,\n isDisabled,\n isReadOnly,\n isInvalid: isInvalid || validationState === 'invalid'\n };\n}\n"],"names":[],"version":3,"file":"useToggle.main.js.map"}
|
package/dist/useToggle.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {mergeProps as $bvdLj$mergeProps, filterDOMProps as $bvdLj$filterDOMProps, useFormReset as $bvdLj$useFormReset} from "@react-aria/utils";
|
|
2
|
-
import {useFocusable as $bvdLj$useFocusable} from "@react-aria/
|
|
3
|
-
import {usePress as $bvdLj$usePress} from "@react-aria/interactions";
|
|
2
|
+
import {usePress as $bvdLj$usePress, useFocusable as $bvdLj$useFocusable} from "@react-aria/interactions";
|
|
4
3
|
|
|
5
4
|
/*
|
|
6
5
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -14,7 +13,6 @@ import {usePress as $bvdLj$usePress} from "@react-aria/interactions";
|
|
|
14
13
|
* governing permissions and limitations under the License.
|
|
15
14
|
*/
|
|
16
15
|
|
|
17
|
-
|
|
18
16
|
function $d2c8e2b0480f3f34$export$cbe85ee05b554577(props, state, ref) {
|
|
19
17
|
let { isDisabled: isDisabled = false, isReadOnly: isReadOnly = false, value: value, name: name, children: children, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, validationState: validationState = 'valid', isInvalid: isInvalid } = props;
|
|
20
18
|
let onChange = (e)=>{
|
|
@@ -26,16 +24,18 @@ function $d2c8e2b0480f3f34$export$cbe85ee05b554577(props, state, ref) {
|
|
|
26
24
|
let hasChildren = children != null;
|
|
27
25
|
let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;
|
|
28
26
|
if (!hasChildren && !hasAriaLabel) console.warn('If you do not provide children, you must specify an aria-label for accessibility');
|
|
29
|
-
//
|
|
27
|
+
// Handle press state for keyboard interactions and cases where labelProps is not used.
|
|
30
28
|
let { pressProps: pressProps, isPressed: isPressed } = (0, $bvdLj$usePress)({
|
|
31
29
|
isDisabled: isDisabled
|
|
32
30
|
});
|
|
33
|
-
//
|
|
31
|
+
// Handle press state on the label.
|
|
34
32
|
let { pressProps: labelProps, isPressed: isLabelPressed } = (0, $bvdLj$usePress)({
|
|
35
|
-
isDisabled: isDisabled || isReadOnly,
|
|
36
33
|
onPress () {
|
|
34
|
+
var _ref_current;
|
|
37
35
|
state.toggle();
|
|
38
|
-
|
|
36
|
+
(_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.focus();
|
|
37
|
+
},
|
|
38
|
+
isDisabled: isDisabled || isReadOnly
|
|
39
39
|
});
|
|
40
40
|
let { focusableProps: focusableProps } = (0, $bvdLj$useFocusable)(props, ref);
|
|
41
41
|
let interactions = (0, $bvdLj$mergeProps)(pressProps, focusableProps);
|
package/dist/useToggle.module.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {mergeProps as $bvdLj$mergeProps, filterDOMProps as $bvdLj$filterDOMProps, useFormReset as $bvdLj$useFormReset} from "@react-aria/utils";
|
|
2
|
-
import {useFocusable as $bvdLj$useFocusable} from "@react-aria/
|
|
3
|
-
import {usePress as $bvdLj$usePress} from "@react-aria/interactions";
|
|
2
|
+
import {usePress as $bvdLj$usePress, useFocusable as $bvdLj$useFocusable} from "@react-aria/interactions";
|
|
4
3
|
|
|
5
4
|
/*
|
|
6
5
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -14,7 +13,6 @@ import {usePress as $bvdLj$usePress} from "@react-aria/interactions";
|
|
|
14
13
|
* governing permissions and limitations under the License.
|
|
15
14
|
*/
|
|
16
15
|
|
|
17
|
-
|
|
18
16
|
function $d2c8e2b0480f3f34$export$cbe85ee05b554577(props, state, ref) {
|
|
19
17
|
let { isDisabled: isDisabled = false, isReadOnly: isReadOnly = false, value: value, name: name, children: children, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, validationState: validationState = 'valid', isInvalid: isInvalid } = props;
|
|
20
18
|
let onChange = (e)=>{
|
|
@@ -26,16 +24,18 @@ function $d2c8e2b0480f3f34$export$cbe85ee05b554577(props, state, ref) {
|
|
|
26
24
|
let hasChildren = children != null;
|
|
27
25
|
let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;
|
|
28
26
|
if (!hasChildren && !hasAriaLabel) console.warn('If you do not provide children, you must specify an aria-label for accessibility');
|
|
29
|
-
//
|
|
27
|
+
// Handle press state for keyboard interactions and cases where labelProps is not used.
|
|
30
28
|
let { pressProps: pressProps, isPressed: isPressed } = (0, $bvdLj$usePress)({
|
|
31
29
|
isDisabled: isDisabled
|
|
32
30
|
});
|
|
33
|
-
//
|
|
31
|
+
// Handle press state on the label.
|
|
34
32
|
let { pressProps: labelProps, isPressed: isLabelPressed } = (0, $bvdLj$usePress)({
|
|
35
|
-
isDisabled: isDisabled || isReadOnly,
|
|
36
33
|
onPress () {
|
|
34
|
+
var _ref_current;
|
|
37
35
|
state.toggle();
|
|
38
|
-
|
|
36
|
+
(_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.focus();
|
|
37
|
+
},
|
|
38
|
+
isDisabled: isDisabled || isReadOnly
|
|
39
39
|
});
|
|
40
40
|
let { focusableProps: focusableProps } = (0, $bvdLj$useFocusable)(props, ref);
|
|
41
41
|
let interactions = (0, $bvdLj$mergeProps)(pressProps, focusableProps);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AA6BM,SAAS,0CAAU,KAAsB,EAAE,KAAkB,EAAE,GAAuC;IAC3G,IAAI,cACF,aAAa,mBACb,aAAa,cACb,KAAK,QACL,IAAI,YACJ,QAAQ,EACR,cAAc,SAAS,EACvB,mBAAmB,cAAc,mBACjC,kBAAkB,oBAClB,SAAS,EACV,GAAG;IAEJ,IAAI,WAAW,CAAC;QACd,iFAAiF;QACjF,wEAAwE;QACxE,EAAE,eAAe;QACjB,MAAM,WAAW,CAAC,EAAE,MAAM,CAAC,OAAO;IACpC;IAEA,IAAI,cAAc,YAAY;IAC9B,IAAI,eAAe,aAAa,QAAQ,kBAAkB;IAC1D,IAAI,CAAC,eAAe,CAAC,cACnB,QAAQ,IAAI,CAAC;IAGf,uFAAuF;IACvF,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;oBACrC;IACF;IAEA,mCAAmC;IACnC,IAAI,EAAC,YAAY,UAAU,EAAE,WAAW,cAAc,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;QACjE;gBAEE;YADA,MAAM,MAAM;aACZ,eAAA,IAAI,OAAO,cAAX,mCAAA,aAAa,KAAK;QACpB;QACA,YAAY,cAAc;IAC5B;IAEA,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,mBAAW,EAAE,OAAO;IAC3C,IAAI,eAAe,CAAA,GAAA,iBAAS,EAAE,YAAY;IAC1C,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,CAAA,GAAA,mBAAW,EAAE,KAAK,MAAM,UAAU,EAAE,MAAM,WAAW;IAErD,OAAO;QACL,YAAY,CAAA,GAAA,iBAAS,EAAE,YAAY;YAAC,SAAS,CAAA,IAAK,EAAE,cAAc;QAAE;QACpE,YAAY,CAAA,GAAA,iBAAS,EAAE,UAAU;YAC/B,gBAAgB,aAAa,oBAAoB,aAAa;YAC9D,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,iBAAiB,KAAK,CAAC,gBAAgB;YACvC,iBAAiB,cAAc;sBAC/B;YACA,UAAU;YACV,GAAI,SAAS,OAAO,CAAC,IAAI;uBAAC;YAAK,CAAC;kBAChC;YACA,MAAM;YACN,GAAG,YAAY;QACjB;QACA,YAAY,MAAM,UAAU;QAC5B,WAAW,aAAa;oBACxB;oBACA;QACA,WAAW,aAAa,oBAAoB;IAC9C;AACF","sources":["packages/@react-aria/toggle/src/useToggle.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 {AriaToggleProps} from '@react-types/checkbox';\nimport {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';\nimport {InputHTMLAttributes, LabelHTMLAttributes} from 'react';\nimport {RefObject} from '@react-types/shared';\nimport {ToggleState} from '@react-stately/toggle';\nimport {useFocusable, usePress} from '@react-aria/interactions';\n\nexport interface ToggleAria {\n /** Props to be spread on the label element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>,\n /** Props to be spread on the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Whether the toggle is selected. */\n isSelected: boolean,\n /** Whether the toggle is in a pressed state. */\n isPressed: boolean,\n /** Whether the toggle is disabled. */\n isDisabled: boolean,\n /** Whether the toggle is read only. */\n isReadOnly: boolean,\n /** Whether the toggle is invalid. */\n isInvalid: boolean\n}\n\n/**\n * Handles interactions for toggle elements, e.g. Checkboxes and Switches.\n */\nexport function useToggle(props: AriaToggleProps, state: ToggleState, ref: RefObject<HTMLInputElement | null>): ToggleAria {\n let {\n isDisabled = false,\n isReadOnly = false,\n value,\n name,\n children,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledby,\n validationState = 'valid',\n isInvalid\n } = props;\n\n let onChange = (e) => {\n // since we spread props on label, onChange will end up there as well as in here.\n // so we have to stop propagation at the lowest level that we care about\n e.stopPropagation();\n state.setSelected(e.target.checked);\n };\n\n let hasChildren = children != null;\n let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;\n if (!hasChildren && !hasAriaLabel) {\n console.warn('If you do not provide children, you must specify an aria-label for accessibility');\n }\n\n // Handle press state for keyboard interactions and cases where labelProps is not used.\n let {pressProps, isPressed} = usePress({\n isDisabled\n });\n\n // Handle press state on the label.\n let {pressProps: labelProps, isPressed: isLabelPressed} = usePress({\n onPress() {\n state.toggle();\n ref.current?.focus();\n },\n isDisabled: isDisabled || isReadOnly\n });\n\n let {focusableProps} = useFocusable(props, ref);\n let interactions = mergeProps(pressProps, focusableProps);\n let domProps = filterDOMProps(props, {labelable: true});\n\n useFormReset(ref, state.isSelected, state.setSelected);\n\n return {\n labelProps: mergeProps(labelProps, {onClick: e => e.preventDefault()}),\n inputProps: mergeProps(domProps, {\n 'aria-invalid': isInvalid || validationState === 'invalid' || undefined,\n 'aria-errormessage': props['aria-errormessage'],\n 'aria-controls': props['aria-controls'],\n 'aria-readonly': isReadOnly || undefined,\n onChange,\n disabled: isDisabled,\n ...(value == null ? {} : {value}),\n name,\n type: 'checkbox',\n ...interactions\n }),\n isSelected: state.isSelected,\n isPressed: isPressed || isLabelPressed,\n isDisabled,\n isReadOnly,\n isInvalid: isInvalid || validationState === 'invalid'\n };\n}\n"],"names":[],"version":3,"file":"useToggle.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/toggle",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.11.1",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,12 +22,11 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-aria/
|
|
26
|
-
"@react-aria/
|
|
27
|
-
"@react-
|
|
28
|
-
"@react-
|
|
29
|
-
"@react-types/
|
|
30
|
-
"@react-types/shared": "^3.27.0",
|
|
25
|
+
"@react-aria/interactions": "^3.24.1",
|
|
26
|
+
"@react-aria/utils": "^3.28.1",
|
|
27
|
+
"@react-stately/toggle": "^3.8.2",
|
|
28
|
+
"@react-types/checkbox": "^3.9.2",
|
|
29
|
+
"@react-types/shared": "^3.28.0",
|
|
31
30
|
"@swc/helpers": "^0.5.0"
|
|
32
31
|
},
|
|
33
32
|
"peerDependencies": {
|
|
@@ -37,5 +36,5 @@
|
|
|
37
36
|
"publishConfig": {
|
|
38
37
|
"access": "public"
|
|
39
38
|
},
|
|
40
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "9c4ebbc0c1972cc880febc29de995ca58caa3ba4"
|
|
41
40
|
}
|
package/src/useToggle.ts
CHANGED
|
@@ -15,8 +15,7 @@ import {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';
|
|
|
15
15
|
import {InputHTMLAttributes, LabelHTMLAttributes} from 'react';
|
|
16
16
|
import {RefObject} from '@react-types/shared';
|
|
17
17
|
import {ToggleState} from '@react-stately/toggle';
|
|
18
|
-
import {useFocusable} from '@react-aria/
|
|
19
|
-
import {usePress} from '@react-aria/interactions';
|
|
18
|
+
import {useFocusable, usePress} from '@react-aria/interactions';
|
|
20
19
|
|
|
21
20
|
export interface ToggleAria {
|
|
22
21
|
/** Props to be spread on the label element. */
|
|
@@ -64,17 +63,18 @@ export function useToggle(props: AriaToggleProps, state: ToggleState, ref: RefOb
|
|
|
64
63
|
console.warn('If you do not provide children, you must specify an aria-label for accessibility');
|
|
65
64
|
}
|
|
66
65
|
|
|
67
|
-
//
|
|
66
|
+
// Handle press state for keyboard interactions and cases where labelProps is not used.
|
|
68
67
|
let {pressProps, isPressed} = usePress({
|
|
69
68
|
isDisabled
|
|
70
69
|
});
|
|
71
70
|
|
|
72
|
-
//
|
|
71
|
+
// Handle press state on the label.
|
|
73
72
|
let {pressProps: labelProps, isPressed: isLabelPressed} = usePress({
|
|
74
|
-
isDisabled: isDisabled || isReadOnly,
|
|
75
73
|
onPress() {
|
|
76
74
|
state.toggle();
|
|
77
|
-
|
|
75
|
+
ref.current?.focus();
|
|
76
|
+
},
|
|
77
|
+
isDisabled: isDisabled || isReadOnly
|
|
78
78
|
});
|
|
79
79
|
|
|
80
80
|
let {focusableProps} = useFocusable(props, ref);
|