@react-aria/toggle 3.9.0 → 3.10.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/import.mjs CHANGED
@@ -40,6 +40,13 @@ function $d2c8e2b0480f3f34$export$cbe85ee05b554577(props, state, ref) {
40
40
  let { pressProps: pressProps, isPressed: isPressed } = (0, $7CUUz$usePress)({
41
41
  isDisabled: isDisabled
42
42
  });
43
+ // iOS does not toggle checkboxes if you drag off and back onto the label, so handle it ourselves.
44
+ let { pressProps: labelProps, isPressed: isLabelPressed } = (0, $7CUUz$usePress)({
45
+ isDisabled: isDisabled || isReadOnly,
46
+ onPress () {
47
+ state.toggle();
48
+ }
49
+ });
43
50
  let { focusableProps: focusableProps } = (0, $7CUUz$useFocusable)(props, ref);
44
51
  let interactions = (0, $7CUUz$mergeProps)(pressProps, focusableProps);
45
52
  let domProps = (0, $7CUUz$filterDOMProps)(props, {
@@ -47,6 +54,9 @@ function $d2c8e2b0480f3f34$export$cbe85ee05b554577(props, state, ref) {
47
54
  });
48
55
  (0, $7CUUz$useFormReset)(ref, state.isSelected, state.setSelected);
49
56
  return {
57
+ labelProps: (0, $7CUUz$mergeProps)(labelProps, {
58
+ onClick: (e)=>e.preventDefault()
59
+ }),
50
60
  inputProps: (0, $7CUUz$mergeProps)(domProps, {
51
61
  "aria-invalid": isInvalid || validationState === "invalid" || undefined,
52
62
  "aria-errormessage": props["aria-errormessage"],
@@ -62,7 +72,7 @@ function $d2c8e2b0480f3f34$export$cbe85ee05b554577(props, state, ref) {
62
72
  ...interactions
63
73
  }),
64
74
  isSelected: state.isSelected,
65
- isPressed: isPressed,
75
+ isPressed: isPressed || isLabelPressed,
66
76
  isDisabled: isDisabled,
67
77
  isReadOnly: isReadOnly,
68
78
  isInvalid: isInvalid || validationState === "invalid"
package/dist/main.js CHANGED
@@ -46,6 +46,13 @@ function $ee1b638d33c90dcc$export$cbe85ee05b554577(props, state, ref) {
46
46
  let { pressProps: pressProps, isPressed: isPressed } = (0, $7WOm2$reactariainteractions.usePress)({
47
47
  isDisabled: isDisabled
48
48
  });
49
+ // iOS does not toggle checkboxes if you drag off and back onto the label, so handle it ourselves.
50
+ let { pressProps: labelProps, isPressed: isLabelPressed } = (0, $7WOm2$reactariainteractions.usePress)({
51
+ isDisabled: isDisabled || isReadOnly,
52
+ onPress () {
53
+ state.toggle();
54
+ }
55
+ });
49
56
  let { focusableProps: focusableProps } = (0, $7WOm2$reactariafocus.useFocusable)(props, ref);
50
57
  let interactions = (0, $7WOm2$reactariautils.mergeProps)(pressProps, focusableProps);
51
58
  let domProps = (0, $7WOm2$reactariautils.filterDOMProps)(props, {
@@ -53,6 +60,9 @@ function $ee1b638d33c90dcc$export$cbe85ee05b554577(props, state, ref) {
53
60
  });
54
61
  (0, $7WOm2$reactariautils.useFormReset)(ref, state.isSelected, state.setSelected);
55
62
  return {
63
+ labelProps: (0, $7WOm2$reactariautils.mergeProps)(labelProps, {
64
+ onClick: (e)=>e.preventDefault()
65
+ }),
56
66
  inputProps: (0, $7WOm2$reactariautils.mergeProps)(domProps, {
57
67
  "aria-invalid": isInvalid || validationState === "invalid" || undefined,
58
68
  "aria-errormessage": props["aria-errormessage"],
@@ -68,7 +78,7 @@ function $ee1b638d33c90dcc$export$cbe85ee05b554577(props, state, ref) {
68
78
  ...interactions
69
79
  }),
70
80
  isSelected: state.isSelected,
71
- isPressed: isPressed,
81
+ isPressed: isPressed || isLabelPressed,
72
82
  isDisabled: isDisabled,
73
83
  isReadOnly: isReadOnly,
74
84
  isInvalid: isInvalid || validationState === "invalid"
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;AA6BM,SAAS,0CAAU,KAAsB,EAAE,KAAkB,EAAE,GAAgC;IACpG,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,wFAAwF;IACxF,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,qCAAO,EAAE;oBACrC;IACF;IAEA,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,kCAAW,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,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;mBAC5B;oBACA;oBACA;QACA,WAAW,aAAa,oBAAoB;IAC9C;AACF;;CDrFC","sources":["packages/@react-aria/toggle/src/index.ts","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\nexport {useToggle} from './useToggle';\nexport type {AriaToggleProps} from '@react-types/checkbox';\nexport type {ToggleAria} from './useToggle';\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 {AriaToggleProps} from '@react-types/checkbox';\nimport {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';\nimport {InputHTMLAttributes, RefObject} from 'react';\nimport {ToggleState} from '@react-stately/toggle';\nimport {useFocusable} from '@react-aria/focus';\nimport {usePress} from '@react-aria/interactions';\n\nexport interface ToggleAria {\n /**\n * Props to be spread on the input element.\n */\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>): 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 // This handles focusing the input on pointer down, which Safari does not do by default.\n let {pressProps, isPressed} = usePress({\n isDisabled\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 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,\n isDisabled,\n isReadOnly,\n isInvalid: isInvalid || validationState === 'invalid'\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;AA6BM,SAAS,0CAAU,KAAsB,EAAE,KAAkB,EAAE,GAAgC;IACpG,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,wFAAwF;IACxF,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,qCAAO,EAAE;oBACrC;IACF;IAEA,kGAAkG;IAClG,IAAI,EAAC,YAAY,UAAU,EAAE,WAAW,cAAc,EAAC,GAAG,CAAA,GAAA,qCAAO,EAAE;QACjE,YAAY,cAAc;QAC1B;YACE,MAAM,MAAM;QACd;IACF;IAEA,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,kCAAW,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;;CD9FC","sources":["packages/@react-aria/toggle/src/index.ts","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\nexport {useToggle} from './useToggle';\nexport type {AriaToggleProps} from '@react-types/checkbox';\nexport type {ToggleAria} from './useToggle';\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 {AriaToggleProps} from '@react-types/checkbox';\nimport {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';\nimport {InputHTMLAttributes, LabelHTMLAttributes, RefObject} from 'react';\nimport {ToggleState} from '@react-stately/toggle';\nimport {useFocusable} from '@react-aria/focus';\nimport {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>): 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 // This handles focusing the input on pointer down, which Safari does not do by default.\n let {pressProps, isPressed} = usePress({\n isDisabled\n });\n\n // iOS does not toggle checkboxes if you drag off and back onto the label, so handle it ourselves.\n let {pressProps: labelProps, isPressed: isLabelPressed} = usePress({\n isDisabled: isDisabled || isReadOnly,\n onPress() {\n state.toggle();\n }\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":"main.js.map"}
package/dist/module.js CHANGED
@@ -40,6 +40,13 @@ function $d2c8e2b0480f3f34$export$cbe85ee05b554577(props, state, ref) {
40
40
  let { pressProps: pressProps, isPressed: isPressed } = (0, $7CUUz$usePress)({
41
41
  isDisabled: isDisabled
42
42
  });
43
+ // iOS does not toggle checkboxes if you drag off and back onto the label, so handle it ourselves.
44
+ let { pressProps: labelProps, isPressed: isLabelPressed } = (0, $7CUUz$usePress)({
45
+ isDisabled: isDisabled || isReadOnly,
46
+ onPress () {
47
+ state.toggle();
48
+ }
49
+ });
43
50
  let { focusableProps: focusableProps } = (0, $7CUUz$useFocusable)(props, ref);
44
51
  let interactions = (0, $7CUUz$mergeProps)(pressProps, focusableProps);
45
52
  let domProps = (0, $7CUUz$filterDOMProps)(props, {
@@ -47,6 +54,9 @@ function $d2c8e2b0480f3f34$export$cbe85ee05b554577(props, state, ref) {
47
54
  });
48
55
  (0, $7CUUz$useFormReset)(ref, state.isSelected, state.setSelected);
49
56
  return {
57
+ labelProps: (0, $7CUUz$mergeProps)(labelProps, {
58
+ onClick: (e)=>e.preventDefault()
59
+ }),
50
60
  inputProps: (0, $7CUUz$mergeProps)(domProps, {
51
61
  "aria-invalid": isInvalid || validationState === "invalid" || undefined,
52
62
  "aria-errormessage": props["aria-errormessage"],
@@ -62,7 +72,7 @@ function $d2c8e2b0480f3f34$export$cbe85ee05b554577(props, state, ref) {
62
72
  ...interactions
63
73
  }),
64
74
  isSelected: state.isSelected,
65
- isPressed: isPressed,
75
+ isPressed: isPressed || isLabelPressed,
66
76
  isDisabled: isDisabled,
67
77
  isReadOnly: isReadOnly,
68
78
  isInvalid: isInvalid || validationState === "invalid"
@@ -1 +1 @@
1
- {"mappings":";;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;AA6BM,SAAS,0CAAU,KAAsB,EAAE,KAAkB,EAAE,GAAgC;IACpG,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,wFAAwF;IACxF,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;oBACrC;IACF;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,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;mBAC5B;oBACA;oBACA;QACA,WAAW,aAAa,oBAAoB;IAC9C;AACF;;CDrFC","sources":["packages/@react-aria/toggle/src/index.ts","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\nexport {useToggle} from './useToggle';\nexport type {AriaToggleProps} from '@react-types/checkbox';\nexport type {ToggleAria} from './useToggle';\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 {AriaToggleProps} from '@react-types/checkbox';\nimport {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';\nimport {InputHTMLAttributes, RefObject} from 'react';\nimport {ToggleState} from '@react-stately/toggle';\nimport {useFocusable} from '@react-aria/focus';\nimport {usePress} from '@react-aria/interactions';\n\nexport interface ToggleAria {\n /**\n * Props to be spread on the input element.\n */\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>): 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 // This handles focusing the input on pointer down, which Safari does not do by default.\n let {pressProps, isPressed} = usePress({\n isDisabled\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 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,\n isDisabled,\n isReadOnly,\n isInvalid: isInvalid || validationState === 'invalid'\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;AA6BM,SAAS,0CAAU,KAAsB,EAAE,KAAkB,EAAE,GAAgC;IACpG,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,wFAAwF;IACxF,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;oBACrC;IACF;IAEA,kGAAkG;IAClG,IAAI,EAAC,YAAY,UAAU,EAAE,WAAW,cAAc,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;QACjE,YAAY,cAAc;QAC1B;YACE,MAAM,MAAM;QACd;IACF;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;;CD9FC","sources":["packages/@react-aria/toggle/src/index.ts","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\nexport {useToggle} from './useToggle';\nexport type {AriaToggleProps} from '@react-types/checkbox';\nexport type {ToggleAria} from './useToggle';\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 {AriaToggleProps} from '@react-types/checkbox';\nimport {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';\nimport {InputHTMLAttributes, LabelHTMLAttributes, RefObject} from 'react';\nimport {ToggleState} from '@react-stately/toggle';\nimport {useFocusable} from '@react-aria/focus';\nimport {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>): 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 // This handles focusing the input on pointer down, which Safari does not do by default.\n let {pressProps, isPressed} = usePress({\n isDisabled\n });\n\n // iOS does not toggle checkboxes if you drag off and back onto the label, so handle it ourselves.\n let {pressProps: labelProps, isPressed: isLabelPressed} = usePress({\n isDisabled: isDisabled || isReadOnly,\n onPress() {\n state.toggle();\n }\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":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { AriaToggleProps } 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
  export interface ToggleAria {
5
- /**
6
- * Props to be spread on the input element.
7
- */
5
+ /** Props to be spread on the label element. */
6
+ labelProps: LabelHTMLAttributes<HTMLLabelElement>;
7
+ /** Props to be spread on the input element. */
8
8
  inputProps: InputHTMLAttributes<HTMLInputElement>;
9
9
  /** Whether the toggle is selected. */
10
10
  isSelected: boolean;
@@ -1 +1 @@
1
- {"mappings":";;;AAmBA;IACE;;OAEG;IACH,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,CAAC,GAAG,UAAU,CAwDlH;AClFD,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"}
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,CAAC,GAAG,UAAU,CAiElH;AC3FD,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/toggle",
3
- "version": "3.9.0",
3
+ "version": "3.10.1",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,11 +22,11 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-aria/focus": "^3.15.0",
26
- "@react-aria/interactions": "^3.20.0",
27
- "@react-aria/utils": "^3.22.0",
28
- "@react-stately/toggle": "^3.7.0",
29
- "@react-types/checkbox": "^3.6.0",
25
+ "@react-aria/focus": "^3.16.1",
26
+ "@react-aria/interactions": "^3.21.0",
27
+ "@react-aria/utils": "^3.23.1",
28
+ "@react-stately/toggle": "^3.7.1",
29
+ "@react-types/checkbox": "^3.7.0",
30
30
  "@swc/helpers": "^0.5.0"
31
31
  },
32
32
  "peerDependencies": {
@@ -35,5 +35,5 @@
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "gitHead": "9ce2f674eab2cc8912800d3162dcf00a1ce94274"
38
+ "gitHead": "f040ff62678e6a31375b96c05396df0bae660350"
39
39
  }
package/src/useToggle.ts CHANGED
@@ -12,15 +12,15 @@
12
12
 
13
13
  import {AriaToggleProps} from '@react-types/checkbox';
14
14
  import {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';
15
- import {InputHTMLAttributes, RefObject} from 'react';
15
+ import {InputHTMLAttributes, LabelHTMLAttributes, RefObject} from 'react';
16
16
  import {ToggleState} from '@react-stately/toggle';
17
17
  import {useFocusable} from '@react-aria/focus';
18
18
  import {usePress} from '@react-aria/interactions';
19
19
 
20
20
  export interface ToggleAria {
21
- /**
22
- * Props to be spread on the input element.
23
- */
21
+ /** Props to be spread on the label element. */
22
+ labelProps: LabelHTMLAttributes<HTMLLabelElement>,
23
+ /** Props to be spread on the input element. */
24
24
  inputProps: InputHTMLAttributes<HTMLInputElement>,
25
25
  /** Whether the toggle is selected. */
26
26
  isSelected: boolean,
@@ -68,6 +68,14 @@ export function useToggle(props: AriaToggleProps, state: ToggleState, ref: RefOb
68
68
  isDisabled
69
69
  });
70
70
 
71
+ // iOS does not toggle checkboxes if you drag off and back onto the label, so handle it ourselves.
72
+ let {pressProps: labelProps, isPressed: isLabelPressed} = usePress({
73
+ isDisabled: isDisabled || isReadOnly,
74
+ onPress() {
75
+ state.toggle();
76
+ }
77
+ });
78
+
71
79
  let {focusableProps} = useFocusable(props, ref);
72
80
  let interactions = mergeProps(pressProps, focusableProps);
73
81
  let domProps = filterDOMProps(props, {labelable: true});
@@ -75,6 +83,7 @@ export function useToggle(props: AriaToggleProps, state: ToggleState, ref: RefOb
75
83
  useFormReset(ref, state.isSelected, state.setSelected);
76
84
 
77
85
  return {
86
+ labelProps: mergeProps(labelProps, {onClick: e => e.preventDefault()}),
78
87
  inputProps: mergeProps(domProps, {
79
88
  'aria-invalid': isInvalid || validationState === 'invalid' || undefined,
80
89
  'aria-errormessage': props['aria-errormessage'],
@@ -88,7 +97,7 @@ export function useToggle(props: AriaToggleProps, state: ToggleState, ref: RefOb
88
97
  ...interactions
89
98
  }),
90
99
  isSelected: state.isSelected,
91
- isPressed,
100
+ isPressed: isPressed || isLabelPressed,
92
101
  isDisabled,
93
102
  isReadOnly,
94
103
  isInvalid: isInvalid || validationState === 'invalid'