@react-aria/overlays 3.12.0 → 3.12.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/main.js +308 -187
- package/dist/main.js.map +1 -1
- package/dist/module.js +308 -187
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +11 -11
- package/src/usePreventScroll.ts +20 -4
package/src/usePreventScroll.ts
CHANGED
|
@@ -33,6 +33,10 @@ const nonTextInputTypes = new Set([
|
|
|
33
33
|
'reset'
|
|
34
34
|
]);
|
|
35
35
|
|
|
36
|
+
// The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position
|
|
37
|
+
let preventScrollCount = 0;
|
|
38
|
+
let restore;
|
|
39
|
+
|
|
36
40
|
/**
|
|
37
41
|
* Prevents scrolling on the document body on mount, and
|
|
38
42
|
* restores it on unmount. Also ensures that content does not
|
|
@@ -46,11 +50,21 @@ export function usePreventScroll(options: PreventScrollOptions = {}) {
|
|
|
46
50
|
return;
|
|
47
51
|
}
|
|
48
52
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
preventScrollCount++;
|
|
54
|
+
if (preventScrollCount === 1) {
|
|
55
|
+
if (isIOS()) {
|
|
56
|
+
restore = preventScrollMobileSafari();
|
|
57
|
+
} else {
|
|
58
|
+
restore = preventScrollStandard();
|
|
59
|
+
}
|
|
53
60
|
}
|
|
61
|
+
|
|
62
|
+
return () => {
|
|
63
|
+
preventScrollCount--;
|
|
64
|
+
if (preventScrollCount === 0) {
|
|
65
|
+
restore();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
54
68
|
}, [isDisabled]);
|
|
55
69
|
}
|
|
56
70
|
|
|
@@ -183,6 +197,7 @@ function preventScrollMobileSafari() {
|
|
|
183
197
|
// enable us to scroll the window to the top, which is required for the rest of this to work.
|
|
184
198
|
let scrollX = window.pageXOffset;
|
|
185
199
|
let scrollY = window.pageYOffset;
|
|
200
|
+
|
|
186
201
|
let restoreStyles = chain(
|
|
187
202
|
setStyle(document.documentElement, 'paddingRight', `${window.innerWidth - document.documentElement.clientWidth}px`),
|
|
188
203
|
setStyle(document.documentElement, 'overflow', 'hidden'),
|
|
@@ -212,6 +227,7 @@ function preventScrollMobileSafari() {
|
|
|
212
227
|
function setStyle(element: HTMLElement, style: string, value: string) {
|
|
213
228
|
let cur = element.style[style];
|
|
214
229
|
element.style[style] = value;
|
|
230
|
+
|
|
215
231
|
return () => {
|
|
216
232
|
element.style[style] = cur;
|
|
217
233
|
};
|