@react-aria/overlays 3.31.1 → 3.32.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 (263) hide show
  1. package/dist/import.mjs +12 -12
  2. package/dist/main.js +28 -28
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +12 -12
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +19 -0
  7. package/package.json +15 -21
  8. package/src/index.ts +19 -22
  9. package/dist/DismissButton.main.js +0 -51
  10. package/dist/DismissButton.main.js.map +0 -1
  11. package/dist/DismissButton.mjs +0 -46
  12. package/dist/DismissButton.module.js +0 -46
  13. package/dist/DismissButton.module.js.map +0 -1
  14. package/dist/Overlay.main.js +0 -73
  15. package/dist/Overlay.main.js.map +0 -1
  16. package/dist/Overlay.mjs +0 -63
  17. package/dist/Overlay.module.js +0 -63
  18. package/dist/Overlay.module.js.map +0 -1
  19. package/dist/PortalProvider.main.js +0 -41
  20. package/dist/PortalProvider.main.js.map +0 -1
  21. package/dist/PortalProvider.mjs +0 -31
  22. package/dist/PortalProvider.module.js +0 -31
  23. package/dist/PortalProvider.module.js.map +0 -1
  24. package/dist/ar-AE.main.js +0 -6
  25. package/dist/ar-AE.main.js.map +0 -1
  26. package/dist/ar-AE.mjs +0 -8
  27. package/dist/ar-AE.module.js +0 -8
  28. package/dist/ar-AE.module.js.map +0 -1
  29. package/dist/ariaHideOutside.main.js +0 -152
  30. package/dist/ariaHideOutside.main.js.map +0 -1
  31. package/dist/ariaHideOutside.mjs +0 -146
  32. package/dist/ariaHideOutside.module.js +0 -146
  33. package/dist/ariaHideOutside.module.js.map +0 -1
  34. package/dist/bg-BG.main.js +0 -6
  35. package/dist/bg-BG.main.js.map +0 -1
  36. package/dist/bg-BG.mjs +0 -8
  37. package/dist/bg-BG.module.js +0 -8
  38. package/dist/bg-BG.module.js.map +0 -1
  39. package/dist/calculatePosition.main.js +0 -414
  40. package/dist/calculatePosition.main.js.map +0 -1
  41. package/dist/calculatePosition.mjs +0 -408
  42. package/dist/calculatePosition.module.js +0 -408
  43. package/dist/calculatePosition.module.js.map +0 -1
  44. package/dist/cs-CZ.main.js +0 -6
  45. package/dist/cs-CZ.main.js.map +0 -1
  46. package/dist/cs-CZ.mjs +0 -8
  47. package/dist/cs-CZ.module.js +0 -8
  48. package/dist/cs-CZ.module.js.map +0 -1
  49. package/dist/da-DK.main.js +0 -6
  50. package/dist/da-DK.main.js.map +0 -1
  51. package/dist/da-DK.mjs +0 -8
  52. package/dist/da-DK.module.js +0 -8
  53. package/dist/da-DK.module.js.map +0 -1
  54. package/dist/de-DE.main.js +0 -6
  55. package/dist/de-DE.main.js.map +0 -1
  56. package/dist/de-DE.mjs +0 -8
  57. package/dist/de-DE.module.js +0 -8
  58. package/dist/de-DE.module.js.map +0 -1
  59. package/dist/el-GR.main.js +0 -6
  60. package/dist/el-GR.main.js.map +0 -1
  61. package/dist/el-GR.mjs +0 -8
  62. package/dist/el-GR.module.js +0 -8
  63. package/dist/el-GR.module.js.map +0 -1
  64. package/dist/en-US.main.js +0 -6
  65. package/dist/en-US.main.js.map +0 -1
  66. package/dist/en-US.mjs +0 -8
  67. package/dist/en-US.module.js +0 -8
  68. package/dist/en-US.module.js.map +0 -1
  69. package/dist/es-ES.main.js +0 -6
  70. package/dist/es-ES.main.js.map +0 -1
  71. package/dist/es-ES.mjs +0 -8
  72. package/dist/es-ES.module.js +0 -8
  73. package/dist/es-ES.module.js.map +0 -1
  74. package/dist/et-EE.main.js +0 -6
  75. package/dist/et-EE.main.js.map +0 -1
  76. package/dist/et-EE.mjs +0 -8
  77. package/dist/et-EE.module.js +0 -8
  78. package/dist/et-EE.module.js.map +0 -1
  79. package/dist/fi-FI.main.js +0 -6
  80. package/dist/fi-FI.main.js.map +0 -1
  81. package/dist/fi-FI.mjs +0 -8
  82. package/dist/fi-FI.module.js +0 -8
  83. package/dist/fi-FI.module.js.map +0 -1
  84. package/dist/fr-FR.main.js +0 -6
  85. package/dist/fr-FR.main.js.map +0 -1
  86. package/dist/fr-FR.mjs +0 -8
  87. package/dist/fr-FR.module.js +0 -8
  88. package/dist/fr-FR.module.js.map +0 -1
  89. package/dist/he-IL.main.js +0 -6
  90. package/dist/he-IL.main.js.map +0 -1
  91. package/dist/he-IL.mjs +0 -8
  92. package/dist/he-IL.module.js +0 -8
  93. package/dist/he-IL.module.js.map +0 -1
  94. package/dist/hr-HR.main.js +0 -6
  95. package/dist/hr-HR.main.js.map +0 -1
  96. package/dist/hr-HR.mjs +0 -8
  97. package/dist/hr-HR.module.js +0 -8
  98. package/dist/hr-HR.module.js.map +0 -1
  99. package/dist/hu-HU.main.js +0 -6
  100. package/dist/hu-HU.main.js.map +0 -1
  101. package/dist/hu-HU.mjs +0 -8
  102. package/dist/hu-HU.module.js +0 -8
  103. package/dist/hu-HU.module.js.map +0 -1
  104. package/dist/intlStrings.main.js +0 -108
  105. package/dist/intlStrings.main.js.map +0 -1
  106. package/dist/intlStrings.mjs +0 -110
  107. package/dist/intlStrings.module.js +0 -110
  108. package/dist/intlStrings.module.js.map +0 -1
  109. package/dist/it-IT.main.js +0 -6
  110. package/dist/it-IT.main.js.map +0 -1
  111. package/dist/it-IT.mjs +0 -8
  112. package/dist/it-IT.module.js +0 -8
  113. package/dist/it-IT.module.js.map +0 -1
  114. package/dist/ja-JP.main.js +0 -6
  115. package/dist/ja-JP.main.js.map +0 -1
  116. package/dist/ja-JP.mjs +0 -8
  117. package/dist/ja-JP.module.js +0 -8
  118. package/dist/ja-JP.module.js.map +0 -1
  119. package/dist/ko-KR.main.js +0 -6
  120. package/dist/ko-KR.main.js.map +0 -1
  121. package/dist/ko-KR.mjs +0 -8
  122. package/dist/ko-KR.module.js +0 -8
  123. package/dist/ko-KR.module.js.map +0 -1
  124. package/dist/lt-LT.main.js +0 -6
  125. package/dist/lt-LT.main.js.map +0 -1
  126. package/dist/lt-LT.mjs +0 -8
  127. package/dist/lt-LT.module.js +0 -8
  128. package/dist/lt-LT.module.js.map +0 -1
  129. package/dist/lv-LV.main.js +0 -6
  130. package/dist/lv-LV.main.js.map +0 -1
  131. package/dist/lv-LV.mjs +0 -8
  132. package/dist/lv-LV.module.js +0 -8
  133. package/dist/lv-LV.module.js.map +0 -1
  134. package/dist/nb-NO.main.js +0 -6
  135. package/dist/nb-NO.main.js.map +0 -1
  136. package/dist/nb-NO.mjs +0 -8
  137. package/dist/nb-NO.module.js +0 -8
  138. package/dist/nb-NO.module.js.map +0 -1
  139. package/dist/nl-NL.main.js +0 -6
  140. package/dist/nl-NL.main.js.map +0 -1
  141. package/dist/nl-NL.mjs +0 -8
  142. package/dist/nl-NL.module.js +0 -8
  143. package/dist/nl-NL.module.js.map +0 -1
  144. package/dist/pl-PL.main.js +0 -6
  145. package/dist/pl-PL.main.js.map +0 -1
  146. package/dist/pl-PL.mjs +0 -8
  147. package/dist/pl-PL.module.js +0 -8
  148. package/dist/pl-PL.module.js.map +0 -1
  149. package/dist/pt-BR.main.js +0 -6
  150. package/dist/pt-BR.main.js.map +0 -1
  151. package/dist/pt-BR.mjs +0 -8
  152. package/dist/pt-BR.module.js +0 -8
  153. package/dist/pt-BR.module.js.map +0 -1
  154. package/dist/pt-PT.main.js +0 -6
  155. package/dist/pt-PT.main.js.map +0 -1
  156. package/dist/pt-PT.mjs +0 -8
  157. package/dist/pt-PT.module.js +0 -8
  158. package/dist/pt-PT.module.js.map +0 -1
  159. package/dist/ro-RO.main.js +0 -6
  160. package/dist/ro-RO.main.js.map +0 -1
  161. package/dist/ro-RO.mjs +0 -8
  162. package/dist/ro-RO.module.js +0 -8
  163. package/dist/ro-RO.module.js.map +0 -1
  164. package/dist/ru-RU.main.js +0 -6
  165. package/dist/ru-RU.main.js.map +0 -1
  166. package/dist/ru-RU.mjs +0 -8
  167. package/dist/ru-RU.module.js +0 -8
  168. package/dist/ru-RU.module.js.map +0 -1
  169. package/dist/sk-SK.main.js +0 -6
  170. package/dist/sk-SK.main.js.map +0 -1
  171. package/dist/sk-SK.mjs +0 -8
  172. package/dist/sk-SK.module.js +0 -8
  173. package/dist/sk-SK.module.js.map +0 -1
  174. package/dist/sl-SI.main.js +0 -6
  175. package/dist/sl-SI.main.js.map +0 -1
  176. package/dist/sl-SI.mjs +0 -8
  177. package/dist/sl-SI.module.js +0 -8
  178. package/dist/sl-SI.module.js.map +0 -1
  179. package/dist/sr-SP.main.js +0 -6
  180. package/dist/sr-SP.main.js.map +0 -1
  181. package/dist/sr-SP.mjs +0 -8
  182. package/dist/sr-SP.module.js +0 -8
  183. package/dist/sr-SP.module.js.map +0 -1
  184. package/dist/sv-SE.main.js +0 -6
  185. package/dist/sv-SE.main.js.map +0 -1
  186. package/dist/sv-SE.mjs +0 -8
  187. package/dist/sv-SE.module.js +0 -8
  188. package/dist/sv-SE.module.js.map +0 -1
  189. package/dist/tr-TR.main.js +0 -6
  190. package/dist/tr-TR.main.js.map +0 -1
  191. package/dist/tr-TR.mjs +0 -8
  192. package/dist/tr-TR.module.js +0 -8
  193. package/dist/tr-TR.module.js.map +0 -1
  194. package/dist/types.d.ts +0 -355
  195. package/dist/types.d.ts.map +0 -1
  196. package/dist/uk-UA.main.js +0 -6
  197. package/dist/uk-UA.main.js.map +0 -1
  198. package/dist/uk-UA.mjs +0 -8
  199. package/dist/uk-UA.module.js +0 -8
  200. package/dist/uk-UA.module.js.map +0 -1
  201. package/dist/useCloseOnScroll.main.js +0 -52
  202. package/dist/useCloseOnScroll.main.js.map +0 -1
  203. package/dist/useCloseOnScroll.mjs +0 -46
  204. package/dist/useCloseOnScroll.module.js +0 -46
  205. package/dist/useCloseOnScroll.module.js.map +0 -1
  206. package/dist/useModal.main.js +0 -118
  207. package/dist/useModal.main.js.map +0 -1
  208. package/dist/useModal.mjs +0 -105
  209. package/dist/useModal.module.js +0 -105
  210. package/dist/useModal.module.js.map +0 -1
  211. package/dist/useModalOverlay.main.js +0 -57
  212. package/dist/useModalOverlay.main.js.map +0 -1
  213. package/dist/useModalOverlay.mjs +0 -52
  214. package/dist/useModalOverlay.module.js +0 -52
  215. package/dist/useModalOverlay.module.js.map +0 -1
  216. package/dist/useOverlay.main.js +0 -111
  217. package/dist/useOverlay.main.js.map +0 -1
  218. package/dist/useOverlay.mjs +0 -106
  219. package/dist/useOverlay.module.js +0 -106
  220. package/dist/useOverlay.module.js.map +0 -1
  221. package/dist/useOverlayPosition.main.js +0 -225
  222. package/dist/useOverlayPosition.main.js.map +0 -1
  223. package/dist/useOverlayPosition.mjs +0 -220
  224. package/dist/useOverlayPosition.module.js +0 -220
  225. package/dist/useOverlayPosition.module.js.map +0 -1
  226. package/dist/useOverlayTrigger.main.js +0 -54
  227. package/dist/useOverlayTrigger.main.js.map +0 -1
  228. package/dist/useOverlayTrigger.mjs +0 -49
  229. package/dist/useOverlayTrigger.module.js +0 -49
  230. package/dist/useOverlayTrigger.module.js.map +0 -1
  231. package/dist/usePopover.main.js +0 -77
  232. package/dist/usePopover.main.js.map +0 -1
  233. package/dist/usePopover.mjs +0 -72
  234. package/dist/usePopover.module.js +0 -72
  235. package/dist/usePopover.module.js.map +0 -1
  236. package/dist/usePreventScroll.main.js +0 -215
  237. package/dist/usePreventScroll.main.js.map +0 -1
  238. package/dist/usePreventScroll.mjs +0 -210
  239. package/dist/usePreventScroll.module.js +0 -210
  240. package/dist/usePreventScroll.module.js.map +0 -1
  241. package/dist/zh-CN.main.js +0 -6
  242. package/dist/zh-CN.main.js.map +0 -1
  243. package/dist/zh-CN.mjs +0 -8
  244. package/dist/zh-CN.module.js +0 -8
  245. package/dist/zh-CN.module.js.map +0 -1
  246. package/dist/zh-TW.main.js +0 -6
  247. package/dist/zh-TW.main.js.map +0 -1
  248. package/dist/zh-TW.mjs +0 -8
  249. package/dist/zh-TW.module.js +0 -8
  250. package/dist/zh-TW.module.js.map +0 -1
  251. package/src/DismissButton.tsx +0 -52
  252. package/src/Overlay.tsx +0 -95
  253. package/src/PortalProvider.tsx +0 -41
  254. package/src/ariaHideOutside.ts +0 -221
  255. package/src/calculatePosition.ts +0 -680
  256. package/src/useCloseOnScroll.ts +0 -65
  257. package/src/useModal.tsx +0 -197
  258. package/src/useModalOverlay.ts +0 -69
  259. package/src/useOverlay.ts +0 -169
  260. package/src/useOverlayPosition.ts +0 -327
  261. package/src/useOverlayTrigger.ts +0 -72
  262. package/src/usePopover.ts +0 -138
  263. package/src/usePreventScroll.ts +0 -273
