@react-aria/overlays 3.21.1 → 3.22.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/DismissButton.main.js +51 -0
- package/dist/DismissButton.main.js.map +1 -0
- package/dist/DismissButton.mjs +46 -0
- package/dist/DismissButton.module.js +46 -0
- package/dist/DismissButton.module.js.map +1 -0
- package/dist/Overlay.main.js +73 -0
- package/dist/Overlay.main.js.map +1 -0
- package/dist/Overlay.mjs +63 -0
- package/dist/Overlay.module.js +63 -0
- package/dist/Overlay.module.js.map +1 -0
- package/dist/PortalProvider.main.js +41 -0
- package/dist/PortalProvider.main.js.map +1 -0
- package/dist/PortalProvider.mjs +31 -0
- package/dist/PortalProvider.module.js +31 -0
- package/dist/PortalProvider.module.js.map +1 -0
- package/dist/ariaHideOutside.main.js +121 -0
- package/dist/ariaHideOutside.main.js.map +1 -0
- package/dist/ariaHideOutside.mjs +116 -0
- package/dist/ariaHideOutside.module.js +116 -0
- package/dist/ariaHideOutside.module.js.map +1 -0
- package/dist/calculatePosition.main.js +355 -0
- package/dist/calculatePosition.main.js.map +1 -0
- package/dist/calculatePosition.mjs +350 -0
- package/dist/calculatePosition.module.js +350 -0
- package/dist/calculatePosition.module.js.map +1 -0
- package/dist/import.mjs +12 -1397
- package/dist/intlStrings.main.js +108 -0
- package/dist/intlStrings.main.js.map +1 -0
- package/dist/intlStrings.mjs +110 -0
- package/dist/intlStrings.module.js +110 -0
- package/dist/intlStrings.module.js.map +1 -0
- package/dist/main.js +28 -1411
- package/dist/main.js.map +1 -1
- package/dist/module.js +12 -1397
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +8 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/useCloseOnScroll.main.js +46 -0
- package/dist/useCloseOnScroll.main.js.map +1 -0
- package/dist/useCloseOnScroll.mjs +40 -0
- package/dist/useCloseOnScroll.module.js +40 -0
- package/dist/useCloseOnScroll.module.js.map +1 -0
- package/dist/useModal.main.js +114 -0
- package/dist/useModal.main.js.map +1 -0
- package/dist/useModal.mjs +101 -0
- package/dist/useModal.module.js +101 -0
- package/dist/useModal.module.js.map +1 -0
- package/dist/useModalOverlay.main.js +55 -0
- package/dist/useModalOverlay.main.js.map +1 -0
- package/dist/useModalOverlay.mjs +50 -0
- package/dist/useModalOverlay.module.js +50 -0
- package/dist/useModalOverlay.module.js.map +1 -0
- package/dist/useOverlay.main.js +105 -0
- package/dist/useOverlay.main.js.map +1 -0
- package/dist/useOverlay.mjs +100 -0
- package/dist/useOverlay.module.js +100 -0
- package/dist/useOverlay.module.js.map +1 -0
- package/dist/useOverlayPosition.main.js +190 -0
- package/dist/useOverlayPosition.main.js.map +1 -0
- package/dist/useOverlayPosition.mjs +185 -0
- package/dist/useOverlayPosition.module.js +185 -0
- package/dist/useOverlayPosition.module.js.map +1 -0
- package/dist/useOverlayTrigger.main.js +54 -0
- package/dist/useOverlayTrigger.main.js.map +1 -0
- package/dist/useOverlayTrigger.mjs +49 -0
- package/dist/useOverlayTrigger.module.js +49 -0
- package/dist/useOverlayTrigger.module.js.map +1 -0
- package/dist/usePopover.main.js +66 -0
- package/dist/usePopover.main.js.map +1 -0
- package/dist/usePopover.mjs +61 -0
- package/dist/usePopover.module.js +61 -0
- package/dist/usePopover.module.js.map +1 -0
- package/dist/usePreventScroll.main.js +226 -0
- package/dist/usePreventScroll.main.js.map +1 -0
- package/dist/usePreventScroll.mjs +221 -0
- package/dist/usePreventScroll.module.js +221 -0
- package/dist/usePreventScroll.module.js.map +1 -0
- package/package.json +12 -12
- package/src/Overlay.tsx +6 -0
- package/src/PortalProvider.tsx +34 -0
- package/src/calculatePosition.ts +3 -3
- package/src/index.ts +1 -0
- package/src/useModalOverlay.ts +2 -2
- package/src/useOverlay.ts +1 -1
- package/src/useOverlayPosition.ts +8 -3
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import {useLayoutEffect as $7mMvr$useLayoutEffect, isIOS as $7mMvr$isIOS, chain as $7mMvr$chain, getScrollParent as $7mMvr$getScrollParent} 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
|
+
// @ts-ignore
|
|
15
|
+
const $49c51c25361d4cd2$var$visualViewport = typeof document !== 'undefined' && window.visualViewport;
|
|
16
|
+
// HTML input types that do not cause the software keyboard to appear.
|
|
17
|
+
const $49c51c25361d4cd2$var$nonTextInputTypes = new Set([
|
|
18
|
+
'checkbox',
|
|
19
|
+
'radio',
|
|
20
|
+
'range',
|
|
21
|
+
'color',
|
|
22
|
+
'file',
|
|
23
|
+
'image',
|
|
24
|
+
'button',
|
|
25
|
+
'submit',
|
|
26
|
+
'reset'
|
|
27
|
+
]);
|
|
28
|
+
// The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position
|
|
29
|
+
let $49c51c25361d4cd2$var$preventScrollCount = 0;
|
|
30
|
+
let $49c51c25361d4cd2$var$restore;
|
|
31
|
+
function $49c51c25361d4cd2$export$ee0f7cc6afcd1c18(options = {}) {
|
|
32
|
+
let { isDisabled: isDisabled } = options;
|
|
33
|
+
(0, $7mMvr$useLayoutEffect)(()=>{
|
|
34
|
+
if (isDisabled) return;
|
|
35
|
+
$49c51c25361d4cd2$var$preventScrollCount++;
|
|
36
|
+
if ($49c51c25361d4cd2$var$preventScrollCount === 1) {
|
|
37
|
+
if ((0, $7mMvr$isIOS)()) $49c51c25361d4cd2$var$restore = $49c51c25361d4cd2$var$preventScrollMobileSafari();
|
|
38
|
+
else $49c51c25361d4cd2$var$restore = $49c51c25361d4cd2$var$preventScrollStandard();
|
|
39
|
+
}
|
|
40
|
+
return ()=>{
|
|
41
|
+
$49c51c25361d4cd2$var$preventScrollCount--;
|
|
42
|
+
if ($49c51c25361d4cd2$var$preventScrollCount === 0) $49c51c25361d4cd2$var$restore();
|
|
43
|
+
};
|
|
44
|
+
}, [
|
|
45
|
+
isDisabled
|
|
46
|
+
]);
|
|
47
|
+
}
|
|
48
|
+
// For most browsers, all we need to do is set `overflow: hidden` on the root element, and
|
|
49
|
+
// add some padding to prevent the page from shifting when the scrollbar is hidden.
|
|
50
|
+
function $49c51c25361d4cd2$var$preventScrollStandard() {
|
|
51
|
+
return (0, $7mMvr$chain)($49c51c25361d4cd2$var$setStyle(document.documentElement, 'paddingRight', `${window.innerWidth - document.documentElement.clientWidth}px`), $49c51c25361d4cd2$var$setStyle(document.documentElement, 'overflow', 'hidden'));
|
|
52
|
+
}
|
|
53
|
+
// Mobile Safari is a whole different beast. Even with overflow: hidden,
|
|
54
|
+
// it still scrolls the page in many situations:
|
|
55
|
+
//
|
|
56
|
+
// 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.
|
|
57
|
+
// 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of
|
|
58
|
+
// it, so it becomes scrollable.
|
|
59
|
+
// 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.
|
|
60
|
+
// This may cause even fixed position elements to scroll off the screen.
|
|
61
|
+
// 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always
|
|
62
|
+
// scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.
|
|
63
|
+
//
|
|
64
|
+
// In order to work around these cases, and prevent scrolling without jankiness, we do a few things:
|
|
65
|
+
//
|
|
66
|
+
// 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling
|
|
67
|
+
// on the window.
|
|
68
|
+
// 2. Set `overscroll-behavior: contain` on nested scrollable regions so they do not scroll the page when at
|
|
69
|
+
// the top or bottom. Work around a bug where this does not work when the element does not actually overflow
|
|
70
|
+
// by preventing default in a `touchmove` event.
|
|
71
|
+
// 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.
|
|
72
|
+
// 4. When focusing an input, apply a transform to trick Safari into thinking the input is at the top
|
|
73
|
+
// of the page, which prevents it from scrolling the page. After the input is focused, scroll the element
|
|
74
|
+
// into view ourselves, without scrolling the whole page.
|
|
75
|
+
// 5. Offset the body by the scroll position using a negative margin and scroll to the top. This should appear the
|
|
76
|
+
// same visually, but makes the actual scroll position always zero. This is required to make all of the
|
|
77
|
+
// above work or Safari will still try to scroll the page when focusing an input.
|
|
78
|
+
// 6. As a last resort, handle window scroll events, and scroll back to the top. This can happen when attempting
|
|
79
|
+
// to navigate to an input with the next/previous buttons that's outside a modal.
|
|
80
|
+
function $49c51c25361d4cd2$var$preventScrollMobileSafari() {
|
|
81
|
+
let scrollable;
|
|
82
|
+
let restoreScrollableStyles;
|
|
83
|
+
let onTouchStart = (e)=>{
|
|
84
|
+
// Store the nearest scrollable parent element from the element that the user touched.
|
|
85
|
+
scrollable = (0, $7mMvr$getScrollParent)(e.target, true);
|
|
86
|
+
if (scrollable === document.documentElement && scrollable === document.body) return;
|
|
87
|
+
// Prevent scrolling up when at the top and scrolling down when at the bottom
|
|
88
|
+
// of a nested scrollable area, otherwise mobile Safari will start scrolling
|
|
89
|
+
// the window instead.
|
|
90
|
+
if (scrollable instanceof HTMLElement && window.getComputedStyle(scrollable).overscrollBehavior === 'auto') restoreScrollableStyles = $49c51c25361d4cd2$var$setStyle(scrollable, 'overscrollBehavior', 'contain');
|
|
91
|
+
};
|
|
92
|
+
let onTouchMove = (e)=>{
|
|
93
|
+
// Prevent scrolling the window.
|
|
94
|
+
if (!scrollable || scrollable === document.documentElement || scrollable === document.body) {
|
|
95
|
+
e.preventDefault();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
// overscroll-behavior should prevent scroll chaining, but currently does not
|
|
99
|
+
// if the element doesn't actually overflow. https://bugs.webkit.org/show_bug.cgi?id=243452
|
|
100
|
+
// This checks that both the width and height do not overflow, otherwise we might
|
|
101
|
+
// block horizontal scrolling too. In that case, adding `touch-action: pan-x` to
|
|
102
|
+
// the element will prevent vertical page scrolling. We can't add that automatically
|
|
103
|
+
// because it must be set before the touchstart event.
|
|
104
|
+
if (scrollable.scrollHeight === scrollable.clientHeight && scrollable.scrollWidth === scrollable.clientWidth) e.preventDefault();
|
|
105
|
+
};
|
|
106
|
+
let onTouchEnd = (e)=>{
|
|
107
|
+
let target = e.target;
|
|
108
|
+
// Apply this change if we're not already focused on the target element
|
|
109
|
+
if ($49c51c25361d4cd2$var$willOpenKeyboard(target) && target !== document.activeElement) {
|
|
110
|
+
e.preventDefault();
|
|
111
|
+
setupStyles();
|
|
112
|
+
// Apply a transform to trick Safari into thinking the input is at the top of the page
|
|
113
|
+
// so it doesn't try to scroll it into view. When tapping on an input, this needs to
|
|
114
|
+
// be done before the "focus" event, so we have to focus the element ourselves.
|
|
115
|
+
target.style.transform = 'translateY(-2000px)';
|
|
116
|
+
target.focus();
|
|
117
|
+
requestAnimationFrame(()=>{
|
|
118
|
+
target.style.transform = '';
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
if (restoreScrollableStyles) restoreScrollableStyles();
|
|
122
|
+
};
|
|
123
|
+
let onFocus = (e)=>{
|
|
124
|
+
let target = e.target;
|
|
125
|
+
if ($49c51c25361d4cd2$var$willOpenKeyboard(target)) {
|
|
126
|
+
setupStyles();
|
|
127
|
+
// Transform also needs to be applied in the focus event in cases where focus moves
|
|
128
|
+
// other than tapping on an input directly, e.g. the next/previous buttons in the
|
|
129
|
+
// software keyboard. In these cases, it seems applying the transform in the focus event
|
|
130
|
+
// is good enough, whereas when tapping an input, it must be done before the focus event. 🤷♂️
|
|
131
|
+
target.style.transform = 'translateY(-2000px)';
|
|
132
|
+
requestAnimationFrame(()=>{
|
|
133
|
+
target.style.transform = '';
|
|
134
|
+
// This will have prevented the browser from scrolling the focused element into view,
|
|
135
|
+
// so we need to do this ourselves in a way that doesn't cause the whole page to scroll.
|
|
136
|
+
if ($49c51c25361d4cd2$var$visualViewport) {
|
|
137
|
+
if ($49c51c25361d4cd2$var$visualViewport.height < window.innerHeight) // If the keyboard is already visible, do this after one additional frame
|
|
138
|
+
// to wait for the transform to be removed.
|
|
139
|
+
requestAnimationFrame(()=>{
|
|
140
|
+
$49c51c25361d4cd2$var$scrollIntoView(target);
|
|
141
|
+
});
|
|
142
|
+
else // Otherwise, wait for the visual viewport to resize before scrolling so we can
|
|
143
|
+
// measure the correct position to scroll to.
|
|
144
|
+
$49c51c25361d4cd2$var$visualViewport.addEventListener('resize', ()=>$49c51c25361d4cd2$var$scrollIntoView(target), {
|
|
145
|
+
once: true
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
let restoreStyles = null;
|
|
152
|
+
let setupStyles = ()=>{
|
|
153
|
+
if (restoreStyles) return;
|
|
154
|
+
let onWindowScroll = ()=>{
|
|
155
|
+
// Last resort. If the window scrolled, scroll it back to the top.
|
|
156
|
+
// It should always be at the top because the body will have a negative margin (see below).
|
|
157
|
+
window.scrollTo(0, 0);
|
|
158
|
+
};
|
|
159
|
+
// Record the original scroll position so we can restore it.
|
|
160
|
+
// Then apply a negative margin to the body to offset it by the scroll position. This will
|
|
161
|
+
// enable us to scroll the window to the top, which is required for the rest of this to work.
|
|
162
|
+
let scrollX = window.pageXOffset;
|
|
163
|
+
let scrollY = window.pageYOffset;
|
|
164
|
+
restoreStyles = (0, $7mMvr$chain)($49c51c25361d4cd2$var$addEvent(window, 'scroll', onWindowScroll), $49c51c25361d4cd2$var$setStyle(document.documentElement, 'paddingRight', `${window.innerWidth - document.documentElement.clientWidth}px`), $49c51c25361d4cd2$var$setStyle(document.documentElement, 'overflow', 'hidden'), $49c51c25361d4cd2$var$setStyle(document.body, 'marginTop', `-${scrollY}px`), ()=>{
|
|
165
|
+
window.scrollTo(scrollX, scrollY);
|
|
166
|
+
});
|
|
167
|
+
// Scroll to the top. The negative margin on the body will make this appear the same.
|
|
168
|
+
window.scrollTo(0, 0);
|
|
169
|
+
};
|
|
170
|
+
let removeEvents = (0, $7mMvr$chain)($49c51c25361d4cd2$var$addEvent(document, 'touchstart', onTouchStart, {
|
|
171
|
+
passive: false,
|
|
172
|
+
capture: true
|
|
173
|
+
}), $49c51c25361d4cd2$var$addEvent(document, 'touchmove', onTouchMove, {
|
|
174
|
+
passive: false,
|
|
175
|
+
capture: true
|
|
176
|
+
}), $49c51c25361d4cd2$var$addEvent(document, 'touchend', onTouchEnd, {
|
|
177
|
+
passive: false,
|
|
178
|
+
capture: true
|
|
179
|
+
}), $49c51c25361d4cd2$var$addEvent(document, 'focus', onFocus, true));
|
|
180
|
+
return ()=>{
|
|
181
|
+
// Restore styles and scroll the page back to where it was.
|
|
182
|
+
restoreScrollableStyles === null || restoreScrollableStyles === void 0 ? void 0 : restoreScrollableStyles();
|
|
183
|
+
restoreStyles === null || restoreStyles === void 0 ? void 0 : restoreStyles();
|
|
184
|
+
removeEvents();
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
// Sets a CSS property on an element, and returns a function to revert it to the previous value.
|
|
188
|
+
function $49c51c25361d4cd2$var$setStyle(element, style, value) {
|
|
189
|
+
let cur = element.style[style];
|
|
190
|
+
element.style[style] = value;
|
|
191
|
+
return ()=>{
|
|
192
|
+
element.style[style] = cur;
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
// Adds an event listener to an element, and returns a function to remove it.
|
|
196
|
+
function $49c51c25361d4cd2$var$addEvent(target, event, handler, options) {
|
|
197
|
+
target.addEventListener(event, handler, options);
|
|
198
|
+
return ()=>{
|
|
199
|
+
target.removeEventListener(event, handler, options);
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function $49c51c25361d4cd2$var$scrollIntoView(target) {
|
|
203
|
+
let root = document.scrollingElement || document.documentElement;
|
|
204
|
+
while(target && target !== root){
|
|
205
|
+
// Find the parent scrollable element and adjust the scroll position if the target is not already in view.
|
|
206
|
+
let scrollable = (0, $7mMvr$getScrollParent)(target);
|
|
207
|
+
if (scrollable !== document.documentElement && scrollable !== document.body && scrollable !== target) {
|
|
208
|
+
let scrollableTop = scrollable.getBoundingClientRect().top;
|
|
209
|
+
let targetTop = target.getBoundingClientRect().top;
|
|
210
|
+
if (targetTop > scrollableTop + target.clientHeight) scrollable.scrollTop += targetTop - scrollableTop;
|
|
211
|
+
}
|
|
212
|
+
target = scrollable.parentElement;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function $49c51c25361d4cd2$var$willOpenKeyboard(target) {
|
|
216
|
+
return target instanceof HTMLInputElement && !$49c51c25361d4cd2$var$nonTextInputTypes.has(target.type) || target instanceof HTMLTextAreaElement || target instanceof HTMLElement && target.isContentEditable;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
export {$49c51c25361d4cd2$export$ee0f7cc6afcd1c18 as usePreventScroll};
|
|
221
|
+
//# sourceMappingURL=usePreventScroll.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AASD,aAAa;AACb,MAAM,uCAAiB,OAAO,aAAa,eAAe,OAAO,cAAc;AAE/E,sEAAsE;AACtE,MAAM,0CAAoB,IAAI,IAAI;IAChC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,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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UAAU,WAAW,KAAM;QAChC,0GAA0G;QAC1G,IAAI,aAAa,CAAA,GAAA,sBAAc,EAAE;QACjC,IAAI,eAAe,SAAS,eAAe,IAAI,eAAe,SAAS,IAAI,IAAI,eAAe,QAAQ;YACpG,IAAI,gBAAgB,WAAW,qBAAqB,GAAG,GAAG;YAC1D,IAAI,YAAY,OAAO,qBAAqB,GAAG,GAAG;YAClD,IAAI,YAAY,gBAAgB,OAAO,YAAY,EACjD,WAAW,SAAS,IAAI,YAAY;QAExC;QAEA,SAAS,WAAW,aAAa;IACnC;AACF;AAEA,SAAS,uCAAiB,MAAe;IACvC,OACE,AAAC,kBAAkB,oBAAoB,CAAC,wCAAkB,GAAG,CAAC,OAAO,IAAI,KACzE,kBAAkB,uBACjB,kBAAkB,eAAe,OAAO,iBAAiB;AAE9D","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, useLayoutEffect} from '@react-aria/utils';\n\ninterface PreventScrollOptions {\n /** Whether the scroll lock is disabled. */\n isDisabled?: boolean\n}\n\n// @ts-ignore\nconst visualViewport = typeof document !== 'undefined' && window.visualViewport;\n\n// HTML input types that do not cause the software keyboard to appear.\nconst nonTextInputTypes = new Set([\n 'checkbox',\n 'radio',\n 'range',\n 'color',\n 'file',\n 'image',\n 'button',\n 'submit',\n 'reset'\n]);\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 = {}) {\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 return chain(\n setStyle(document.documentElement, 'paddingRight', `${window.innerWidth - document.documentElement.clientWidth}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.\n// 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.\n// 4. When focusing an input, apply a transform to trick Safari into thinking the input is at the top\n// of the page, which prevents it from scrolling the page. After the input is focused, scroll the element\n// into view ourselves, without scrolling the whole page.\n// 5. Offset the body by the scroll position using a negative margin and scroll to the top. This should appear the\n// same visually, but makes the actual scroll position always zero. This is required to make all of the\n// above work or Safari will still try to scroll the page when focusing an input.\n// 6. As a last resort, handle window scroll events, and scroll back to the top. This can happen when attempting\n// to navigate to an input with the next/previous buttons that's outside a modal.\nfunction preventScrollMobileSafari() {\n let scrollable: Element;\n let restoreScrollableStyles;\n let onTouchStart = (e: TouchEvent) => {\n // Store the nearest scrollable parent element from the element that the user touched.\n scrollable = getScrollParent(e.target as Element, true);\n if (scrollable === document.documentElement && scrollable === document.body) {\n return;\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 if (scrollable instanceof HTMLElement && window.getComputedStyle(scrollable).overscrollBehavior === 'auto') {\n restoreScrollableStyles = setStyle(scrollable, 'overscrollBehavior', 'contain');\n }\n };\n\n let onTouchMove = (e: TouchEvent) => {\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 onTouchEnd = (e: TouchEvent) => {\n let target = e.target as HTMLElement;\n\n // Apply this change if we're not already focused on the target element\n if (willOpenKeyboard(target) && target !== document.activeElement) {\n e.preventDefault();\n setupStyles();\n\n // Apply a transform to trick Safari into thinking the input is at the top of the page\n // so it doesn't try to scroll it into view. When tapping on an input, this needs to\n // be done before the \"focus\" event, so we have to focus the element ourselves.\n target.style.transform = 'translateY(-2000px)';\n target.focus();\n requestAnimationFrame(() => {\n target.style.transform = '';\n });\n }\n\n if (restoreScrollableStyles) {\n restoreScrollableStyles();\n }\n };\n\n let onFocus = (e: FocusEvent) => {\n let target = e.target as HTMLElement;\n if (willOpenKeyboard(target)) {\n setupStyles();\n\n // Transform also needs to be applied in the focus event in cases where focus moves\n // other than tapping on an input directly, e.g. the next/previous buttons in the\n // software keyboard. In these cases, it seems applying the transform in the focus event\n // is good enough, whereas when tapping an input, it must be done before the focus event. 🤷♂️\n target.style.transform = 'translateY(-2000px)';\n requestAnimationFrame(() => {\n target.style.transform = '';\n\n // This will have prevented the browser from scrolling the focused element into view,\n // so we need to do this ourselves in a way that doesn't cause the whole page to scroll.\n if (visualViewport) {\n if (visualViewport.height < window.innerHeight) {\n // If the keyboard is already visible, do this after one additional frame\n // to wait for the transform to be removed.\n requestAnimationFrame(() => {\n scrollIntoView(target);\n });\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 });\n }\n };\n\n let restoreStyles = null;\n let setupStyles = () => {\n if (restoreStyles) {\n return;\n }\n\n let onWindowScroll = () => {\n // Last resort. If the window scrolled, scroll it back to the top.\n // It should always be at the top because the body will have a negative margin (see below).\n window.scrollTo(0, 0);\n };\n\n // Record the original scroll position so we can restore it.\n // Then apply a negative margin to the body to offset it by the scroll position. This will\n // enable us to scroll the window to the top, which is required for the rest of this to work.\n let scrollX = window.pageXOffset;\n let scrollY = window.pageYOffset;\n\n restoreStyles = chain(\n addEvent(window, 'scroll', onWindowScroll),\n setStyle(document.documentElement, 'paddingRight', `${window.innerWidth - document.documentElement.clientWidth}px`),\n setStyle(document.documentElement, 'overflow', 'hidden'),\n setStyle(document.body, 'marginTop', `-${scrollY}px`),\n () => {\n window.scrollTo(scrollX, scrollY);\n }\n );\n\n // Scroll to the top. The negative margin on the body will make this appear the same.\n window.scrollTo(0, 0);\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, 'touchend', onTouchEnd, {passive: false, capture: true}),\n addEvent(document, 'focus', onFocus, true)\n );\n\n return () => {\n // Restore styles and scroll the page back to where it was.\n restoreScrollableStyles?.();\n restoreStyles?.();\n removeEvents();\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: EventTarget,\n event: K,\n handler: (this: Document, ev: GlobalEventHandlersEventMap[K]) => any,\n options?: boolean | AddEventListenerOptions\n) {\n target.addEventListener(event, handler, options);\n return () => {\n target.removeEventListener(event, handler, options);\n };\n}\n\nfunction scrollIntoView(target: Element) {\n let root = document.scrollingElement || document.documentElement;\n while (target && target !== root) {\n // Find the parent scrollable element and adjust the scroll position if the target is not already in view.\n let scrollable = getScrollParent(target);\n if (scrollable !== document.documentElement && scrollable !== document.body && scrollable !== target) {\n let scrollableTop = scrollable.getBoundingClientRect().top;\n let targetTop = target.getBoundingClientRect().top;\n if (targetTop > scrollableTop + target.clientHeight) {\n scrollable.scrollTop += targetTop - scrollableTop;\n }\n }\n\n target = scrollable.parentElement;\n }\n}\n\nfunction willOpenKeyboard(target: Element) {\n return (\n (target instanceof HTMLInputElement && !nonTextInputTypes.has(target.type)) ||\n target instanceof HTMLTextAreaElement ||\n (target instanceof HTMLElement && target.isContentEditable)\n );\n}\n"],"names":[],"version":3,"file":"usePreventScroll.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/overlays",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.22.1",
|
|
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/focus": "^3.
|
|
26
|
-
"@react-aria/i18n": "^3.
|
|
27
|
-
"@react-aria/interactions": "^3.21.
|
|
28
|
-
"@react-aria/ssr": "^3.9.
|
|
29
|
-
"@react-aria/utils": "^3.
|
|
30
|
-
"@react-aria/visually-hidden": "^3.8.
|
|
31
|
-
"@react-stately/overlays": "^3.6.
|
|
32
|
-
"@react-types/button": "^3.9.
|
|
33
|
-
"@react-types/overlays": "^3.8.
|
|
34
|
-
"@react-types/shared": "^3.
|
|
25
|
+
"@react-aria/focus": "^3.17.1",
|
|
26
|
+
"@react-aria/i18n": "^3.11.1",
|
|
27
|
+
"@react-aria/interactions": "^3.21.3",
|
|
28
|
+
"@react-aria/ssr": "^3.9.4",
|
|
29
|
+
"@react-aria/utils": "^3.24.1",
|
|
30
|
+
"@react-aria/visually-hidden": "^3.8.12",
|
|
31
|
+
"@react-stately/overlays": "^3.6.7",
|
|
32
|
+
"@react-types/button": "^3.9.4",
|
|
33
|
+
"@react-types/overlays": "^3.8.7",
|
|
34
|
+
"@react-types/shared": "^3.23.1",
|
|
35
35
|
"@swc/helpers": "^0.5.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "b77d7d594dff4dcfb5359bffbcfd18142b146433"
|
|
45
45
|
}
|
package/src/Overlay.tsx
CHANGED
|
@@ -16,6 +16,7 @@ import React, {ReactNode, useContext, useMemo, useState} from 'react';
|
|
|
16
16
|
import ReactDOM from 'react-dom';
|
|
17
17
|
import {useIsSSR} from '@react-aria/ssr';
|
|
18
18
|
import {useLayoutEffect} from '@react-aria/utils';
|
|
19
|
+
import {useUNSTABLE_PortalContext} from './PortalProvider';
|
|
19
20
|
|
|
20
21
|
export interface OverlayProps {
|
|
21
22
|
/**
|
|
@@ -50,6 +51,11 @@ export function Overlay(props: OverlayProps) {
|
|
|
50
51
|
let [contain, setContain] = useState(false);
|
|
51
52
|
let contextValue = useMemo(() => ({contain, setContain}), [contain, setContain]);
|
|
52
53
|
|
|
54
|
+
let {getContainer} = useUNSTABLE_PortalContext();
|
|
55
|
+
if (!props.portalContainer && getContainer) {
|
|
56
|
+
portalContainer = getContainer();
|
|
57
|
+
}
|
|
58
|
+
|
|
53
59
|
if (!portalContainer) {
|
|
54
60
|
return null;
|
|
55
61
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 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 React, {createContext, ReactNode, useContext} from 'react';
|
|
14
|
+
|
|
15
|
+
export interface PortalProviderProps {
|
|
16
|
+
/* Should return the element where we should portal to. Can clear the context by passing null. */
|
|
17
|
+
getContainer?: () => HTMLElement | null
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const PortalContext = createContext<PortalProviderProps>({});
|
|
21
|
+
|
|
22
|
+
export function UNSTABLE_PortalProvider(props: PortalProviderProps & {children: ReactNode}) {
|
|
23
|
+
let {getContainer} = props;
|
|
24
|
+
let {getContainer: ctxGetContainer} = useUNSTABLE_PortalContext();
|
|
25
|
+
return (
|
|
26
|
+
<PortalContext.Provider value={{getContainer: getContainer === null ? null : getContainer ?? ctxGetContainer}}>
|
|
27
|
+
{props.children}
|
|
28
|
+
</PortalContext.Provider>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function useUNSTABLE_PortalContext() {
|
|
33
|
+
return useContext(PortalContext) ?? {};
|
|
34
|
+
}
|
package/src/calculatePosition.ts
CHANGED
|
@@ -417,15 +417,15 @@ export function calculatePositionInternal(
|
|
|
417
417
|
|
|
418
418
|
// All values are transformed so that 0 is at the top/left of the overlay depending on the orientation
|
|
419
419
|
// Prefer the arrow being in the center of the trigger/overlay anchor element
|
|
420
|
-
let preferredArrowPosition = childOffset[crossAxis] + .5 * childOffset[crossSize] -
|
|
420
|
+
let preferredArrowPosition = childOffset[crossAxis] + .5 * childOffset[crossSize] - position[crossAxis];
|
|
421
421
|
|
|
422
422
|
// Min/Max position limits for the arrow with respect to the overlay
|
|
423
423
|
const arrowMinPosition = arrowSize / 2 + arrowBoundaryOffset;
|
|
424
424
|
const arrowMaxPosition = overlaySize[crossSize] - (arrowSize / 2) - arrowBoundaryOffset;
|
|
425
425
|
|
|
426
426
|
// Min/Max position limits for the arrow with respect to the trigger/overlay anchor element
|
|
427
|
-
const arrowOverlappingChildMinEdge = childOffset[crossAxis] -
|
|
428
|
-
const arrowOverlappingChildMaxEdge = childOffset[crossAxis] + childOffset[crossSize] -
|
|
427
|
+
const arrowOverlappingChildMinEdge = childOffset[crossAxis] - position[crossAxis] + (arrowSize / 2);
|
|
428
|
+
const arrowOverlappingChildMaxEdge = childOffset[crossAxis] + childOffset[crossSize] - position[crossAxis] - (arrowSize / 2);
|
|
429
429
|
|
|
430
430
|
// Clamp the arrow positioning so that it always is within the bounds of the anchor and the overlay
|
|
431
431
|
const arrowPositionOverlappingChild = clamp(preferredArrowPosition, arrowOverlappingChildMinEdge, arrowOverlappingChildMaxEdge);
|
package/src/index.ts
CHANGED
|
@@ -19,6 +19,7 @@ export {ariaHideOutside} from './ariaHideOutside';
|
|
|
19
19
|
export {usePopover} from './usePopover';
|
|
20
20
|
export {useModalOverlay} from './useModalOverlay';
|
|
21
21
|
export {Overlay, useOverlayFocusContain} from './Overlay';
|
|
22
|
+
export {UNSTABLE_PortalProvider, useUNSTABLE_PortalContext} from './PortalProvider';
|
|
22
23
|
|
|
23
24
|
export type {AriaPositionProps, PositionAria} from './useOverlayPosition';
|
|
24
25
|
export type {AriaOverlayProps, OverlayAria} from './useOverlay';
|
package/src/useModalOverlay.ts
CHANGED
|
@@ -11,15 +11,15 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import {ariaHideOutside} from './ariaHideOutside';
|
|
14
|
+
import {AriaOverlayProps, useOverlay} from './useOverlay';
|
|
14
15
|
import {DOMAttributes} from '@react-types/shared';
|
|
15
16
|
import {mergeProps} from '@react-aria/utils';
|
|
16
17
|
import {OverlayTriggerState} from '@react-stately/overlays';
|
|
17
18
|
import {RefObject, useEffect} from 'react';
|
|
18
|
-
import {useOverlay} from './useOverlay';
|
|
19
19
|
import {useOverlayFocusContain} from './Overlay';
|
|
20
20
|
import {usePreventScroll} from './usePreventScroll';
|
|
21
21
|
|
|
22
|
-
export interface AriaModalOverlayProps {
|
|
22
|
+
export interface AriaModalOverlayProps extends Pick<AriaOverlayProps, 'shouldCloseOnInteractOutside'> {
|
|
23
23
|
/**
|
|
24
24
|
* Whether to close the modal when the user interacts outside it.
|
|
25
25
|
* @default false
|
package/src/useOverlay.ts
CHANGED
|
@@ -112,7 +112,7 @@ export function useOverlay(props: AriaOverlayProps, ref: RefObject<Element>): Ov
|
|
|
112
112
|
|
|
113
113
|
// Handle the escape key
|
|
114
114
|
let onKeyDown = (e) => {
|
|
115
|
-
if (e.key === 'Escape' && !isKeyboardDismissDisabled) {
|
|
115
|
+
if (e.key === 'Escape' && !isKeyboardDismissDisabled && !e.nativeEvent.isComposing) {
|
|
116
116
|
e.stopPropagation();
|
|
117
117
|
e.preventDefault();
|
|
118
118
|
onHide();
|
|
@@ -145,8 +145,11 @@ export function useOverlayPosition(props: AriaPositionProps): PositionAria {
|
|
|
145
145
|
|
|
146
146
|
// Always reset the overlay's previous max height if not defined by the user so that we can compensate for
|
|
147
147
|
// RAC collections populating after a second render and properly set a correct max height + positioning when it populates.
|
|
148
|
+
let overlay = (overlayRef.current as HTMLElement);
|
|
148
149
|
if (!maxHeight && overlayRef.current) {
|
|
149
|
-
|
|
150
|
+
overlay.style.top = '0px';
|
|
151
|
+
overlay.style.bottom = '';
|
|
152
|
+
overlay.style.maxHeight = (window.visualViewport?.height ?? window.innerHeight) + 'px';
|
|
150
153
|
}
|
|
151
154
|
|
|
152
155
|
let position = calculatePosition({
|
|
@@ -166,8 +169,10 @@ export function useOverlayPosition(props: AriaPositionProps): PositionAria {
|
|
|
166
169
|
|
|
167
170
|
// Modify overlay styles directly so positioning happens immediately without the need of a second render
|
|
168
171
|
// This is so we don't have to delay autoFocus scrolling or delay applying preventScroll for popovers
|
|
169
|
-
|
|
170
|
-
|
|
172
|
+
overlay.style.top = '';
|
|
173
|
+
overlay.style.bottom = '';
|
|
174
|
+
Object.keys(position.position).forEach(key => overlay.style[key] = position.position[key] + 'px');
|
|
175
|
+
overlay.style.maxHeight = position.maxHeight != null ? position.maxHeight + 'px' : undefined;
|
|
171
176
|
|
|
172
177
|
// Trigger a set state for a second render anyway for arrow positioning
|
|
173
178
|
setPosition(position);
|