@react-aria/interactions 3.21.2 → 3.22.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.
Files changed (58) hide show
  1. package/dist/PressResponder.mjs +1 -1
  2. package/dist/Pressable.mjs +1 -1
  3. package/dist/context.main.js +1 -1
  4. package/dist/context.mjs +2 -2
  5. package/dist/context.module.js +1 -1
  6. package/dist/createEventHandler.main.js +1 -1
  7. package/dist/createEventHandler.mjs +2 -2
  8. package/dist/createEventHandler.module.js +1 -1
  9. package/dist/textSelection.main.js +14 -14
  10. package/dist/textSelection.mjs +15 -15
  11. package/dist/textSelection.module.js +14 -14
  12. package/dist/types.d.ts +5 -5
  13. package/dist/types.d.ts.map +1 -1
  14. package/dist/useFocus.mjs +1 -1
  15. package/dist/useFocusVisible.main.js +54 -54
  16. package/dist/useFocusVisible.mjs +55 -55
  17. package/dist/useFocusVisible.module.js +54 -54
  18. package/dist/useFocusWithin.mjs +1 -1
  19. package/dist/useHover.main.js +16 -16
  20. package/dist/useHover.main.js.map +1 -1
  21. package/dist/useHover.mjs +17 -17
  22. package/dist/useHover.module.js +16 -16
  23. package/dist/useHover.module.js.map +1 -1
  24. package/dist/useInteractOutside.main.js +14 -14
  25. package/dist/useInteractOutside.main.js.map +1 -1
  26. package/dist/useInteractOutside.mjs +15 -15
  27. package/dist/useInteractOutside.module.js +14 -14
  28. package/dist/useInteractOutside.module.js.map +1 -1
  29. package/dist/useKeyboard.mjs +1 -1
  30. package/dist/useLongPress.main.js +11 -11
  31. package/dist/useLongPress.main.js.map +1 -1
  32. package/dist/useLongPress.mjs +12 -12
  33. package/dist/useLongPress.module.js +11 -11
  34. package/dist/useLongPress.module.js.map +1 -1
  35. package/dist/useMove.main.js +36 -36
  36. package/dist/useMove.mjs +37 -37
  37. package/dist/useMove.module.js +36 -36
  38. package/dist/usePress.main.js +95 -54
  39. package/dist/usePress.main.js.map +1 -1
  40. package/dist/usePress.mjs +96 -55
  41. package/dist/usePress.module.js +95 -54
  42. package/dist/usePress.module.js.map +1 -1
  43. package/dist/useScrollWheel.main.js +1 -1
  44. package/dist/useScrollWheel.main.js.map +1 -1
  45. package/dist/useScrollWheel.mjs +2 -2
  46. package/dist/useScrollWheel.module.js +1 -1
  47. package/dist/useScrollWheel.module.js.map +1 -1
  48. package/dist/utils.main.js +5 -5
  49. package/dist/utils.mjs +6 -6
  50. package/dist/utils.module.js +5 -5
  51. package/package.json +6 -6
  52. package/src/DOMPropsContext.ts +3 -3
  53. package/src/useDOMPropsResponder.ts +2 -2
  54. package/src/useHover.ts +0 -1
  55. package/src/useInteractOutside.ts +3 -2
  56. package/src/useLongPress.ts +1 -1
  57. package/src/usePress.ts +60 -14
  58. package/src/useScrollWheel.ts +3 -3
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAYM,SAAS,yCAAe,KAAuB,EAAE,GAA2B;IACjF,IAAI,YAAC,QAAQ,cAAE,UAAU,EAAC,GAAG;IAC7B,IAAI,kBAAkB,CAAA,GAAA,wBAAU,EAAE,CAAC;QACjC,+DAA+D;QAC/D,IAAI,EAAE,OAAO,EACX;QAGF,0BAA0B;QAC1B,EAAE,cAAc;QAChB,EAAE,eAAe;QAEjB,IAAI,UACF,SAAS;YAAC,QAAQ,EAAE,MAAM;YAAE,QAAQ,EAAE,MAAM;QAAA;IAEhD,GAAG;QAAC;KAAS;IAEb,CAAA,GAAA,8BAAO,EAAE,KAAK,SAAS,aAAa,YAAY;AAClD","sources":["packages/@react-aria/interactions/src/useScrollWheel.ts"],"sourcesContent":["/*\n * Copyright 2021 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 {RefObject, useCallback} from 'react';\nimport {ScrollEvents} from '@react-types/shared';\nimport {useEvent} from '@react-aria/utils';\n\nexport interface ScrollWheelProps extends ScrollEvents {\n /** Whether the scroll listener should be disabled. */\n isDisabled?: boolean\n}\n\n// scroll wheel needs to be added not passively so it's cancelable, small helper hook to remember that\nexport function useScrollWheel(props: ScrollWheelProps, ref: RefObject<HTMLElement>): void {\n let {onScroll, isDisabled} = props;\n let onScrollHandler = useCallback((e) => {\n // If the ctrlKey is pressed, this is a zoom event, do nothing.\n if (e.ctrlKey) {\n return;\n }\n\n // stop scrolling the page\n e.preventDefault();\n e.stopPropagation();\n\n if (onScroll) {\n onScroll({deltaX: e.deltaX, deltaY: e.deltaY});\n }\n }, [onScroll]);\n\n useEvent(ref, 'wheel', isDisabled ? undefined : onScrollHandler);\n}\n"],"names":[],"version":3,"file":"useScrollWheel.main.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAYM,SAAS,yCAAe,KAAuB,EAAE,GAAkC;IACxF,IAAI,YAAC,QAAQ,cAAE,UAAU,EAAC,GAAG;IAC7B,IAAI,kBAAkB,CAAA,GAAA,wBAAU,EAAE,CAAC;QACjC,+DAA+D;QAC/D,IAAI,EAAE,OAAO,EACX;QAGF,0BAA0B;QAC1B,EAAE,cAAc;QAChB,EAAE,eAAe;QAEjB,IAAI,UACF,SAAS;YAAC,QAAQ,EAAE,MAAM;YAAE,QAAQ,EAAE,MAAM;QAAA;IAEhD,GAAG;QAAC;KAAS;IAEb,CAAA,GAAA,8BAAO,EAAE,KAAK,SAAS,aAAa,YAAY;AAClD","sources":["packages/@react-aria/interactions/src/useScrollWheel.ts"],"sourcesContent":["/*\n * Copyright 2021 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 {RefObject, ScrollEvents} from '@react-types/shared';\nimport {useCallback} from 'react';\nimport {useEvent} from '@react-aria/utils';\n\nexport interface ScrollWheelProps extends ScrollEvents {\n /** Whether the scroll listener should be disabled. */\n isDisabled?: boolean\n}\n\n// scroll wheel needs to be added not passively so it's cancelable, small helper hook to remember that\nexport function useScrollWheel(props: ScrollWheelProps, ref: RefObject<HTMLElement | null>): void {\n let {onScroll, isDisabled} = props;\n let onScrollHandler = useCallback((e) => {\n // If the ctrlKey is pressed, this is a zoom event, do nothing.\n if (e.ctrlKey) {\n return;\n }\n\n // stop scrolling the page\n e.preventDefault();\n e.stopPropagation();\n\n if (onScroll) {\n onScroll({deltaX: e.deltaX, deltaY: e.deltaY});\n }\n }, [onScroll]);\n\n useEvent(ref, 'wheel', isDisabled ? undefined : onScrollHandler);\n}\n"],"names":[],"version":3,"file":"useScrollWheel.main.js.map"}
@@ -28,9 +28,9 @@ function $7d0a636d7a4dcefd$export$2123ff2b87c81ca(props, ref) {
28
28
  }, [
29
29
  onScroll
30
30
  ]);