@@ -1,210 +0,0 @@
1
- import {useLayoutEffect as $7mMvr$useLayoutEffect, isIOS as $7mMvr$isIOS, chain as $7mMvr$chain, isScrollable as $7mMvr$isScrollable, getScrollParent as $7mMvr$getScrollParent, willOpenKeyboard as $7mMvr$willOpenKeyboard} from "@react-aria/utils";
2
-
3
- /*
4
- * Copyright 2020 Adobe. All rights reserved.
5
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License. You may obtain a copy
7
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software distributed under
10
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
- * OF ANY KIND, either express or implied. See the License for the specific language
12
- * governing permissions and limitations under the License.
13
- */
14
- const $49c51c25361d4cd2$var$visualViewport = typeof document !== 'undefined' && window.visualViewport;
15
- // The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position
16
- let $49c51c25361d4cd2$var$preventScrollCount = 0;
17
- let $49c51c25361d4cd2$var$restore;
18
- function $49c51c25361d4cd2$export$ee0f7cc6afcd1c18(options = {}) {
19
- let { isDisabled: isDisabled } = options;
20
- (0, $7mMvr$useLayoutEffect)(()=>{
21
- if (isDisabled) return;
22
- $49c51c25361d4cd2$var$preventScrollCount++;
23
- if ($49c51c25361d4cd2$var$preventScrollCount === 1) {
24
- if ((0, $7mMvr$isIOS)()) $49c51c25361d4cd2$var$restore = $49c51c25361d4cd2$var$preventScrollMobileSafari();
25
- else $49c51c25361d4cd2$var$restore = $49c51c25361d4cd2$var$preventScrollStandard();
26
- }
27
- return ()=>{
28
- $49c51c25361d4cd2$var$preventScrollCount--;
29
- if ($49c51c25361d4cd2$var$preventScrollCount === 0) $49c51c25361d4cd2$var$restore();
30
- };
31
- }, [
32
- isDisabled
33
- ]);
34
- }
35
- // For most browsers, all we need to do is set `overflow: hidden` on the root element, and
36
- // add some padding to prevent the page from shifting when the scrollbar is hidden.
37
- function $49c51c25361d4cd2$var$preventScrollStandard() {
38
- let scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
39
- return (0, $7mMvr$chain)(scrollbarWidth > 0 && // Use scrollbar-gutter when supported because it also works for fixed positioned elements.
40
- ('scrollbarGutter' in document.documentElement.style ? $49c51c25361d4cd2$var$setStyle(document.documentElement, 'scrollbarGutter', 'stable') : $49c51c25361d4cd2$var$setStyle(document.documentElement, 'paddingRight', `${scrollbarWidth}px`)), $49c51c25361d4cd2$var$setStyle(document.documentElement, 'overflow', 'hidden'));
41
- }
42
- // Mobile Safari is a whole different beast. Even with overflow: hidden,
43
- // it still scrolls the page in many situations:
44
- //
45
- // 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.
46
- // 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of
47
- // it, so it becomes scrollable.
48
- // 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.
49
- // This may cause even fixed position elements to scroll off the screen.
50
- // 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always
51
- // scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.
52
- //
53
- // In order to work around these cases, and prevent scrolling without jankiness, we do a few things:
54
- //
55
- // 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling
56
- // on the window.
57
- // 2. Set `overscroll-behavior: contain` on nested scrollable regions so they do not scroll the page when at
58
- // the top or bottom. Work around a bug where this does not work when the element does not actually overflow
59
- // by preventing default in a `touchmove` event. This is best effort: we can't prevent default when pinch
60
- // zooming or when an element contains text selection, which may allow scrolling in some cases.
61
- // 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.
62
- // 4. When focus moves to an input, create an off screen input and focus that temporarily. This prevents
63
- // Safari from scrolling the page. After a small delay, focus the real input and scroll it into view
64
- // ourselves, without scrolling the whole page.
65
- function $49c51c25361d4cd2$var$preventScrollMobileSafari() {
66
- let scrollable;
67
- let allowTouchMove = false;
68
- let onTouchStart = (e)=>{
69
- // Store the nearest scrollable parent element from the element that the user touched.
70
- let target = e.target;
71
- scrollable = (0, $7mMvr$isScrollable)(target) ? target : (0, $7mMvr$getScrollParent)(target, true);
72
- allowTouchMove = false;
73
- // If the target is selected, don't preventDefault in touchmove to allow user to adjust selection.
74
- let selection = target.ownerDocument.defaultView.getSelection();
75
- if (selection && !selection.isCollapsed && selection.containsNode(target, true)) allowTouchMove = true;
76
- // If this is a range input, allow touch move to allow user to adjust the slider value
77
- if (e.composedPath().some((el)=>el instanceof HTMLInputElement && el.type === 'range')) allowTouchMove = true;
78
- // If this is a focused input element with a selected range, allow user to drag the selection handles.
79
- if ('selectionStart' in target && 'selectionEnd' in target && target.selectionStart < target.selectionEnd && target.ownerDocument.activeElement === target) allowTouchMove = true;
80
- };
81
- // Prevent scrolling up when at the top and scrolling down when at the bottom
82
- // of a nested scrollable area, otherwise mobile Safari will start scrolling
83
- // the window instead.
84
- // This must be applied before the touchstart event as of iOS 26, so inject it as a <style> element.
85
- let style = document.createElement('style');
86
- style.textContent = `
87
- @layer {
88
- * {
89
- overscroll-behavior: contain;
90
- }
91
- }`.trim();
92
- document.head.prepend(style);
93
- let onTouchMove = (e)=>{
94
- // Allow pinch-zooming.
95
- if (e.touches.length === 2 || allowTouchMove) return;
96
- // Prevent scrolling the window.
97
- if (!scrollable || scrollable === document.documentElement || scrollable === document.body) {
98
- e.preventDefault();
99
- return;
100
- }
101
- // overscroll-behavior should prevent scroll chaining, but currently does not
102
- // if the element doesn't actually overflow. https://bugs.webkit.org/show_bug.cgi?id=243452
103
- // This checks that both the width and height do not overflow, otherwise we might
104
- // block horizontal scrolling too. In that case, adding `touch-action: pan-x` to
105
- // the element will prevent vertical page scrolling. We can't add that automatically
106
- // because it must be set before the touchstart event.
107
- if (scrollable.scrollHeight === scrollable.clientHeight && scrollable.scrollWidth === scrollable.clientWidth) e.preventDefault();
108
- };
109
- let onBlur = (e)=>{
110
- let target = e.target;
111
- let relatedTarget = e.relatedTarget;
112
- if (relatedTarget && (0, $7mMvr$willOpenKeyboard)(relatedTarget)) {
113
- // Focus without scrolling the whole page, and then scroll into view manually.
114
- relatedTarget.focus({
115
- preventScroll: true
116
- });
117
- $49c51c25361d4cd2$var$scrollIntoViewWhenReady(relatedTarget, (0, $7mMvr$willOpenKeyboard)(target));
118
- } else if (!relatedTarget) {
119
- var _target_parentElement;
120
- // When tapping the Done button on the keyboard, focus moves to the body.
121
- // FocusScope will then restore focus back to the input. Later when tapping
122
- // the same input again, it is already focused, so no blur event will fire,
123
- // resulting in the flow above never running and Safari's native scrolling occurring.
124
- // Instead, move focus to the parent focusable element (e.g. the dialog).
125
- let focusable = (_target_parentElement = target.parentElement) === null || _target_parentElement === void 0 ? void 0 : _target_parentElement.closest('[tabindex]');
126
- focusable === null || focusable === void 0 ? void 0 : focusable.focus({
127
- preventScroll: true
128
- });
129
- }
130
- };
131
- // Override programmatic focus to scroll into view without scrolling the whole page.
132
- let focus = HTMLElement.prototype.focus;
133
- HTMLElement.prototype.focus = function(opts) {
134
- // Track whether the keyboard was already visible before.
135
- let wasKeyboardVisible = document.activeElement != null && (0, $7mMvr$willOpenKeyboard)(document.activeElement);
136
- // Focus the element without scrolling the page.
137
- focus.call(this, {
138
- ...opts,
139
- preventScroll: true
140
- });
141
- if (!opts || !opts.preventScroll) $49c51c25361d4cd2$var$scrollIntoViewWhenReady(this, wasKeyboardVisible);
142
- };
143
- let removeEvents = (0, $7mMvr$chain)($49c51c25361d4cd2$var$addEvent(document, 'touchstart', onTouchStart, {
144
- passive: false,
145
- capture: true
146
- }), $49c51c25361d4cd2$var$addEvent(document, 'touchmove', onTouchMove, {
147
- passive: false,
148
- capture: true
149
- }), $49c51c25361d4cd2$var$addEvent(document, 'blur', onBlur, true));
150
- return ()=>{
151
- removeEvents();
152
- style.remove();
153
- HTMLElement.prototype.focus = focus;
154
- };
155
- }
156
- // Sets a CSS property on an element, and returns a function to revert it to the previous value.
157
- function $49c51c25361d4cd2$var$setStyle(element, style, value) {
158
- let cur = element.style[style];
159
- element.style[style] = value;
160
- return ()=>{
161
- element.style[style] = cur;
162
- };
163
- }
164
- // Adds an event listener to an element, and returns a function to remove it.
165
- function $49c51c25361d4cd2$var$addEvent(target, event, handler, options) {
166
- // internal function, so it's ok to ignore the difficult to fix type error
167
- // @ts-ignore
168
- target.addEventListener(event, handler, options);
169
- return ()=>{
170
- // @ts-ignore
171
- target.removeEventListener(event, handler, options);
172
- };
173
- }
174
- function $49c51c25361d4cd2$var$scrollIntoViewWhenReady(target, wasKeyboardVisible) {
175
- if (wasKeyboardVisible || !$49c51c25361d4cd2$var$visualViewport) // If the keyboard was already visible, scroll the target into view immediately.
176
- $49c51c25361d4cd2$var$scrollIntoView(target);
177
- else // Otherwise, wait for the visual viewport to resize before scrolling so we can
178
- // measure the correct position to scroll to.
179
- $49c51c25361d4cd2$var$visualViewport.addEventListener('resize', ()=>$49c51c25361d4cd2$var$scrollIntoView(target), {
180
- once: true
181
- });
182
- }
183
- function $49c51c25361d4cd2$var$scrollIntoView(target) {
184
- let root = document.scrollingElement || document.documentElement;
185
- let nextTarget = target;
186
- while(nextTarget && nextTarget !== root){
187
- // Find the parent scrollable element and adjust the scroll position if the target is not already in view.
188
- let scrollable = (0, $7mMvr$getScrollParent)(nextTarget);
189
- if (scrollable !== document.documentElement && scrollable !== document.body && scrollable !== nextTarget) {
190
- let scrollableRect = scrollable.getBoundingClientRect();
191
- let targetRect = nextTarget.getBoundingClientRect();
192
- if (targetRect.top < scrollableRect.top || targetRect.bottom > scrollableRect.top + nextTarget.clientHeight) {
193
- let bottom = scrollableRect.bottom;
194
- if ($49c51c25361d4cd2$var$visualViewport) bottom = Math.min(bottom, $49c51c25361d4cd2$var$visualViewport.offsetTop + $49c51c25361d4cd2$var$visualViewport.height);
195
- // Center within the viewport.
196
- let adjustment = targetRect.top - scrollableRect.top - ((bottom - scrollableRect.top) / 2 - targetRect.height / 2);
197
- scrollable.scrollTo({
198
- // Clamp to the valid range to prevent over-scrolling.
199
- top: Math.max(0, Math.min(scrollable.scrollHeight - scrollable.clientHeight, scrollable.scrollTop + adjustment)),
200
- behavior: 'smooth'
201
- });
202
- }
203
- }
204
- nextTarget = scrollable.parentElement;
205
- }
206
- }
207
-
208
-
209
- export {$49c51c25361d4cd2$export$ee0f7cc6afcd1c18 as usePreventScroll};
210
- //# sourceMappingURL=usePreventScroll.module.js.map
@@ -1,210 +0,0 @@
1
- import {useLayoutEffect as $7mMvr$useLayoutEffect, isIOS as $7mMvr$isIOS, chain as $7mMvr$chain, isScrollable as $7mMvr$isScrollable, getScrollParent as $7mMvr$getScrollParent, willOpenKeyboard as $7mMvr$willOpenKeyboard} from "@react-aria/utils";
2
-
3
- /*
4
- * Copyright 2020 Adobe. All rights reserved.
5
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License. You may obtain a copy
7
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software distributed under
10
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
- * OF ANY KIND, either express or implied. See the License for the specific language
12
- * governing permissions and limitations under the License.
13
- */
14
- const $49c51c25361d4cd2$var$visualViewport = typeof document !== 'undefined' && window.visualViewport;
15
- // The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position
16
- let $49c51c25361d4cd2$var$preventScrollCount = 0;
17
- let $49c51c25361d4cd2$var$restore;
18
- function $49c51c25361d4cd2$export$ee0f7cc6afcd1c18(options = {}) {
19
- let { isDisabled: isDisabled } = options;
20
- (0, $7mMvr$useLayoutEffect)(()=>{
21
- if (isDisabled) return;
22
- $49c51c25361d4cd2$var$preventScrollCount++;
23
- if ($49c51c25361d4cd2$var$preventScrollCount === 1) {
24
- if ((0, $7mMvr$isIOS)()) $49c51c25361d4cd2$var$restore = $49c51c25361d4cd2$var$preventScrollMobileSafari();
25
- else $49c51c25361d4cd2$var$restore = $49c51c25361d4cd2$var$preventScrollStandard();
26
- }
27
- return ()=>{
28
- $49c51c25361d4cd2$var$preventScrollCount--;
29
- if ($49c51c25361d4cd2$var$preventScrollCount === 0) $49c51c25361d4cd2$var$restore();
30
- };
31
- }, [
32
- isDisabled
33
- ]);
34
- }
35
- // For most browsers, all we need to do is set `overflow: hidden` on the root element, and
36
- // add some padding to prevent the page from shifting when the scrollbar is hidden.
37
- function $49c51c25361d4cd2$var$preventScrollStandard() {
38
- let scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
39
- return (0, $7mMvr$chain)(scrollbarWidth > 0 && // Use scrollbar-gutter when supported because it also works for fixed positioned elements.
40
- ('scrollbarGutter' in document.documentElement.style ? $49c51c25361d4cd2$var$setStyle(document.documentElement, 'scrollbarGutter', 'stable') : $49c51c25361d4cd2$var$setStyle(document.documentElement, 'paddingRight', `${scrollbarWidth}px`)), $49c51c25361d4cd2$var$setStyle(document.documentElement, 'overflow', 'hidden'));
41
- }
42
- // Mobile Safari is a whole different beast. Even with overflow: hidden,
43
- // it still scrolls the page in many situations:
44
- //
45
- // 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.
46
- // 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of
47
- // it, so it becomes scrollable.
48
- // 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.
49
- // This may cause even fixed position elements to scroll off the screen.
50
- // 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always
51
- // scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.
52
- //
53
- // In order to work around these cases, and prevent scrolling without jankiness, we do a few things:
54
- //
55
- // 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling
56
- // on the window.
57
- // 2. Set `overscroll-behavior: contain` on nested scrollable regions so they do not scroll the page when at
58
- // the top or bottom. Work around a bug where this does not work when the element does not actually overflow
59
- // by preventing default in a `touchmove` event. This is best effort: we can't prevent default when pinch
60
- // zooming or when an element contains text selection, which may allow scrolling in some cases.
61
- // 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.
62
- // 4. When focus moves to an input, create an off screen input and focus that temporarily. This prevents
63
- // Safari from scrolling the page. After a small delay, focus the real input and scroll it into view
64
- // ourselves, without scrolling the whole page.
65
- function $49c51c25361d4cd2$var$preventScrollMobileSafari() {
66
- let scrollable;
67
- let allowTouchMove = false;
68
- let onTouchStart = (e)=>{
69
- // Store the nearest scrollable parent element from the element that the user touched.
70
- let target = e.target;
71
- scrollable = (0, $7mMvr$isScrollable)(target) ? target : (0, $7mMvr$getScrollParent)(target, true);
72
- allowTouchMove = false;
73
- // If the target is selected, don't preventDefault in touchmove to allow user to adjust selection.
74
- let selection = target.ownerDocument.defaultView.getSelection();
75
- if (selection && !selection.isCollapsed && selection.containsNode(target, true)) allowTouchMove = true;
76
- // If this is a range input, allow touch move to allow user to adjust the slider value
77
- if (e.composedPath().some((el)=>el instanceof HTMLInputElement && el.type === 'range')) allowTouchMove = true;
78
- // If this is a focused input element with a selected range, allow user to drag the selection handles.
79
- if ('selectionStart' in target && 'selectionEnd' in target && target.selectionStart < target.selectionEnd && target.ownerDocument.activeElement === target) allowTouchMove = true;
80
- };
81
- // Prevent scrolling up when at the top and scrolling down when at the bottom
82
- // of a nested scrollable area, otherwise mobile Safari will start scrolling
83
- // the window instead.
84
- // This must be applied before the touchstart event as of iOS 26, so inject it as a <style> element.
85
- let style = document.createElement('style');
86
- style.textContent = `
87
- @layer {
88
- * {
89
- overscroll-behavior: contain;
90
- }
91
- }`.trim();
92
- document.head.prepend(style);
93
- let onTouchMove = (e)=>{
94
- // Allow pinch-zooming.
95
- if (e.touches.length === 2 || allowTouchMove) return;
96
- // Prevent scrolling the window.
97
- if (!scrollable || scrollable === document.documentElement || scrollable === document.body) {
98
- e.preventDefault();
99
- return;
100
- }
101
- // overscroll-behavior should prevent scroll chaining, but currently does not
102
- // if the element doesn't actually overflow. https://bugs.webkit.org/show_bug.cgi?id=243452
103
- // This checks that both the width and height do not overflow, otherwise we might
104
- // block horizontal scrolling too. In that case, adding `touch-action: pan-x` to
105
- // the element will prevent vertical page scrolling. We can't add that automatically
106
- // because it must be set before the touchstart event.
107
- if (scrollable.scrollHeight === scrollable.clientHeight && scrollable.scrollWidth === scrollable.clientWidth) e.preventDefault();
108
- };
109
- let onBlur = (e)=>{
110
- let target = e.target;
111
- let relatedTarget = e.relatedTarget;
112
- if (relatedTarget && (0, $7mMvr$willOpenKeyboard)(relatedTarget)) {
113
- // Focus without scrolling the whole page, and then scroll into view manually.
114
- relatedTarget.focus({
115
- preventScroll: true
116
- });
117
- $49c51c25361d4cd2$var$scrollIntoViewWhenReady(relatedTarget, (0, $7mMvr$willOpenKeyboard)(target));
118
- } else if (!relatedTarget) {
119
- var _target_parentElement;
120
- // When tapping the Done button on the keyboard, focus moves to the body.
121
- // FocusScope will then restore focus back to the input. Later when tapping
122
- // the same input again, it is already focused, so no blur event will fire,
123
- // resulting in the flow above never running and Safari's native scrolling occurring.
124
- // Instead, move focus to the parent focusable element (e.g. the dialog).
125
- let focusable = (_target_parentElement = target.parentElement) === null || _target_parentElement === void 0 ? void 0 : _target_parentElement.closest('[tabindex]');
126
- focusable === null || focusable === void 0 ? void 0 : focusable.focus({
127
- preventScroll: true
128
- });
129
- }
130
- };
131
- // Override programmatic focus to scroll into view without scrolling the whole page.
132
- let focus = HTMLElement.prototype.focus;
133
- HTMLElement.prototype.focus = function(opts) {
134
- // Track whether the keyboard was already visible before.
135
- let wasKeyboardVisible = document.activeElement != null && (0, $7mMvr$willOpenKeyboard)(document.activeElement);
136
- // Focus the element without scrolling the page.
137
- focus.call(this, {
138
- ...opts,
139
- preventScroll: true
140
- });
141
- if (!opts || !opts.preventScroll) $49c51c25361d4cd2$var$scrollIntoViewWhenReady(this, wasKeyboardVisible);
142
- };
143
- let removeEvents = (0, $7mMvr$chain)($49c51c25361d4cd2$var$addEvent(document, 'touchstart', onTouchStart, {
144
- passive: false,
145
- capture: true
146
- }), $49c51c25361d4cd2$var$addEvent(document, 'touchmove', onTouchMove, {
147
- passive: false,
148
- capture: true
149
- }), $49c51c25361d4cd2$var$addEvent(document, 'blur', onBlur, true));
150
- return ()=>{
151
- removeEvents();
152
- style.remove();
153
- HTMLElement.prototype.focus = focus;
154
- };
155
- }
156
- // Sets a CSS property on an element, and returns a function to revert it to the previous value.
157
- function $49c51c25361d4cd2$var$setStyle(element, style, value) {
158
- let cur = element.style[style];
159
- element.style[style] = value;
160
- return ()=>{
161
- element.style[style] = cur;
162
- };
163
- }
164
- // Adds an event listener to an element, and returns a function to remove it.
165
- function $49c51c25361d4cd2$var$addEvent(target, event, handler, options) {
166
- // internal function, so it's ok to ignore the difficult to fix type error
167
- // @ts-ignore
168
- target.addEventListener(event, handler, options);
169
- return ()=>{
170
- // @ts-ignore
171
- target.removeEventListener(event, handler, options);
172
- };
173
- }
174
- function $49c51c25361d4cd2$var$scrollIntoViewWhenReady(target, wasKeyboardVisible) {
175
- if (wasKeyboardVisible || !$49c51c25361d4cd2$var$visualViewport) // If the keyboard was already visible, scroll the target into view immediately.
176
- $49c51c25361d4cd2$var$scrollIntoView(target);
177
- else // Otherwise, wait for the visual viewport to resize before scrolling so we can
178
- // measure the correct position to scroll to.
179
- $49c51c25361d4cd2$var$visualViewport.addEventListener('resize', ()=>$49c51c25361d4cd2$var$scrollIntoView(target), {
180
- once: true
181
- });
182
- }
183
- function $49c51c25361d4cd2$var$scrollIntoView(target) {
184
- let root = document.scrollingElement || document.documentElement;
185
- let nextTarget = target;
186
- while(nextTarget && nextTarget !== root){
187
- // Find the parent scrollable element and adjust the scroll position if the target is not already in view.
188
- let scrollable = (0, $7mMvr$getScrollParent)(nextTarget);
189
- if (scrollable !== document.documentElement && scrollable !== document.body && scrollable !== nextTarget) {
190
- let scrollableRect = scrollable.getBoundingClientRect();
191
- let targetRect = nextTarget.getBoundingClientRect();
192
- if (targetRect.top < scrollableRect.top || targetRect.bottom > scrollableRect.top + nextTarget.clientHeight) {
193
- let bottom = scrollableRect.bottom;
194
- if ($49c51c25361d4cd2$var$visualViewport) bottom = Math.min(bottom, $49c51c25361d4cd2$var$visualViewport.offsetTop + $49c51c25361d4cd2$var$visualViewport.height);
195
- // Center within the viewport.
196
- let adjustment = targetRect.top - scrollableRect.top - ((bottom - scrollableRect.top) / 2 - targetRect.height / 2);
197
- scrollable.scrollTo({
198
- // Clamp to the valid range to prevent over-scrolling.
199
- top: Math.max(0, Math.min(scrollable.scrollHeight - scrollable.clientHeight, scrollable.scrollTop + adjustment)),
200
- behavior: 'smooth'
201
- });
202
- }
203
- }
204
- nextTarget = scrollable.parentElement;
205
- }
206
- }
207
-
208
-
209
- export {$49c51c25361d4cd2$export$ee0f7cc6afcd1c18 as usePreventScroll};
210
- //# sourceMappingURL=usePreventScroll.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC;AASD,MAAM,uCAAiB,OAAO,aAAa,eAAe,OAAO,cAAc;AAE/E,mIAAmI;AACnI,IAAI,2CAAqB;AACzB,IAAI;AAOG,SAAS,0CAAiB,UAAgC,CAAC,CAAC;IACjE,IAAI,cAAC,UAAU,EAAC,GAAG;IAEnB,CAAA,GAAA,sBAAc,EAAE;QACd,IAAI,YACF;QAGF;QACA,IAAI,6CAAuB;YACzB,IAAI,CAAA,GAAA,YAAI,KACN,gCAAU;iBAEV,gCAAU;;QAId,OAAO;YACL;YACA,IAAI,6CAAuB,GACzB;QAEJ;IACF,GAAG;QAAC;KAAW;AACjB;AAEA,0FAA0F;AAC1F,mFAAmF;AACnF,SAAS;IACP,IAAI,iBAAiB,OAAO,UAAU,GAAG,SAAS,eAAe,CAAC,WAAW;IAC7E,OA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eAAe,KAAM;QACxC,0GAA0G;QAC1G,IAAI,aAAa,CAAA,GAAA,sBAAc,EAAE;QACjC,IAAI,eAAe,SAAS,eAAe,IAAI,eAAe,SAAS,IAAI,IAAI,eAAe,YAAY;YACxG,IAAI,iBAAiB,WAAW,qBAAqB;YACrD,IAAI,aAAa,WAAW,qBAAqB;YACjD,IAAI,WAAW,GAAG,GAAG,eAAe,GAAG,IAAI,WAAW,MAAM,GAAG,eAAe,GAAG,GAAG,WAAW,YAAY,EAAE;gBAC3G,IAAI,SAAS,eAAe,MAAM;gBAClC,IAAI,sCACF,SAAS,KAAK,GAAG,CAAC,QAAQ,qCAAe,SAAS,GAAG,qCAAe,MAAM;gBAG5E,8BAA8B;gBAC9B,IAAI,aAAa,AAAC,WAAW,GAAG,GAAG,eAAe,GAAG,GAAK,CAAA,AAAC,CAAA,SAAS,eAAe,GAAG,AAAD,IAAK,IAAI,WAAW,MAAM,GAAG,CAAA;gBAClH,WAAW,QAAQ,CAAC;oBAClB,sDAAsD;oBACtD,KAAK,KAAK,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,WAAW,YAAY,GAAG,WAAW,YAAY,EAAE,WAAW,SAAS,GAAG;oBACpG,UAAU;gBACZ;YACF;QACF;QAEA,aAAa,WAAW,aAAa;IACvC;AACF","sources":["packages/@react-aria/overlays/src/usePreventScroll.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 {chain, getScrollParent, isIOS, isScrollable, useLayoutEffect, willOpenKeyboard} from '@react-aria/utils';\n\ninterface PreventScrollOptions {\n /** Whether the scroll lock is disabled. */\n isDisabled?: boolean\n}\n\nconst visualViewport = typeof document !== 'undefined' && window.visualViewport;\n\n// The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position\nlet preventScrollCount = 0;\nlet restore;\n\n/**\n * Prevents scrolling on the document body on mount, and\n * restores it on unmount. Also ensures that content does not\n * shift due to the scrollbars disappearing.\n */\nexport function usePreventScroll(options: PreventScrollOptions = {}): void {\n let {isDisabled} = options;\n\n useLayoutEffect(() => {\n if (isDisabled) {\n return;\n }\n\n preventScrollCount++;\n if (preventScrollCount === 1) {\n if (isIOS()) {\n restore = preventScrollMobileSafari();\n } else {\n restore = preventScrollStandard();\n }\n }\n\n return () => {\n preventScrollCount--;\n if (preventScrollCount === 0) {\n restore();\n }\n };\n }, [isDisabled]);\n}\n\n// For most browsers, all we need to do is set `overflow: hidden` on the root element, and\n// add some padding to prevent the page from shifting when the scrollbar is hidden.\nfunction preventScrollStandard() {\n let scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;\n return chain(\n scrollbarWidth > 0 &&\n // Use scrollbar-gutter when supported because it also works for fixed positioned elements.\n ('scrollbarGutter' in document.documentElement.style\n ? setStyle(document.documentElement, 'scrollbarGutter', 'stable')\n : setStyle(document.documentElement, 'paddingRight', `${scrollbarWidth}px`)),\n setStyle(document.documentElement, 'overflow', 'hidden')\n );\n}\n\n// Mobile Safari is a whole different beast. Even with overflow: hidden,\n// it still scrolls the page in many situations:\n//\n// 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.\n// 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of\n// it, so it becomes scrollable.\n// 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.\n// This may cause even fixed position elements to scroll off the screen.\n// 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always\n// scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.\n//\n// In order to work around these cases, and prevent scrolling without jankiness, we do a few things:\n//\n// 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling\n// on the window.\n// 2. Set `overscroll-behavior: contain` on nested scrollable regions so they do not scroll the page when at\n// the top or bottom. Work around a bug where this does not work when the element does not actually overflow\n// by preventing default in a `touchmove` event. This is best effort: we can't prevent default when pinch\n// zooming or when an element contains text selection, which may allow scrolling in some cases.\n// 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.\n// 4. When focus moves to an input, create an off screen input and focus that temporarily. This prevents \n// Safari from scrolling the page. After a small delay, focus the real input and scroll it into view\n// ourselves, without scrolling the whole page.\nfunction preventScrollMobileSafari() {\n let scrollable: Element;\n let allowTouchMove = false;\n let onTouchStart = (e: TouchEvent) => {\n // Store the nearest scrollable parent element from the element that the user touched.\n let target = e.target as Element;\n scrollable = isScrollable(target) ? target : getScrollParent(target, true);\n allowTouchMove = false;\n \n // If the target is selected, don't preventDefault in touchmove to allow user to adjust selection.\n let selection = target.ownerDocument.defaultView!.getSelection();\n if (selection && !selection.isCollapsed && selection.containsNode(target, true)) {\n allowTouchMove = true;\n }\n\n // If this is a range input, allow touch move to allow user to adjust the slider value\n if (e.composedPath().some((el) =>\n el instanceof HTMLInputElement &&\n el.type === 'range'\n )) {\n allowTouchMove = true;\n }\n\n // If this is a focused input element with a selected range, allow user to drag the selection handles.\n if (\n 'selectionStart' in target && \n 'selectionEnd' in target &&\n (target.selectionStart as number) < (target.selectionEnd as number) &&\n target.ownerDocument.activeElement === target\n ) {\n allowTouchMove = true;\n }\n };\n\n // Prevent scrolling up when at the top and scrolling down when at the bottom\n // of a nested scrollable area, otherwise mobile Safari will start scrolling\n // the window instead.\n // This must be applied before the touchstart event as of iOS 26, so inject it as a <style> element.\n let style = document.createElement('style');\n style.textContent = `\n@layer {\n * {\n overscroll-behavior: contain;\n }\n}`.trim();\n document.head.prepend(style);\n\n let onTouchMove = (e: TouchEvent) => {\n // Allow pinch-zooming.\n if (e.touches.length === 2 || allowTouchMove) {\n return;\n }\n\n // Prevent scrolling the window.\n if (!scrollable || scrollable === document.documentElement || scrollable === document.body) {\n e.preventDefault();\n return;\n }\n\n // overscroll-behavior should prevent scroll chaining, but currently does not\n // if the element doesn't actually overflow. https://bugs.webkit.org/show_bug.cgi?id=243452\n // This checks that both the width and height do not overflow, otherwise we might\n // block horizontal scrolling too. In that case, adding `touch-action: pan-x` to\n // the element will prevent vertical page scrolling. We can't add that automatically\n // because it must be set before the touchstart event.\n if (scrollable.scrollHeight === scrollable.clientHeight && scrollable.scrollWidth === scrollable.clientWidth) {\n e.preventDefault();\n }\n };\n\n let onBlur = (e: FocusEvent) => {\n let target = e.target as HTMLElement;\n let relatedTarget = e.relatedTarget as HTMLElement | null;\n if (relatedTarget && willOpenKeyboard(relatedTarget)) {\n // Focus without scrolling the whole page, and then scroll into view manually.\n relatedTarget.focus({preventScroll: true});\n scrollIntoViewWhenReady(relatedTarget, willOpenKeyboard(target));\n } else if (!relatedTarget) {\n // When tapping the Done button on the keyboard, focus moves to the body.\n // FocusScope will then restore focus back to the input. Later when tapping\n // the same input again, it is already focused, so no blur event will fire,\n // resulting in the flow above never running and Safari's native scrolling occurring.\n // Instead, move focus to the parent focusable element (e.g. the dialog).\n let focusable = target.parentElement?.closest('[tabindex]') as HTMLElement | null;\n focusable?.focus({preventScroll: true});\n }\n };\n\n // Override programmatic focus to scroll into view without scrolling the whole page.\n let focus = HTMLElement.prototype.focus;\n HTMLElement.prototype.focus = function (opts) {\n // Track whether the keyboard was already visible before.\n let wasKeyboardVisible = document.activeElement != null && willOpenKeyboard(document.activeElement);\n\n // Focus the element without scrolling the page.\n focus.call(this, {...opts, preventScroll: true});\n\n if (!opts || !opts.preventScroll) {\n scrollIntoViewWhenReady(this, wasKeyboardVisible);\n }\n };\n\n let removeEvents = chain(\n addEvent(document, 'touchstart', onTouchStart, {passive: false, capture: true}),\n addEvent(document, 'touchmove', onTouchMove, {passive: false, capture: true}),\n addEvent(document, 'blur', onBlur, true)\n );\n\n return () => {\n removeEvents();\n style.remove();\n HTMLElement.prototype.focus = focus;\n };\n}\n\n// Sets a CSS property on an element, and returns a function to revert it to the previous value.\nfunction setStyle(element: HTMLElement, style: string, value: string) {\n let cur = element.style[style];\n element.style[style] = value;\n\n return () => {\n element.style[style] = cur;\n };\n}\n\n// Adds an event listener to an element, and returns a function to remove it.\nfunction addEvent<K extends keyof GlobalEventHandlersEventMap>(\n target: Document | Window,\n event: K,\n handler: (this: Document | Window, ev: GlobalEventHandlersEventMap[K]) => any,\n options?: boolean | AddEventListenerOptions\n) {\n // internal function, so it's ok to ignore the difficult to fix type error\n // @ts-ignore\n target.addEventListener(event, handler, options);\n return () => {\n // @ts-ignore\n target.removeEventListener(event, handler, options);\n };\n}\n\nfunction scrollIntoViewWhenReady(target: Element, wasKeyboardVisible: boolean) {\n if (wasKeyboardVisible || !visualViewport) {\n // If the keyboard was already visible, scroll the target into view immediately.\n scrollIntoView(target);\n } else {\n // Otherwise, wait for the visual viewport to resize before scrolling so we can\n // measure the correct position to scroll to.\n visualViewport.addEventListener('resize', () => scrollIntoView(target), {once: true});\n }\n}\n\nfunction scrollIntoView(target: Element) {\n let root = document.scrollingElement || document.documentElement;\n let nextTarget: Element | null = target;\n while (nextTarget && nextTarget !== root) {\n // Find the parent scrollable element and adjust the scroll position if the target is not already in view.\n let scrollable = getScrollParent(nextTarget);\n if (scrollable !== document.documentElement && scrollable !== document.body && scrollable !== nextTarget) {\n let scrollableRect = scrollable.getBoundingClientRect();\n let targetRect = nextTarget.getBoundingClientRect();\n if (targetRect.top < scrollableRect.top || targetRect.bottom > scrollableRect.top + nextTarget.clientHeight) {\n let bottom = scrollableRect.bottom;\n if (visualViewport) {\n bottom = Math.min(bottom, visualViewport.offsetTop + visualViewport.height);\n }\n\n // Center within the viewport.\n let adjustment = (targetRect.top - scrollableRect.top) - ((bottom - scrollableRect.top) / 2 - targetRect.height / 2);\n scrollable.scrollTo({\n // Clamp to the valid range to prevent over-scrolling.\n top: Math.max(0, Math.min(scrollable.scrollHeight - scrollable.clientHeight, scrollable.scrollTop + adjustment)),\n behavior: 'smooth'\n });\n }\n }\n\n nextTarget = scrollable.parentElement;\n }\n}\n"],"names":[],"version":3,"file":"usePreventScroll.module.js.map"}
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- "dismiss": `\u{53D6}\u{6D88}`
3
- };
4
-
5
-
6
- //# sourceMappingURL=zh-CN.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":"AAAA,iBAAiB;IAAG,WAAW,CAAC,gBAAE,CAAC;AACnC","sources":["packages/@react-aria/overlays/intl/zh-CN.json"],"sourcesContent":["{\n \"dismiss\": \"取消\"\n}\n"],"names":[],"version":3,"file":"zh-CN.main.js.map"}
package/dist/zh-CN.mjs DELETED
@@ -1,8 +0,0 @@
1
- var $d80a27deda7cdb3c$exports = {};
2
- $d80a27deda7cdb3c$exports = {
3
- "dismiss": `\u{53D6}\u{6D88}`
4
- };
5
-
6
-
7
- export {$d80a27deda7cdb3c$exports as default};
8
- //# sourceMappingURL=zh-CN.module.js.map
@@ -1,8 +0,0 @@
1
- var $d80a27deda7cdb3c$exports = {};
2
- $d80a27deda7cdb3c$exports = {
3
- "dismiss": `\u{53D6}\u{6D88}`
4
- };
5
-
6
-
7
- export {$d80a27deda7cdb3c$exports as default};
8
- //# sourceMappingURL=zh-CN.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";AAAA,4BAAiB;IAAG,WAAW,CAAC,gBAAE,CAAC;AACnC","sources":["packages/@react-aria/overlays/intl/zh-CN.json"],"sourcesContent":["{\n \"dismiss\": \"取消\"\n}\n"],"names":[],"version":3,"file":"zh-CN.module.js.map"}
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- "dismiss": `\u{95DC}\u{9589}`
3
- };
4
-
5
-
6
- //# sourceMappingURL=zh-TW.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":"AAAA,iBAAiB;IAAG,WAAW,CAAC,gBAAE,CAAC;AACnC","sources":["packages/@react-aria/overlays/intl/zh-TW.json"],"sourcesContent":["{\n \"dismiss\": \"關閉\"\n}\n"],"names":[],"version":3,"file":"zh-TW.main.js.map"}
package/dist/zh-TW.mjs DELETED
@@ -1,8 +0,0 @@
1
- var $2b2734393847c884$exports = {};
2
- $2b2734393847c884$exports = {
3
- "dismiss": `\u{95DC}\u{9589}`
4
- };
5
-
6
-
7
- export {$2b2734393847c884$exports as default};
8
- //# sourceMappingURL=zh-TW.module.js.map
@@ -1,8 +0,0 @@
1
- var $2b2734393847c884$exports = {};
2
- $2b2734393847c884$exports = {
3
- "dismiss": `\u{95DC}\u{9589}`
4
- };
5
-
6
-
7
- export {$2b2734393847c884$exports as default};
8
- //# sourceMappingURL=zh-TW.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";AAAA,4BAAiB;IAAG,WAAW,CAAC,gBAAE,CAAC;AACnC","sources":["packages/@react-aria/overlays/intl/zh-TW.json"],"sourcesContent":["{\n \"dismiss\": \"關閉\"\n}\n"],"names":[],"version":3,"file":"zh-TW.module.js.map"}
@@ -1,52 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {AriaLabelingProps, DOMProps} from '@react-types/shared';
14
- // @ts-ignore
15
- import intlMessages from '../intl/*.json';
16
- import React, {JSX} from 'react';
17
- import {useLabels} from '@react-aria/utils';
18
- import {useLocalizedStringFormatter} from '@react-aria/i18n';
19
- import {VisuallyHidden} from '@react-aria/visually-hidden';
20
-
21
- export interface DismissButtonProps extends AriaLabelingProps, DOMProps {
22
- /** Called when the dismiss button is activated. */
23
- onDismiss?: () => void
24
- }
25
-
26
- /**
27
- * A visually hidden button that can be used to allow screen reader
28
- * users to dismiss a modal or popup when there is no visual
29
- * affordance to do so.
30
- */
31
- export function DismissButton(props: DismissButtonProps): JSX.Element {
32
- let {onDismiss, ...otherProps} = props;
33
- let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/overlays');
34
-
35
- let labels = useLabels(otherProps, stringFormatter.format('dismiss'));
36
-
37
- let onClick = () => {
38
- if (onDismiss) {
39
- onDismiss();
40
- }
41
- };
42
-
43
- return (
44
- <VisuallyHidden>
45
- <button
46
- {...labels}
47
- tabIndex={-1}
48
- onClick={onClick}
49
- style={{width: 1, height: 1}} />
50
- </VisuallyHidden>
51
- );
52
- }