@react-aria/overlays 3.19.0 → 3.21.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.
- package/dist/import.mjs +135 -55
- package/dist/main.js +133 -53
- package/dist/main.js.map +1 -1
- package/dist/module.js +135 -55
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/DismissButton.tsx +3 -2
- package/src/calculatePosition.ts +85 -24
- package/src/useOverlay.ts +1 -1
- package/src/useOverlayPosition.ts +31 -4
- package/src/usePopover.ts +13 -4
- package/src/usePreventScroll.ts +56 -41
package/dist/import.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import $k7QOs$react, {useState as $k7QOs$useState,
|
|
2
|
-
import {useLayoutEffect as $k7QOs$useLayoutEffect, useResizeObserver as $k7QOs$useResizeObserver, clamp as $k7QOs$clamp, useId as $k7QOs$useId, isIOS as $k7QOs$isIOS, chain as $k7QOs$chain, getScrollParent as $k7QOs$getScrollParent, useLabels as $k7QOs$useLabels, mergeProps as $k7QOs$mergeProps} from "@react-aria/utils";
|
|
1
|
+
import $k7QOs$react, {useState as $k7QOs$useState, useRef as $k7QOs$useRef, useEffect as $k7QOs$useEffect, useCallback as $k7QOs$useCallback, useContext as $k7QOs$useContext, useMemo as $k7QOs$useMemo} from "react";
|
|
2
|
+
import {useLayoutEffect as $k7QOs$useLayoutEffect, useResizeObserver as $k7QOs$useResizeObserver, isWebKit as $k7QOs$isWebKit, clamp as $k7QOs$clamp, useId as $k7QOs$useId, isIOS as $k7QOs$isIOS, chain as $k7QOs$chain, getScrollParent as $k7QOs$getScrollParent, useLabels as $k7QOs$useLabels, mergeProps as $k7QOs$mergeProps} from "@react-aria/utils";
|
|
3
3
|
import {useLocale as $k7QOs$useLocale, useLocalizedStringFormatter as $k7QOs$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
4
4
|
import {isElementInChildOfActiveScope as $k7QOs$isElementInChildOfActiveScope, FocusScope as $k7QOs$FocusScope} from "@react-aria/focus";
|
|
5
5
|
import {useInteractOutside as $k7QOs$useInteractOutside, useFocusWithin as $k7QOs$useFocusWithin, ClearPressResponder as $k7QOs$ClearPressResponder} from "@react-aria/interactions";
|
|
@@ -72,6 +72,7 @@ let $edcf132a9284368a$var$visualViewport = typeof document !== "undefined" && wi
|
|
|
72
72
|
function $edcf132a9284368a$var$getContainerDimensions(containerNode) {
|
|
73
73
|
let width = 0, height = 0, totalWidth = 0, totalHeight = 0, top = 0, left = 0;
|
|
74
74
|
let scroll = {};
|
|
75
|
+
let isPinchZoomedIn = ($edcf132a9284368a$var$visualViewport === null || $edcf132a9284368a$var$visualViewport === void 0 ? void 0 : $edcf132a9284368a$var$visualViewport.scale) > 1;
|
|
75
76
|
if (containerNode.tagName === "BODY") {
|
|
76
77
|
let documentElement = document.documentElement;
|
|
77
78
|
totalWidth = documentElement.clientWidth;
|
|
@@ -82,6 +83,13 @@ function $edcf132a9284368a$var$getContainerDimensions(containerNode) {
|
|
|
82
83
|
height = (_visualViewport_height = $edcf132a9284368a$var$visualViewport === null || $edcf132a9284368a$var$visualViewport === void 0 ? void 0 : $edcf132a9284368a$var$visualViewport.height) !== null && _visualViewport_height !== void 0 ? _visualViewport_height : totalHeight;
|
|
83
84
|
scroll.top = documentElement.scrollTop || containerNode.scrollTop;
|
|
84
85
|
scroll.left = documentElement.scrollLeft || containerNode.scrollLeft;
|
|
86
|
+
// The goal of the below is to get a top/left value that represents the top/left of the visual viewport with
|
|
87
|
+
// respect to the layout viewport origin. This combined with the scrollTop/scrollLeft will allow us to calculate
|
|
88
|
+
// coordinates/values with respect to the visual viewport or with respect to the layout viewport.
|
|
89
|
+
if ($edcf132a9284368a$var$visualViewport) {
|
|
90
|
+
top = $edcf132a9284368a$var$visualViewport.offsetTop;
|
|
91
|
+
left = $edcf132a9284368a$var$visualViewport.offsetLeft;
|
|
92
|
+
}
|
|
85
93
|
} else {
|
|
86
94
|
({ width: width, height: height, top: top, left: left } = $edcf132a9284368a$var$getOffset(containerNode));
|
|
87
95
|
scroll.top = containerNode.scrollTop;
|
|
@@ -89,6 +97,16 @@ function $edcf132a9284368a$var$getContainerDimensions(containerNode) {
|
|
|
89
97
|
totalWidth = width;
|
|
90
98
|
totalHeight = height;
|
|
91
99
|
}
|
|
100
|
+
if ((0, $k7QOs$isWebKit)() && (containerNode.tagName === "BODY" || containerNode.tagName === "HTML") && isPinchZoomedIn) {
|
|
101
|
+
// Safari will report a non-zero scrollTop/Left for the non-scrolling body/HTML element when pinch zoomed in unlike other browsers.
|
|
102
|
+
// Set to zero for parity calculations so we get consistent positioning of overlays across all browsers.
|
|
103
|
+
// Also switch to visualViewport.pageTop/pageLeft so that we still accomodate for scroll positioning for body/HTML elements that are actually scrollable
|
|
104
|
+
// before pinch zoom happens
|
|
105
|
+
scroll.top = 0;
|
|
106
|
+
scroll.left = 0;
|
|
107
|
+
top = $edcf132a9284368a$var$visualViewport.pageTop;
|
|
108
|
+
left = $edcf132a9284368a$var$visualViewport.pageLeft;
|
|
109
|
+
}
|
|
92
110
|
return {
|
|
93
111
|
width: width,
|
|
94
112
|
height: height,
|
|
@@ -107,6 +125,7 @@ function $edcf132a9284368a$var$getScroll(node) {
|
|
|
107
125
|
height: node.scrollHeight
|
|
108
126
|
};
|
|
109
127
|
}
|
|
128
|
+
// Determines the amount of space required when moving the overlay to ensure it remains in the boundary
|
|
110
129
|
function $edcf132a9284368a$var$getDelta(axis, offset, size, // The dimensions of the boundary element that the popover is
|
|
111
130
|
// positioned within (most of the time this is the <body>).
|
|
112
131
|
boundaryDimensions, // The dimensions of the containing block element that the popover is
|
|
@@ -114,13 +133,20 @@ boundaryDimensions, // The dimensions of the containing block element that the p
|
|
|
114
133
|
// Usually this is the same as the boundary element, but if the popover
|
|
115
134
|
// is portaled somewhere other than the body and has an ancestor with
|
|
116
135
|
// position: relative/absolute, it will be different.
|
|
117
|
-
containerDimensions, padding) {
|
|
136
|
+
containerDimensions, padding, containerOffsetWithBoundary) {
|
|
118
137
|
let containerScroll = containerDimensions.scroll[axis];
|
|
119
|
-
|
|
120
|
-
let
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
138
|
+
// The height/width of the boundary. Matches the axis along which we are adjusting the overlay position
|
|
139
|
+
let boundarySize = boundaryDimensions[$edcf132a9284368a$var$AXIS_SIZE[axis]];
|
|
140
|
+
// Calculate the edges of the boundary (accomodating for the boundary padding) and the edges of the overlay.
|
|
141
|
+
// Note that these values are with respect to the visual viewport (aka 0,0 is the top left of the viewport)
|
|
142
|
+
let boundaryStartEdge = boundaryDimensions.scroll[$edcf132a9284368a$var$AXIS[axis]] + padding;
|
|
143
|
+
let boundaryEndEdge = boundarySize + boundaryDimensions.scroll[$edcf132a9284368a$var$AXIS[axis]] - padding;
|
|
144
|
+
let startEdgeOffset = offset - containerScroll + containerOffsetWithBoundary[axis] - boundaryDimensions[$edcf132a9284368a$var$AXIS[axis]];
|
|
145
|
+
let endEdgeOffset = offset - containerScroll + size + containerOffsetWithBoundary[axis] - boundaryDimensions[$edcf132a9284368a$var$AXIS[axis]];
|
|
146
|
+
// If any of the overlay edges falls outside of the boundary, shift the overlay the required amount to align one of the overlay's
|
|
147
|
+
// edges with the closest boundary edge.
|
|
148
|
+
if (startEdgeOffset < boundaryStartEdge) return boundaryStartEdge - startEdgeOffset;
|
|
149
|
+
else if (endEdgeOffset > boundaryEndEdge) return Math.max(boundaryEndEdge - endEdgeOffset, boundaryStartEdge - startEdgeOffset);
|
|
124
150
|
else return 0;
|
|
125
151
|
}
|
|
126
152
|
function $edcf132a9284368a$var$getMargins(node) {
|
|
@@ -164,7 +190,6 @@ function $edcf132a9284368a$var$computePosition(childOffset, boundaryDimensions,
|
|
|
164
190
|
/* else {
|
|
165
191
|
the overlay top should match the button top
|
|
166
192
|
} */
|
|
167
|
-
// add the crossOffset from props
|
|
168
193
|
position[crossAxis] += crossOffset;
|
|
169
194
|
// overlay top overlapping arrow with button bottom
|
|
170
195
|
const minPosition = childOffset[crossAxis] - overlaySize[crossSize] + arrowSize + arrowBoundaryOffset;
|
|
@@ -182,14 +207,20 @@ function $edcf132a9284368a$var$computePosition(childOffset, boundaryDimensions,
|
|
|
182
207
|
} else position[axis] = Math.floor(childOffset[axis] + childOffset[size] + offset);
|
|
183
208
|
return position;
|
|
184
209
|
}
|
|
185
|
-
function $edcf132a9284368a$var$getMaxHeight(position, boundaryDimensions, containerOffsetWithBoundary,
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
210
|
+
function $edcf132a9284368a$var$getMaxHeight(position, boundaryDimensions, containerOffsetWithBoundary, isContainerPositioned, margins, padding, overlayHeight, heightGrowthDirection) {
|
|
211
|
+
const containerHeight = isContainerPositioned ? containerOffsetWithBoundary.height : boundaryDimensions[$edcf132a9284368a$var$TOTAL_SIZE.height];
|
|
212
|
+
// For cases where position is set via "bottom" instead of "top", we need to calculate the true overlay top with respect to the boundary. Reverse calculate this with the same method
|
|
213
|
+
// used in computePosition.
|
|
214
|
+
let overlayTop = position.top != null ? containerOffsetWithBoundary.top + position.top : containerOffsetWithBoundary.top + (containerHeight - position.bottom - overlayHeight);
|
|
215
|
+
let maxHeight = heightGrowthDirection !== "top" ? // We want the distance between the top of the overlay to the bottom of the boundary
|
|
216
|
+
Math.max(0, boundaryDimensions.height + boundaryDimensions.top + boundaryDimensions.scroll.top // this is the bottom of the boundary
|
|
217
|
+
- overlayTop // this is the top of the overlay
|
|
218
|
+
- (margins.top + margins.bottom + padding // save additional space for margin and padding
|
|
219
|
+
)) : Math.max(0, overlayTop + overlayHeight // this is the bottom of the overlay
|
|
190
220
|
- (boundaryDimensions.top + boundaryDimensions.scroll.top // this is the top of the boundary
|
|
191
221
|
) - (margins.top + margins.bottom + padding // save additional space for margin and padding
|
|
192
222
|
));
|
|
223
|
+
return Math.min(boundaryDimensions.height - padding * 2, maxHeight);
|
|
193
224
|
}
|
|
194
225
|
function $edcf132a9284368a$var$getAvailableSpace(boundaryDimensions, containerOffsetWithBoundary, childOffset, margins, padding, placementInfo) {
|
|
195
226
|
let { placement: placement, axis: axis, size: size } = placementInfo;
|
|
@@ -214,13 +245,22 @@ function $edcf132a9284368a$export$6839422d1f33cee9(placementInput, childOffset,
|
|
|
214
245
|
normalizedOffset = offset;
|
|
215
246
|
}
|
|
216
247
|
}
|
|
217
|
-
|
|
248
|
+
// Determine the direction the height of the overlay can grow so that we can choose how to calculate the max height
|
|
249
|
+
let heightGrowthDirection = "bottom";
|
|
250
|
+
if (placementInfo.axis === "top") {
|
|
251
|
+
if (placementInfo.placement === "top") heightGrowthDirection = "top";
|
|
252
|
+
else if (placementInfo.placement === "bottom") heightGrowthDirection = "bottom";
|
|
253
|
+
} else if (placementInfo.crossAxis === "top") {
|
|
254
|
+
if (placementInfo.crossPlacement === "top") heightGrowthDirection = "bottom";
|
|
255
|
+
else if (placementInfo.crossPlacement === "bottom") heightGrowthDirection = "top";
|
|
256
|
+
}
|
|
257
|
+
let delta = $edcf132a9284368a$var$getDelta(crossAxis, position[crossAxis], overlaySize[crossSize], boundaryDimensions, containerDimensions, padding, containerOffsetWithBoundary);
|
|
218
258
|
position[crossAxis] += delta;
|
|
219
|
-
let maxHeight = $edcf132a9284368a$var$getMaxHeight(position, boundaryDimensions, containerOffsetWithBoundary,
|
|
259
|
+
let maxHeight = $edcf132a9284368a$var$getMaxHeight(position, boundaryDimensions, containerOffsetWithBoundary, isContainerPositioned, margins, padding, overlaySize.height, heightGrowthDirection);
|
|
220
260
|
if (userSetMaxHeight && userSetMaxHeight < maxHeight) maxHeight = userSetMaxHeight;
|
|
221
261
|
overlaySize.height = Math.min(overlaySize.height, maxHeight);
|
|
222
262
|
position = $edcf132a9284368a$var$computePosition(childOffset, boundaryDimensions, overlaySize, placementInfo, normalizedOffset, crossOffset, containerOffsetWithBoundary, isContainerPositioned, arrowSize, arrowBoundaryOffset);
|
|
223
|
-
delta = $edcf132a9284368a$var$getDelta(crossAxis, position[crossAxis], overlaySize[crossSize], boundaryDimensions, containerDimensions, padding);
|
|
263
|
+
delta = $edcf132a9284368a$var$getDelta(crossAxis, position[crossAxis], overlaySize[crossSize], boundaryDimensions, containerDimensions, padding, containerOffsetWithBoundary);
|
|
224
264
|
position[crossAxis] += delta;
|
|
225
265
|
let arrowPosition = {};
|
|
226
266
|
// All values are transformed so that 0 is at the top/left of the overlay depending on the orientation
|
|
@@ -262,7 +302,14 @@ function $edcf132a9284368a$export$b3ceb0cbf1056d98(opts) {
|
|
|
262
302
|
let scrollSize = $edcf132a9284368a$var$getScroll(scrollNode);
|
|
263
303
|
let boundaryDimensions = $edcf132a9284368a$var$getContainerDimensions(boundaryElement);
|
|
264
304
|
let containerDimensions = $edcf132a9284368a$var$getContainerDimensions(container);
|
|
305
|
+
// If the container is the HTML element wrapping the body element, the retrieved scrollTop/scrollLeft will be equal to the
|
|
306
|
+
// body element's scroll. Set the container's scroll values to 0 since the overlay's edge position value in getDelta don't then need to be further offset
|
|
307
|
+
// by the container scroll since they are essentially the same containing element and thus in the same coordinate system
|
|
265
308
|
let containerOffsetWithBoundary = boundaryElement.tagName === "BODY" ? $edcf132a9284368a$var$getOffset(container) : $edcf132a9284368a$var$getPosition(container, boundaryElement);
|
|
309
|
+
if (container.tagName === "HTML" && boundaryElement.tagName === "BODY") {
|
|
310
|
+
containerDimensions.scroll.top = 0;
|
|
311
|
+
containerDimensions.scroll.left = 0;
|
|
312
|
+
}
|
|
266
313
|
return $edcf132a9284368a$export$6839422d1f33cee9(placement, childOffset, overlaySize, scrollSize, margins, padding, shouldFlip, boundaryDimensions, containerDimensions, containerOffsetWithBoundary, offset, crossOffset, isContainerPositioned, maxHeight, arrowSize, arrowBoundaryOffset);
|
|
267
314
|
}
|
|
268
315
|
function $edcf132a9284368a$var$getOffset(node) {
|
|
@@ -398,8 +445,21 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
398
445
|
arrowBoundaryOffset,
|
|
399
446
|
arrowSize
|
|
400
447
|
];
|
|
448
|
+
// Note, the position freezing breaks if body sizes itself dynamicly with the visual viewport but that might
|
|
449
|
+
// just be a non-realistic use case
|
|
450
|
+
// Upon opening a overlay, record the current visual viewport scale so we can freeze the overlay styles
|
|
451
|
+
let lastScale = (0, $k7QOs$useRef)($2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.scale);
|
|
452
|
+
(0, $k7QOs$useEffect)(()=>{
|
|
453
|
+
if (isOpen) lastScale.current = $2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.scale;
|
|
454
|
+
}, [
|
|
455
|
+
isOpen
|
|
456
|
+
]);
|
|
401
457
|
let updatePosition = (0, $k7QOs$useCallback)(()=>{
|
|
402
458
|
if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !scrollRef.current || !boundaryElement) return;
|
|
459
|
+
if (($2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.scale) !== lastScale.current) return;
|
|
460
|
+
// Always reset the overlay's previous max height if not defined by the user so that we can compensate for
|
|
461
|
+
// RAC collections populating after a second render and properly set a correct max height + positioning when it populates.
|
|
462
|
+
if (!maxHeight && overlayRef.current) overlayRef.current.style.maxHeight = "none";
|
|
403
463
|
let position = (0, $edcf132a9284368a$export$b3ceb0cbf1056d98)({
|
|
404
464
|
placement: $2a41e45df1593e64$var$translateRTL(placement, direction),
|
|
405
465
|
overlayNode: overlayRef.current,
|
|
@@ -445,11 +505,16 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
445
505
|
}, 500);
|
|
446
506
|
updatePosition();
|
|
447
507
|
};
|
|
508
|
+
// Only reposition the overlay if a scroll event happens immediately as a result of resize (aka the virtual keyboard has appears)
|
|
509
|
+
// We don't want to reposition the overlay if the user has pinch zoomed in and is scrolling the viewport around.
|
|
510
|
+
let onScroll = ()=>{
|
|
511
|
+
if (isResizing.current) onResize();
|
|
512
|
+
};
|
|
448
513
|
$2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.addEventListener("resize", onResize);
|
|
449
|
-
$2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.addEventListener("scroll",
|
|
514
|
+
$2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.addEventListener("scroll", onScroll);
|
|
450
515
|
return ()=>{
|
|
451
516
|
$2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.removeEventListener("resize", onResize);
|
|
452
|
-
$2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.removeEventListener("scroll",
|
|
517
|
+
$2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.removeEventListener("scroll", onScroll);
|
|
453
518
|
};
|
|
454
519
|
}, [
|
|
455
520
|
updatePosition
|
|
@@ -531,7 +596,7 @@ function $a11501f3d1d39e6c$export$ea8f71083e90600f(props, ref) {
|
|
|
531
596
|
isOpen,
|
|
532
597
|
ref
|
|
533
598
|
]);
|
|
534
|
-
// Only hide the overlay when it is the topmost visible overlay in the stack
|
|
599
|
+
// Only hide the overlay when it is the topmost visible overlay in the stack
|
|
535
600
|
let onHide = ()=>{
|
|
536
601
|
if ($a11501f3d1d39e6c$var$visibleOverlays[$a11501f3d1d39e6c$var$visibleOverlays.length - 1] === ref && onClose) onClose();
|
|
537
602
|
};
|
|
@@ -706,8 +771,9 @@ function $49c51c25361d4cd2$var$preventScrollStandard() {
|
|
|
706
771
|
//
|
|
707
772
|
// 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling
|
|
708
773
|
// on the window.
|
|
709
|
-
// 2.
|
|
710
|
-
// top or bottom.
|
|
774
|
+
// 2. Set `overscroll-behavior: contain` on nested scrollable regions so they do not scroll the page when at
|
|
775
|
+
// the top or bottom. Work around a bug where this does not work when the element does not actually overflow
|
|
776
|
+
// by preventing default in a `touchmove` event.
|
|
711
777
|
// 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.
|
|
712
778
|
// 4. When focusing an input, apply a transform to trick Safari into thinking the input is at the top
|
|
713
779
|
// of the page, which prevents it from scrolling the page. After the input is focused, scroll the element
|
|
@@ -719,12 +785,15 @@ function $49c51c25361d4cd2$var$preventScrollStandard() {
|
|
|
719
785
|
// to navigate to an input with the next/previous buttons that's outside a modal.
|
|
720
786
|
function $49c51c25361d4cd2$var$preventScrollMobileSafari() {
|
|
721
787
|
let scrollable;
|
|
722
|
-
let
|
|
788
|
+
let restoreScrollableStyles;
|
|
723
789
|
let onTouchStart = (e)=>{
|
|
724
790
|
// Store the nearest scrollable parent element from the element that the user touched.
|
|
725
|
-
scrollable = (0, $k7QOs$getScrollParent)(e.target);
|
|
791
|
+
scrollable = (0, $k7QOs$getScrollParent)(e.target, true);
|
|
726
792
|
if (scrollable === document.documentElement && scrollable === document.body) return;
|
|
727
|
-
|
|
793
|
+
// Prevent scrolling up when at the top and scrolling down when at the bottom
|
|
794
|
+
// of a nested scrollable area, otherwise mobile Safari will start scrolling
|
|
795
|
+
// the window instead.
|
|
796
|
+
if (scrollable instanceof HTMLElement && window.getComputedStyle(scrollable).overscrollBehavior === "auto") restoreScrollableStyles = $49c51c25361d4cd2$var$setStyle(scrollable, "overscrollBehavior", "contain");
|
|
728
797
|
};
|
|
729
798
|
let onTouchMove = (e)=>{
|
|
730
799
|
// Prevent scrolling the window.
|
|
@@ -732,22 +801,20 @@ function $49c51c25361d4cd2$var$preventScrollMobileSafari() {
|
|
|
732
801
|
e.preventDefault();
|
|
733
802
|
return;
|
|
734
803
|
}
|
|
735
|
-
//
|
|
736
|
-
//
|
|
737
|
-
// the
|
|
738
|
-
//
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
if (bottom === 0) return;
|
|
743
|
-
if (scrollTop <= 0 && y > lastY || scrollTop >= bottom && y < lastY) e.preventDefault();
|
|
744
|
-
lastY = y;
|
|
804
|
+
// overscroll-behavior should prevent scroll chaining, but currently does not
|
|
805
|
+
// if the element doesn't actually overflow. https://bugs.webkit.org/show_bug.cgi?id=243452
|
|
806
|
+
// This checks that both the width and height do not overflow, otherwise we might
|
|
807
|
+
// block horizontal scrolling too. In that case, adding `touch-action: pan-x` to
|
|
808
|
+
// the element will prevent vertical page scrolling. We can't add that automatically
|
|
809
|
+
// because it must be set before the touchstart event.
|
|
810
|
+
if (scrollable.scrollHeight === scrollable.clientHeight && scrollable.scrollWidth === scrollable.clientWidth) e.preventDefault();
|
|
745
811
|
};
|
|
746
812
|
let onTouchEnd = (e)=>{
|
|
747
813
|
let target = e.target;
|
|
748
814
|
// Apply this change if we're not already focused on the target element
|
|
749
815
|
if ($49c51c25361d4cd2$var$willOpenKeyboard(target) && target !== document.activeElement) {
|
|
750
816
|
e.preventDefault();
|
|
817
|
+
setupStyles();
|
|
751
818
|
// Apply a transform to trick Safari into thinking the input is at the top of the page
|
|
752
819
|
// so it doesn't try to scroll it into view. When tapping on an input, this needs to
|
|
753
820
|
// be done before the "focus" event, so we have to focus the element ourselves.
|
|
@@ -757,10 +824,12 @@ function $49c51c25361d4cd2$var$preventScrollMobileSafari() {
|
|
|
757
824
|
target.style.transform = "";
|
|
758
825
|
});
|
|
759
826
|
}
|
|
827
|
+
if (restoreScrollableStyles) restoreScrollableStyles();
|
|
760
828
|
};
|
|
761
829
|
let onFocus = (e)=>{
|
|
762
830
|
let target = e.target;
|
|
763
831
|
if ($49c51c25361d4cd2$var$willOpenKeyboard(target)) {
|
|
832
|
+
setupStyles();
|
|
764
833
|
// Transform also needs to be applied in the focus event in cases where focus moves
|
|
765
834
|
// other than tapping on an input directly, e.g. the next/previous buttons in the
|
|
766
835
|
// software keyboard. In these cases, it seems applying the transform in the focus event
|
|
@@ -785,19 +854,25 @@ function $49c51c25361d4cd2$var$preventScrollMobileSafari() {
|
|
|
785
854
|
});
|
|
786
855
|
}
|
|
787
856
|
};
|
|
788
|
-
let
|
|
789
|
-
|
|
790
|
-
|
|
857
|
+
let restoreStyles = null;
|
|
858
|
+
let setupStyles = ()=>{
|
|
859
|
+
if (restoreStyles) return;
|
|
860
|
+
let onWindowScroll = ()=>{
|
|
861
|
+
// Last resort. If the window scrolled, scroll it back to the top.
|
|
862
|
+
// It should always be at the top because the body will have a negative margin (see below).
|
|
863
|
+
window.scrollTo(0, 0);
|
|
864
|
+
};
|
|
865
|
+
// Record the original scroll position so we can restore it.
|
|
866
|
+
// Then apply a negative margin to the body to offset it by the scroll position. This will
|
|
867
|
+
// enable us to scroll the window to the top, which is required for the rest of this to work.
|
|
868
|
+
let scrollX = window.pageXOffset;
|
|
869
|
+
let scrollY = window.pageYOffset;
|
|
870
|
+
restoreStyles = (0, $k7QOs$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`), ()=>{
|
|
871
|
+
window.scrollTo(scrollX, scrollY);
|
|
872
|
+
});
|
|
873
|
+
// Scroll to the top. The negative margin on the body will make this appear the same.
|
|
791
874
|
window.scrollTo(0, 0);
|
|
792
875
|
};
|
|
793
|
-
// Record the original scroll position so we can restore it.
|
|
794
|
-
// Then apply a negative margin to the body to offset it by the scroll position. This will
|
|
795
|
-
// enable us to scroll the window to the top, which is required for the rest of this to work.
|
|
796
|
-
let scrollX = window.pageXOffset;
|
|
797
|
-
let scrollY = window.pageYOffset;
|
|
798
|
-
let restoreStyles = (0, $k7QOs$chain)($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`));
|
|
799
|
-
// Scroll to the top. The negative margin on the body will make this appear the same.
|
|
800
|
-
window.scrollTo(0, 0);
|
|
801
876
|
let removeEvents = (0, $k7QOs$chain)($49c51c25361d4cd2$var$addEvent(document, "touchstart", onTouchStart, {
|
|
802
877
|
passive: false,
|
|
803
878
|
capture: true
|
|
@@ -807,12 +882,12 @@ function $49c51c25361d4cd2$var$preventScrollMobileSafari() {
|
|
|
807
882
|
}), $49c51c25361d4cd2$var$addEvent(document, "touchend", onTouchEnd, {
|
|
808
883
|
passive: false,
|
|
809
884
|
capture: true
|
|
810
|
-
}), $49c51c25361d4cd2$var$addEvent(document, "focus", onFocus, true)
|
|
885
|
+
}), $49c51c25361d4cd2$var$addEvent(document, "focus", onFocus, true));
|
|
811
886
|
return ()=>{
|
|
812
887
|
// Restore styles and scroll the page back to where it was.
|
|
813
|
-
|
|
888
|
+
restoreScrollableStyles === null || restoreScrollableStyles === void 0 ? void 0 : restoreScrollableStyles();
|
|
889
|
+
restoreStyles === null || restoreStyles === void 0 ? void 0 : restoreStyles();
|
|
814
890
|
removeEvents();
|
|
815
|
-
window.scrollTo(scrollX, scrollY);
|
|
816
891
|
};
|
|
817
892
|
}
|
|
818
893
|
// Sets a CSS property on an element, and returns a function to revert it to the previous value.
|
|
@@ -1202,7 +1277,7 @@ $a2f21f5f14f60553$exports = {
|
|
|
1202
1277
|
|
|
1203
1278
|
function $86ea4cb521eb2e37$export$2317d149ed6f78c4(props) {
|
|
1204
1279
|
let { onDismiss: onDismiss, ...otherProps } = props;
|
|
1205
|
-
let stringFormatter = (0, $k7QOs$useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($a2f21f5f14f60553$exports))));
|
|
1280
|
+
let stringFormatter = (0, $k7QOs$useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($a2f21f5f14f60553$exports))), "@react-aria/overlays");
|
|
1206
1281
|
let labels = (0, $k7QOs$useLabels)(otherProps, stringFormatter.format("dismiss"));
|
|
1207
1282
|
let onClick = ()=>{
|
|
1208
1283
|
if (onDismiss) onDismiss();
|
|
@@ -1210,7 +1285,11 @@ function $86ea4cb521eb2e37$export$2317d149ed6f78c4(props) {
|
|
|
1210
1285
|
return /*#__PURE__*/ (0, $k7QOs$react).createElement((0, $k7QOs$VisuallyHidden), null, /*#__PURE__*/ (0, $k7QOs$react).createElement("button", {
|
|
1211
1286
|
...labels,
|
|
1212
1287
|
tabIndex: -1,
|
|
1213
|
-
onClick: onClick
|
|
1288
|
+
onClick: onClick,
|
|
1289
|
+
style: {
|
|
1290
|
+
width: 1,
|
|
1291
|
+
height: 1
|
|
1292
|
+
}
|
|
1214
1293
|
}));
|
|
1215
1294
|
}
|
|
1216
1295
|
|
|
@@ -1345,23 +1424,24 @@ function $5e3802645cc19319$export$1c3ebcada18427bf(targets, root = document.body
|
|
|
1345
1424
|
|
|
1346
1425
|
|
|
1347
1426
|
function $f2f8a6077418541e$export$542a6fd13ac93354(props, state) {
|
|
1348
|
-
let { triggerRef: triggerRef, popoverRef: popoverRef, isNonModal: isNonModal, isKeyboardDismissDisabled: isKeyboardDismissDisabled, ...otherProps } = props;
|
|
1427
|
+
let { triggerRef: triggerRef, popoverRef: popoverRef, isNonModal: isNonModal, isKeyboardDismissDisabled: isKeyboardDismissDisabled, shouldCloseOnInteractOutside: shouldCloseOnInteractOutside, ...otherProps } = props;
|
|
1349
1428
|
let { overlayProps: overlayProps, underlayProps: underlayProps } = (0, $a11501f3d1d39e6c$export$ea8f71083e90600f)({
|
|
1350
1429
|
isOpen: state.isOpen,
|
|
1351
1430
|
onClose: state.close,
|
|
1352
1431
|
shouldCloseOnBlur: true,
|
|
1353
1432
|
isDismissable: !isNonModal,
|
|
1354
|
-
isKeyboardDismissDisabled: isKeyboardDismissDisabled
|
|
1433
|
+
isKeyboardDismissDisabled: isKeyboardDismissDisabled,
|
|
1434
|
+
shouldCloseOnInteractOutside: shouldCloseOnInteractOutside
|
|
1355
1435
|
}, popoverRef);
|
|
1356
1436
|
let { overlayProps: positionProps, arrowProps: arrowProps, placement: placement } = (0, $2a41e45df1593e64$export$d39e1813b3bdd0e1)({
|
|
1357
1437
|
...otherProps,
|
|
1358
1438
|
targetRef: triggerRef,
|
|
1359
1439
|
overlayRef: popoverRef,
|
|
1360
1440
|
isOpen: state.isOpen,
|
|
1361
|
-
onClose: null
|
|
1441
|
+
onClose: isNonModal ? state.close : null
|
|
1362
1442
|
});
|
|
1363
1443
|
(0, $49c51c25361d4cd2$export$ee0f7cc6afcd1c18)({
|
|
1364
|
-
isDisabled: isNonModal
|
|
1444
|
+
isDisabled: isNonModal || !state.isOpen
|
|
1365
1445
|
});
|
|
1366
1446
|
(0, $k7QOs$useLayoutEffect)(()=>{
|
|
1367
1447
|
if (state.isOpen && !isNonModal && popoverRef.current) return (0, $5e3802645cc19319$export$1c3ebcada18427bf)([
|