31
- (0, $nrdL2$useEvent)(ref, "wheel", isDisabled ? undefined : onScrollHandler);
31
+ (0, $nrdL2$useEvent)(ref, 'wheel', isDisabled ? undefined : onScrollHandler);
32
32
  }
33
33
 
34
34
 
35
35
  export {$7d0a636d7a4dcefd$export$2123ff2b87c81ca as useScrollWheel};
36
- //# sourceMappingURL=useScrollWheel.mjs.map
36
+ //# sourceMappingURL=useScrollWheel.module.js.map
@@ -28,7 +28,7 @@ function $7d0a636d7a4dcefd$export$2123ff2b87c81ca(props, ref) {
28
28
  }, [
29
29
  onScroll
30
30
  ]);
31
- (0, $nrdL2$useEvent)(ref, "wheel", isDisabled ? undefined : onScrollHandler);
31
+ (0, $nrdL2$useEvent)(ref, 'wheel', isDisabled ? undefined : onScrollHandler);
32
32
  }
33
33
 
34
34
 
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAYM,SAAS,yCAAe,KAAuB,EAAE,GAA2B;IACjF,IAAI,YAAC,QAAQ,cAAE,UAAU,EAAC,GAAG;IAC7B,IAAI,kBAAkB,CAAA,GAAA,kBAAU,EAAE,CAAC;QACjC,+DAA+D;QAC/D,IAAI,EAAE,OAAO,EACX;QAGF,0BAA0B;QAC1B,EAAE,cAAc;QAChB,EAAE,eAAe;QAEjB,IAAI,UACF,SAAS;YAAC,QAAQ,EAAE,MAAM;YAAE,QAAQ,EAAE,MAAM;QAAA;IAEhD,GAAG;QAAC;KAAS;IAEb,CAAA,GAAA,eAAO,EAAE,KAAK,SAAS,aAAa,YAAY;AAClD","sources":["packages/@react-aria/interactions/src/useScrollWheel.ts"],"sourcesContent":["/*\n * Copyright 2021 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 {RefObject, useCallback} from 'react';\nimport {ScrollEvents} from '@react-types/shared';\nimport {useEvent} from '@react-aria/utils';\n\nexport interface ScrollWheelProps extends ScrollEvents {\n /** Whether the scroll listener should be disabled. */\n isDisabled?: boolean\n}\n\n// scroll wheel needs to be added not passively so it's cancelable, small helper hook to remember that\nexport function useScrollWheel(props: ScrollWheelProps, ref: RefObject<HTMLElement>): void {\n let {onScroll, isDisabled} = props;\n let onScrollHandler = useCallback((e) => {\n // If the ctrlKey is pressed, this is a zoom event, do nothing.\n if (e.ctrlKey) {\n return;\n }\n\n // stop scrolling the page\n e.preventDefault();\n e.stopPropagation();\n\n if (onScroll) {\n onScroll({deltaX: e.deltaX, deltaY: e.deltaY});\n }\n }, [onScroll]);\n\n useEvent(ref, 'wheel', isDisabled ? undefined : onScrollHandler);\n}\n"],"names":[],"version":3,"file":"useScrollWheel.module.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAYM,SAAS,yCAAe,KAAuB,EAAE,GAAkC;IACxF,IAAI,YAAC,QAAQ,cAAE,UAAU,EAAC,GAAG;IAC7B,IAAI,kBAAkB,CAAA,GAAA,kBAAU,EAAE,CAAC;QACjC,+DAA+D;QAC/D,IAAI,EAAE,OAAO,EACX;QAGF,0BAA0B;QAC1B,EAAE,cAAc;QAChB,EAAE,eAAe;QAEjB,IAAI,UACF,SAAS;YAAC,QAAQ,EAAE,MAAM;YAAE,QAAQ,EAAE,MAAM;QAAA;IAEhD,GAAG;QAAC;KAAS;IAEb,CAAA,GAAA,eAAO,EAAE,KAAK,SAAS,aAAa,YAAY;AAClD","sources":["packages/@react-aria/interactions/src/useScrollWheel.ts"],"sourcesContent":["/*\n * Copyright 2021 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 {RefObject, ScrollEvents} from '@react-types/shared';\nimport {useCallback} from 'react';\nimport {useEvent} from '@react-aria/utils';\n\nexport interface ScrollWheelProps extends ScrollEvents {\n /** Whether the scroll listener should be disabled. */\n isDisabled?: boolean\n}\n\n// scroll wheel needs to be added not passively so it's cancelable, small helper hook to remember that\nexport function useScrollWheel(props: ScrollWheelProps, ref: RefObject<HTMLElement | null>): void {\n let {onScroll, isDisabled} = props;\n let onScrollHandler = useCallback((e) => {\n // If the ctrlKey is pressed, this is a zoom event, do nothing.\n if (e.ctrlKey) {\n return;\n }\n\n // stop scrolling the page\n e.preventDefault();\n e.stopPropagation();\n\n if (onScroll) {\n onScroll({deltaX: e.deltaX, deltaY: e.deltaY});\n }\n }, [onScroll]);\n\n useEvent(ref, 'wheel', isDisabled ? undefined : onScrollHandler);\n}\n"],"names":[],"version":3,"file":"useScrollWheel.module.js.map"}
@@ -80,14 +80,14 @@ function $625cf83917e112ad$export$715c682d09d639cc(onBlur) {
80
80
  let onBlurHandler = (e)=>{
81
81
  stateRef.current.isFocused = false;
82
82
  if (target.disabled) // For backward compatibility, dispatch a (fake) React synthetic event.
83
- dispatchBlur(new $625cf83917e112ad$export$905e7fc544a71f36("blur", e));
83
+ dispatchBlur(new $625cf83917e112ad$export$905e7fc544a71f36('blur', e));
84
84
  // We no longer need the MutationObserver once the target is blurred.
85
85
  if (stateRef.current.observer) {
86
86
  stateRef.current.observer.disconnect();
87
87
  stateRef.current.observer = null;
88
88
  }
89
89
  };
90
- target.addEventListener("focusout", onBlurHandler, {
90
+ target.addEventListener('focusout', onBlurHandler, {
91
91
  once: true
92
92
  });
93
93
  stateRef.current.observer = new MutationObserver(()=>{
@@ -95,10 +95,10 @@ function $625cf83917e112ad$export$715c682d09d639cc(onBlur) {
95
95
  var _stateRef_current_observer;
96
96
  (_stateRef_current_observer = stateRef.current.observer) === null || _stateRef_current_observer === void 0 ? void 0 : _stateRef_current_observer.disconnect();
97
97
  let relatedTargetEl = target === document.activeElement ? null : document.activeElement;
98
- target.dispatchEvent(new FocusEvent("blur", {
98
+ target.dispatchEvent(new FocusEvent('blur', {
99
99
  relatedTarget: relatedTargetEl
100
100
  }));
101
- target.dispatchEvent(new FocusEvent("focusout", {
101
+ target.dispatchEvent(new FocusEvent('focusout', {
102
102
  bubbles: true,
103
103
  relatedTarget: relatedTargetEl
104
104
  }));
@@ -107,7 +107,7 @@ function $625cf83917e112ad$export$715c682d09d639cc(onBlur) {
107
107
  stateRef.current.observer.observe(target, {
108
108
  attributes: true,
109
109
  attributeFilter: [
110
- "disabled"
110
+ 'disabled'
111
111
  ]
112
112
  });
113
113
  }
package/dist/utils.mjs CHANGED
@@ -74,14 +74,14 @@ function $8a9cb279dc87e130$export$715c682d09d639cc(onBlur) {
74
74
  let onBlurHandler = (e)=>{
75
75
  stateRef.current.isFocused = false;
76
76
  if (target.disabled) // For backward compatibility, dispatch a (fake) React synthetic event.
77
- dispatchBlur(new $8a9cb279dc87e130$export$905e7fc544a71f36("blur", e));
77
+ dispatchBlur(new $8a9cb279dc87e130$export$905e7fc544a71f36('blur', e));
78
78
  // We no longer need the MutationObserver once the target is blurred.
79
79
  if (stateRef.current.observer) {
80
80
  stateRef.current.observer.disconnect();
81
81
  stateRef.current.observer = null;
82
82
  }
83
83
  };
84
- target.addEventListener("focusout", onBlurHandler, {
84
+ target.addEventListener('focusout', onBlurHandler, {
85
85
  once: true
86
86
  });
87
87
  stateRef.current.observer = new MutationObserver(()=>{
@@ -89,10 +89,10 @@ function $8a9cb279dc87e130$export$715c682d09d639cc(onBlur) {
89
89
  var _stateRef_current_observer;
90
90
  (_stateRef_current_observer = stateRef.current.observer) === null || _stateRef_current_observer === void 0 ? void 0 : _stateRef_current_observer.disconnect();
91
91
  let relatedTargetEl = target === document.activeElement ? null : document.activeElement;
92
- target.dispatchEvent(new FocusEvent("blur", {
92
+ target.dispatchEvent(new FocusEvent('blur', {
93
93
  relatedTarget: relatedTargetEl
94
94
  }));
95
- target.dispatchEvent(new FocusEvent("focusout", {
95
+ target.dispatchEvent(new FocusEvent('focusout', {
96
96
  bubbles: true,
97
97
  relatedTarget: relatedTargetEl
98
98
  }));
@@ -101,7 +101,7 @@ function $8a9cb279dc87e130$export$715c682d09d639cc(onBlur) {
101
101
  stateRef.current.observer.observe(target, {
102
102
  attributes: true,
103
103
  attributeFilter: [
104
- "disabled"
104
+ 'disabled'
105
105
  ]
106
106
  });
107
107
  }
@@ -112,4 +112,4 @@ function $8a9cb279dc87e130$export$715c682d09d639cc(onBlur) {
112
112
 
113
113
 
114
114
  export {$8a9cb279dc87e130$export$905e7fc544a71f36 as SyntheticFocusEvent, $8a9cb279dc87e130$export$715c682d09d639cc as useSyntheticBlurEvent};
115
- //# sourceMappingURL=utils.mjs.map
115
+ //# sourceMappingURL=utils.module.js.map
@@ -74,14 +74,14 @@ function $8a9cb279dc87e130$export$715c682d09d639cc(onBlur) {
74
74
  let onBlurHandler = (e)=>{
75
75
  stateRef.current.isFocused = false;
76
76
  if (target.disabled) // For backward compatibility, dispatch a (fake) React synthetic event.
77
- dispatchBlur(new $8a9cb279dc87e130$export$905e7fc544a71f36("blur", e));
77
+ dispatchBlur(new $8a9cb279dc87e130$export$905e7fc544a71f36('blur', e));
78
78
  // We no longer need the MutationObserver once the target is blurred.
79
79
  if (stateRef.current.observer) {
80
80
  stateRef.current.observer.disconnect();
81
81
  stateRef.current.observer = null;
82
82
  }
83
83
  };
84
- target.addEventListener("focusout", onBlurHandler, {
84
+ target.addEventListener('focusout', onBlurHandler, {
85
85
  once: true
86
86
  });
87
87
  stateRef.current.observer = new MutationObserver(()=>{
@@ -89,10 +89,10 @@ function $8a9cb279dc87e130$export$715c682d09d639cc(onBlur) {
89
89
  var _stateRef_current_observer;
90
90
  (_stateRef_current_observer = stateRef.current.observer) === null || _stateRef_current_observer === void 0 ? void 0 : _stateRef_current_observer.disconnect();
91
91
  let relatedTargetEl = target === document.activeElement ? null : document.activeElement;
92
- target.dispatchEvent(new FocusEvent("blur", {
92
+ target.dispatchEvent(new FocusEvent('blur', {
93
93
  relatedTarget: relatedTargetEl
94
94
  }));
95
- target.dispatchEvent(new FocusEvent("focusout", {
95
+ target.dispatchEvent(new FocusEvent('focusout', {
96
96
  bubbles: true,
97
97
  relatedTarget: relatedTargetEl
98
98
  }));
@@ -101,7 +101,7 @@ function $8a9cb279dc87e130$export$715c682d09d639cc(onBlur) {
101
101
  stateRef.current.observer.observe(target, {
102
102
  attributes: true,
103
103
  attributeFilter: [
104
- "disabled"
104
+ 'disabled'
105
105
  ]
106
106
  });
107
107
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/interactions",
3
- "version": "3.21.2",
3
+ "version": "3.22.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,16 +22,16 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-aria/ssr": "^3.9.3",
26
- "@react-aria/utils": "^3.24.0",
27
- "@react-types/shared": "^3.23.0",
25
+ "@react-aria/ssr": "^3.9.5",
26
+ "@react-aria/utils": "^3.25.0",
27
+ "@react-types/shared": "^3.24.0",
28
28
  "@swc/helpers": "^0.5.0"
29
29
  },
30
30
  "peerDependencies": {
31
- "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
31
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"
35
35
  },
36
- "gitHead": "f645f29edc1322153fd60af4640cbcab1d992dbd"
36
+ "gitHead": "86d80e3216bc32e75108831cf3a5a720bc849206"
37
37
  }
@@ -10,12 +10,12 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import {DOMAttributes} from '@react-types/shared';
13
+ import {DOMAttributes, RefObject} from '@react-types/shared';
14
14
  import {mergeProps, useSyncRef} from '@react-aria/utils';
15
- import React, {MutableRefObject, RefObject, useContext} from 'react';
15
+ import React, {MutableRefObject, useContext} from 'react';
16
16
 
17
17
  interface DOMPropsResponderProps extends DOMAttributes {
18
- ref?: RefObject<Element>
18
+ ref?: RefObject<Element | null>
19
19
  }
20
20
 
21
21
  interface IDOMPropsResponderContext extends DOMAttributes {
@@ -10,10 +10,10 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import {RefObject} from 'react';
13
+ import {RefObject} from '@react-types/shared';
14
14
  import {useDOMPropsResponderContext} from './DOMPropsContext';
15
15
 
16
- export function useDOMPropsResponder(domRef: RefObject<Element>) {
16
+ export function useDOMPropsResponder(domRef: RefObject<Element | null>) {
17
17
 
18
18
  let domProps = useDOMPropsResponderContext({ref: domRef}) || {};
19
19
 
package/src/useHover.ts CHANGED
@@ -204,4 +204,3 @@ export function useHover(props: HoverProps): HoverResult {
204
204
  isHovered
205
205
  };
206
206
  }
207
-
@@ -16,10 +16,11 @@
16
16
  // See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
17
17
 
18
18
  import {getOwnerDocument, useEffectEvent} from '@react-aria/utils';
19
- import {RefObject, useEffect, useRef} from 'react';
19
+ import {RefObject} from '@react-types/shared';
20
+ import {useEffect, useRef} from 'react';
20
21
 
21
22
  export interface InteractOutsideProps {
22
- ref: RefObject<Element>,
23
+ ref: RefObject<Element | null>,
23
24
  onInteractOutside?: (e: PointerEvent) => void,
24
25
  onInteractOutsideStart?: (e: PointerEvent) => void,
25
26
  /** Whether the interact outside events should be disabled. */
@@ -63,7 +63,7 @@ export function useLongPress(props: LongPressProps): LongPressResult {
63
63
  accessibilityDescription
64
64
  } = props;
65
65
 
66
- const timeRef = useRef<ReturnType<typeof setTimeout> | undefined>();
66
+ const timeRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
67
67
  let {addGlobalListener, removeGlobalListener} = useGlobalListeners();
68
68
 
69
69
  let {pressProps} = usePress({
package/src/usePress.ts CHANGED
@@ -17,9 +17,9 @@
17
17
 
18
18
  import {chain, focusWithoutScrolling, getOwnerDocument, getOwnerWindow, isMac, isVirtualClick, isVirtualPointerEvent, mergeProps, openLink, useEffectEvent, useGlobalListeners, useSyncRef} from '@react-aria/utils';
19
19
  import {disableTextSelection, restoreTextSelection} from './textSelection';
20
- import {DOMAttributes, FocusableElement, PressEvent as IPressEvent, PointerType, PressEvents} from '@react-types/shared';
20
+ import {DOMAttributes, FocusableElement, PressEvent as IPressEvent, PointerType, PressEvents, RefObject} from '@react-types/shared';
21
21
  import {PressResponderContext} from './context';
22
- import {RefObject, useContext, useEffect, useMemo, useRef, useState} from 'react';
22
+ import {TouchEvent as RTouchEvent, useContext, useEffect, useMemo, useRef, useState} from 'react';
23
23
 
24
24
  export interface PressProps extends PressEvents {
25
25
  /** Whether the target is in a controlled press state (e.g. an overlay it triggers is open). */
@@ -41,7 +41,7 @@ export interface PressProps extends PressEvents {
41
41
 
42
42
  export interface PressHookProps extends PressProps {
43
43
  /** A ref to the target element. */
44
- ref?: RefObject<Element>
44
+ ref?: RefObject<Element | null>
45
45
  }
46
46
 
47
47
  interface PressState {
@@ -63,7 +63,10 @@ interface EventBase {
63
63
  shiftKey: boolean,
64
64
  ctrlKey: boolean,
65
65
  metaKey: boolean,
66
- altKey: boolean
66
+ altKey: boolean,
67
+ clientX?: number,
68
+ clientY?: number,
69
+ targetTouches?: Array<{clientX?: number, clientY?: number}>
67
70
  }
68
71
 
69
72
  export interface PressResult {
@@ -94,9 +97,28 @@ class PressEvent implements IPressEvent {
94
97
  ctrlKey: boolean;
95
98
  metaKey: boolean;
96
99
  altKey: boolean;
100
+ x: number;
101
+ y: number;
97
102
  #shouldStopPropagation = true;
98
103
 
99
- constructor(type: IPressEvent['type'], pointerType: PointerType, originalEvent: EventBase) {
104
+ constructor(type: IPressEvent['type'], pointerType: PointerType, originalEvent: EventBase, state?: PressState) {
105
+ let currentTarget = state?.target ?? originalEvent.currentTarget;
106
+ const rect: DOMRect | undefined = (currentTarget as Element)?.getBoundingClientRect();
107
+ let x, y = 0;
108
+ let clientX, clientY: number | null = null;
109
+ if (originalEvent.clientX != null && originalEvent.clientY != null) {
110
+ clientX = originalEvent.clientX;
111
+ clientY = originalEvent.clientY;
112
+ }
113
+ if (rect) {
114
+ if (clientX != null && clientY != null) {
115
+ x = clientX - rect.left;
116
+ y = clientY - rect.top;
117
+ } else {
118
+ x = rect.width / 2;
119
+ y = rect.height / 2;
120
+ }
121
+ }
100
122
  this.type = type;
101
123
  this.pointerType = pointerType;
102
124
  this.target = originalEvent.currentTarget as Element;
@@ -104,6 +126,8 @@ class PressEvent implements IPressEvent {
104
126
  this.metaKey = originalEvent.metaKey;
105
127
  this.ctrlKey = originalEvent.ctrlKey;
106
128
  this.altKey = originalEvent.altKey;
129
+ this.x = x;
130
+ this.y = y;
107
131
  }
108
132
 
109
133
  continuePropagation() {
@@ -628,7 +652,7 @@ export function usePress(props: PressHookProps): PressResult {
628
652
  disableTextSelection(state.target);
629
653
  }
630
654
 
631
- let shouldStopPropagation = triggerPressStart(e, state.pointerType);
655
+ let shouldStopPropagation = triggerPressStart(createTouchEvent(state.target, e), state.pointerType);
632
656
  if (shouldStopPropagation) {
633
657
  e.stopPropagation();
634
658
  }
@@ -651,12 +675,12 @@ export function usePress(props: PressHookProps): PressResult {
651
675
  if (touch && isOverTarget(touch, e.currentTarget)) {
652
676
  if (!state.isOverTarget && state.pointerType != null) {
653
677
  state.isOverTarget = true;
654
- shouldStopPropagation = triggerPressStart(e, state.pointerType);
678
+ shouldStopPropagation = triggerPressStart(createTouchEvent(state.target!, e), state.pointerType);
655
679
  }
656
680
  } else if (state.isOverTarget && state.pointerType != null) {
657
681
  state.isOverTarget = false;
658
- shouldStopPropagation = triggerPressEnd(e, state.pointerType, false);
659
- cancelOnPointerExit(e);
682
+ shouldStopPropagation = triggerPressEnd(createTouchEvent(state.target!, e), state.pointerType, false);
683
+ cancelOnPointerExit(createTouchEvent(state.target!, e));
660
684
  }
661
685
 
662
686
  if (shouldStopPropagation) {
@@ -677,10 +701,10 @@ export function usePress(props: PressHookProps): PressResult {
677
701
  let touch = getTouchById(e.nativeEvent, state.activePointerId);
678
702
  let shouldStopPropagation = true;
679
703
  if (touch && isOverTarget(touch, e.currentTarget) && state.pointerType != null) {
680
- triggerPressUp(e, state.pointerType);
681
- shouldStopPropagation = triggerPressEnd(e, state.pointerType);
704
+ triggerPressUp(createTouchEvent(state.target!, e), state.pointerType);
705
+ shouldStopPropagation = triggerPressEnd(createTouchEvent(state.target!, e), state.pointerType);
682
706
  } else if (state.isOverTarget && state.pointerType != null) {
683
- shouldStopPropagation = triggerPressEnd(e, state.pointerType, false);
707
+ shouldStopPropagation = triggerPressEnd(createTouchEvent(state.target!, e), state.pointerType, false);
684
708
  }
685
709
 
686
710
  if (shouldStopPropagation) {
@@ -704,7 +728,7 @@ export function usePress(props: PressHookProps): PressResult {
704
728
 
705
729
  e.stopPropagation();
706
730
  if (state.isPressed) {
707
- cancel(e);
731
+ cancel(createTouchEvent(state.target!, e));
708
732
  }
709
733
  };
710
734
 
@@ -802,13 +826,35 @@ function getTouchById(
802
826
  return null;
803
827
  }
804
828
 
829
+ function createTouchEvent(target: FocusableElement, e: RTouchEvent<FocusableElement>): EventBase {
830
+ let clientX = 0;
831
+ let clientY = 0;
832
+ if (e.targetTouches && e.targetTouches.length === 1) {
833
+ clientX = e.targetTouches[0].clientX;
834
+ clientY = e.targetTouches[0].clientY;
835
+ }
836
+ return {
837
+ currentTarget: target,
838
+ shiftKey: e.shiftKey,
839
+ ctrlKey: e.ctrlKey,
840
+ metaKey: e.metaKey,
841
+ altKey: e.altKey,
842
+ clientX,
843
+ clientY
844
+ };
845
+ }
846
+
805
847
  function createEvent(target: FocusableElement, e: EventBase): EventBase {
848
+ let clientX = e.clientX;
849
+ let clientY = e.clientY;
806
850
  return {
807
851
  currentTarget: target,
808
852
  shiftKey: e.shiftKey,
809
853
  ctrlKey: e.ctrlKey,
810
854
  metaKey: e.metaKey,
811
- altKey: e.altKey
855
+ altKey: e.altKey,
856
+ clientX,
857
+ clientY
812
858
  };
813
859
  }
814
860
 
@@ -10,8 +10,8 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import {RefObject, useCallback} from 'react';
14
- import {ScrollEvents} from '@react-types/shared';
13
+ import {RefObject, ScrollEvents} from '@react-types/shared';
14
+ import {useCallback} from 'react';
15
15
  import {useEvent} from '@react-aria/utils';
16
16
 
17
17
  export interface ScrollWheelProps extends ScrollEvents {
@@ -20,7 +20,7 @@ export interface ScrollWheelProps extends ScrollEvents {
20
20
  }
21
21
 
22
22
  // scroll wheel needs to be added not passively so it's cancelable, small helper hook to remember that
23
- export function useScrollWheel(props: ScrollWheelProps, ref: RefObject<HTMLElement>): void {
23
+ export function useScrollWheel(props: ScrollWheelProps, ref: RefObject<HTMLElement | null>): void {
24
24
  let {onScroll, isDisabled} = props;
25
25
  let onScrollHandler = useCallback((e) => {
26
26
  // If the ctrlKey is pressed, this is a zoom event, do nothing.