@react-aria/overlays 3.7.5 → 3.8.2
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 +305 -294
- package/dist/main.js.map +1 -1
- package/dist/module.js +299 -288
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +2 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +10 -9
- package/src/DismissButton.tsx +8 -3
- package/src/useOverlay.ts +1 -0
- package/src/usePreventScroll.ts +24 -9
package/src/usePreventScroll.ts
CHANGED
|
@@ -126,7 +126,9 @@ function preventScrollMobileSafari() {
|
|
|
126
126
|
|
|
127
127
|
let onTouchEnd = (e: TouchEvent) => {
|
|
128
128
|
let target = e.target as HTMLElement;
|
|
129
|
-
|
|
129
|
+
|
|
130
|
+
// Apply this change if we're not already focused on the target element
|
|
131
|
+
if (willOpenKeyboard(target) && target !== document.activeElement) {
|
|
130
132
|
e.preventDefault();
|
|
131
133
|
|
|
132
134
|
// Apply a transform to trick Safari into thinking the input is at the top of the page
|
|
@@ -142,7 +144,7 @@ function preventScrollMobileSafari() {
|
|
|
142
144
|
|
|
143
145
|
let onFocus = (e: FocusEvent) => {
|
|
144
146
|
let target = e.target as HTMLElement;
|
|
145
|
-
if (
|
|
147
|
+
if (willOpenKeyboard(target)) {
|
|
146
148
|
// Transform also needs to be applied in the focus event in cases where focus moves
|
|
147
149
|
// other than tapping on an input directly, e.g. the next/previous buttons in the
|
|
148
150
|
// software keyboard. In these cases, it seems applying the transform in the focus event
|
|
@@ -229,13 +231,26 @@ function addEvent<K extends keyof GlobalEventHandlersEventMap>(
|
|
|
229
231
|
}
|
|
230
232
|
|
|
231
233
|
function scrollIntoView(target: Element) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
let
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
234
|
+
let root = document.scrollingElement || document.documentElement;
|
|
235
|
+
while (target && target !== root) {
|
|
236
|
+
// Find the parent scrollable element and adjust the scroll position if the target is not already in view.
|
|
237
|
+
let scrollable = getScrollParent(target);
|
|
238
|
+
if (scrollable !== document.documentElement && scrollable !== document.body && scrollable !== target) {
|
|
239
|
+
let scrollableTop = scrollable.getBoundingClientRect().top;
|
|
240
|
+
let targetTop = target.getBoundingClientRect().top;
|
|
241
|
+
if (targetTop > scrollableTop + target.clientHeight) {
|
|
242
|
+
scrollable.scrollTop += targetTop - scrollableTop;
|
|
243
|
+
}
|
|
239
244
|
}
|
|
245
|
+
|
|
246
|
+
target = scrollable.parentElement;
|
|
240
247
|
}
|
|
241
248
|
}
|
|
249
|
+
|
|
250
|
+
function willOpenKeyboard(target: Element) {
|
|
251
|
+
return (
|
|
252
|
+
(target instanceof HTMLInputElement && !nonTextInputTypes.has(target.type)) ||
|
|
253
|
+
target instanceof HTMLTextAreaElement ||
|
|
254
|
+
(target instanceof HTMLElement && target.isContentEditable)
|
|
255
|
+
);
|
|
256
|
+
}
|