@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/main.js
CHANGED
|
@@ -92,6 +92,7 @@ let $5935ba4d7da2c103$var$visualViewport = typeof document !== "undefined" && wi
|
|
|
92
92
|
function $5935ba4d7da2c103$var$getContainerDimensions(containerNode) {
|
|
93
93
|
let width = 0, height = 0, totalWidth = 0, totalHeight = 0, top = 0, left = 0;
|
|
94
94
|
let scroll = {};
|
|
95
|
+
let isPinchZoomedIn = ($5935ba4d7da2c103$var$visualViewport === null || $5935ba4d7da2c103$var$visualViewport === void 0 ? void 0 : $5935ba4d7da2c103$var$visualViewport.scale) > 1;
|
|
95
96
|
if (containerNode.tagName === "BODY") {
|
|
96
97
|
let documentElement = document.documentElement;
|
|
97
98
|
totalWidth = documentElement.clientWidth;
|
|
@@ -102,6 +103,13 @@ function $5935ba4d7da2c103$var$getContainerDimensions(containerNode) {
|
|
|
102
103
|
height = (_visualViewport_height = $5935ba4d7da2c103$var$visualViewport === null || $5935ba4d7da2c103$var$visualViewport === void 0 ? void 0 : $5935ba4d7da2c103$var$visualViewport.height) !== null && _visualViewport_height !== void 0 ? _visualViewport_height : totalHeight;
|
|
103
104
|
scroll.top = documentElement.scrollTop || containerNode.scrollTop;
|
|
104
105
|
scroll.left = documentElement.scrollLeft || containerNode.scrollLeft;
|
|
106
|
+
// The goal of the below is to get a top/left value that represents the top/left of the visual viewport with
|
|
107
|
+
// respect to the layout viewport origin. This combined with the scrollTop/scrollLeft will allow us to calculate
|
|
108
|
+
// coordinates/values with respect to the visual viewport or with respect to the layout viewport.
|
|
109
|
+
if ($5935ba4d7da2c103$var$visualViewport) {
|
|
110
|
+
top = $5935ba4d7da2c103$var$visualViewport.offsetTop;
|
|
111
|
+
left = $5935ba4d7da2c103$var$visualViewport.offsetLeft;
|
|
112
|
+
}
|
|
105
113
|
} else {
|
|
106
114
|
({ width: width, height: height, top: top, left: left } = $5935ba4d7da2c103$var$getOffset(containerNode));
|
|
107
115
|
scroll.top = containerNode.scrollTop;
|
|
@@ -109,6 +117,16 @@ function $5935ba4d7da2c103$var$getContainerDimensions(containerNode) {
|
|
|
109
117
|
totalWidth = width;
|
|
110
118
|
totalHeight = height;
|
|
111
119
|
}
|
|
120
|
+
if ((0, $6Zb2x$reactariautils.isWebKit)() && (containerNode.tagName === "BODY" || containerNode.tagName === "HTML") && isPinchZoomedIn) {
|
|
121
|
+
// Safari will report a non-zero scrollTop/Left for the non-scrolling body/HTML element when pinch zoomed in unlike other browsers.
|
|
122
|
+
// Set to zero for parity calculations so we get consistent positioning of overlays across all browsers.
|
|
123
|
+
// Also switch to visualViewport.pageTop/pageLeft so that we still accomodate for scroll positioning for body/HTML elements that are actually scrollable
|
|
124
|
+
// before pinch zoom happens
|
|
125
|
+
scroll.top = 0;
|
|
126
|
+
scroll.left = 0;
|
|
127
|
+
top = $5935ba4d7da2c103$var$visualViewport.pageTop;
|
|
128
|
+
left = $5935ba4d7da2c103$var$visualViewport.pageLeft;
|
|
129
|
+
}
|
|
112
130
|
return {
|
|
113
131
|
width: width,
|
|
114
132
|
height: height,
|
|
@@ -127,6 +145,7 @@ function $5935ba4d7da2c103$var$getScroll(node) {
|
|
|
127
145
|
height: node.scrollHeight
|
|
128
146
|
};
|
|
129
147
|
}
|
|
148
|
+
// Determines the amount of space required when moving the overlay to ensure it remains in the boundary
|
|
130
149
|
function $5935ba4d7da2c103$var$getDelta(axis, offset, size, // The dimensions of the boundary element that the popover is
|
|
131
150
|
// positioned within (most of the time this is the <body>).
|
|
132
151
|
boundaryDimensions, // The dimensions of the containing block element that the popover is
|
|
@@ -134,13 +153,20 @@ boundaryDimensions, // The dimensions of the containing block element that the p
|
|
|
134
153
|
// Usually this is the same as the boundary element, but if the popover
|
|
135
154
|
// is portaled somewhere other than the body and has an ancestor with
|
|
136
155
|
// position: relative/absolute, it will be different.
|
|
137
|
-
containerDimensions, padding) {
|
|
156
|
+
containerDimensions, padding, containerOffsetWithBoundary) {
|
|
138
157
|
let containerScroll = containerDimensions.scroll[axis];
|
|
139
|
-
|
|
140
|
-
let
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
158
|
+
// The height/width of the boundary. Matches the axis along which we are adjusting the overlay position
|
|
159
|
+
let boundarySize = boundaryDimensions[$5935ba4d7da2c103$var$AXIS_SIZE[axis]];
|
|
160
|
+
// Calculate the edges of the boundary (accomodating for the boundary padding) and the edges of the overlay.
|
|
161
|
+
// Note that these values are with respect to the visual viewport (aka 0,0 is the top left of the viewport)
|
|
162
|
+
let boundaryStartEdge = boundaryDimensions.scroll[$5935ba4d7da2c103$var$AXIS[axis]] + padding;
|
|
163
|
+
let boundaryEndEdge = boundarySize + boundaryDimensions.scroll[$5935ba4d7da2c103$var$AXIS[axis]] - padding;
|
|
164
|
+
let startEdgeOffset = offset - containerScroll + containerOffsetWithBoundary[axis] - boundaryDimensions[$5935ba4d7da2c103$var$AXIS[axis]];
|
|
165
|
+
let endEdgeOffset = offset - containerScroll + size + containerOffsetWithBoundary[axis] - boundaryDimensions[$5935ba4d7da2c103$var$AXIS[axis]];
|
|
166
|
+
// If any of the overlay edges falls outside of the boundary, shift the overlay the required amount to align one of the overlay's
|
|
167
|
+
// edges with the closest boundary edge.
|
|
168
|
+
if (startEdgeOffset < boundaryStartEdge) return boundaryStartEdge - startEdgeOffset;
|
|
169
|
+
else if (endEdgeOffset > boundaryEndEdge) return Math.max(boundaryEndEdge - endEdgeOffset, boundaryStartEdge - startEdgeOffset);
|
|
144
170
|
else return 0;
|
|
145
171
|
}
|
|
146
172
|
function $5935ba4d7da2c103$var$getMargins(node) {
|
|
@@ -184,7 +210,6 @@ function $5935ba4d7da2c103$var$computePosition(childOffset, boundaryDimensions,
|
|
|
184
210
|
/* else {
|
|
185
211
|
the overlay top should match the button top
|
|
186
212
|
} */
|
|
187
|
-
// add the crossOffset from props
|
|
188
213
|
position[crossAxis] += crossOffset;
|
|
189
214
|
// overlay top overlapping arrow with button bottom
|
|
190
215
|
const minPosition = childOffset[crossAxis] - overlaySize[crossSize] + arrowSize + arrowBoundaryOffset;
|
|
@@ -202,14 +227,20 @@ function $5935ba4d7da2c103$var$computePosition(childOffset, boundaryDimensions,
|
|
|
202
227
|
} else position[axis] = Math.floor(childOffset[axis] + childOffset[size] + offset);
|
|
203
228
|
return position;
|
|
204
229
|
}
|
|
205
|
-
function $5935ba4d7da2c103$var$getMaxHeight(position, boundaryDimensions, containerOffsetWithBoundary,
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
230
|
+
function $5935ba4d7da2c103$var$getMaxHeight(position, boundaryDimensions, containerOffsetWithBoundary, isContainerPositioned, margins, padding, overlayHeight, heightGrowthDirection) {
|
|
231
|
+
const containerHeight = isContainerPositioned ? containerOffsetWithBoundary.height : boundaryDimensions[$5935ba4d7da2c103$var$TOTAL_SIZE.height];
|
|
232
|
+
// 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
|
|
233
|
+
// used in computePosition.
|
|
234
|
+
let overlayTop = position.top != null ? containerOffsetWithBoundary.top + position.top : containerOffsetWithBoundary.top + (containerHeight - position.bottom - overlayHeight);
|
|
235
|
+
let maxHeight = heightGrowthDirection !== "top" ? // We want the distance between the top of the overlay to the bottom of the boundary
|
|
236
|
+
Math.max(0, boundaryDimensions.height + boundaryDimensions.top + boundaryDimensions.scroll.top // this is the bottom of the boundary
|
|
237
|
+
- overlayTop // this is the top of the overlay
|
|
238
|
+
- (margins.top + margins.bottom + padding // save additional space for margin and padding
|
|
239
|
+
)) : Math.max(0, overlayTop + overlayHeight // this is the bottom of the overlay
|
|
210
240
|
- (boundaryDimensions.top + boundaryDimensions.scroll.top // this is the top of the boundary
|
|
211
241
|
) - (margins.top + margins.bottom + padding // save additional space for margin and padding
|
|
212
242
|
));
|
|
243
|
+
return Math.min(boundaryDimensions.height - padding * 2, maxHeight);
|
|
213
244
|
}
|
|
214
245
|
function $5935ba4d7da2c103$var$getAvailableSpace(boundaryDimensions, containerOffsetWithBoundary, childOffset, margins, padding, placementInfo) {
|
|
215
246
|
let { placement: placement, axis: axis, size: size } = placementInfo;
|
|
@@ -234,13 +265,22 @@ function $5935ba4d7da2c103$export$6839422d1f33cee9(placementInput, childOffset,
|
|
|
234
265
|
normalizedOffset = offset;
|
|
235
266
|
}
|
|
236
267
|
}
|
|
237
|
-
|
|
268
|
+
// Determine the direction the height of the overlay can grow so that we can choose how to calculate the max height
|
|
269
|
+
let heightGrowthDirection = "bottom";
|
|
270
|
+
if (placementInfo.axis === "top") {
|
|
271
|
+
if (placementInfo.placement === "top") heightGrowthDirection = "top";
|
|
272
|
+
else if (placementInfo.placement === "bottom") heightGrowthDirection = "bottom";
|
|
273
|
+
} else if (placementInfo.crossAxis === "top") {
|
|
274
|
+
if (placementInfo.crossPlacement === "top") heightGrowthDirection = "bottom";
|
|
275
|
+
else if (placementInfo.crossPlacement === "bottom") heightGrowthDirection = "top";
|
|
276
|
+
}
|
|
277
|
+
let delta = $5935ba4d7da2c103$var$getDelta(crossAxis, position[crossAxis], overlaySize[crossSize], boundaryDimensions, containerDimensions, padding, containerOffsetWithBoundary);
|
|
238
278
|
position[crossAxis] += delta;
|
|
239
|
-
let maxHeight = $5935ba4d7da2c103$var$getMaxHeight(position, boundaryDimensions, containerOffsetWithBoundary,
|
|
279
|
+
let maxHeight = $5935ba4d7da2c103$var$getMaxHeight(position, boundaryDimensions, containerOffsetWithBoundary, isContainerPositioned, margins, padding, overlaySize.height, heightGrowthDirection);
|
|
240
280
|
if (userSetMaxHeight && userSetMaxHeight < maxHeight) maxHeight = userSetMaxHeight;
|
|
241
281
|
overlaySize.height = Math.min(overlaySize.height, maxHeight);
|
|
242
282
|
position = $5935ba4d7da2c103$var$computePosition(childOffset, boundaryDimensions, overlaySize, placementInfo, normalizedOffset, crossOffset, containerOffsetWithBoundary, isContainerPositioned, arrowSize, arrowBoundaryOffset);
|
|
243
|
-
delta = $5935ba4d7da2c103$var$getDelta(crossAxis, position[crossAxis], overlaySize[crossSize], boundaryDimensions, containerDimensions, padding);
|
|
283
|
+
delta = $5935ba4d7da2c103$var$getDelta(crossAxis, position[crossAxis], overlaySize[crossSize], boundaryDimensions, containerDimensions, padding, containerOffsetWithBoundary);
|
|
244
284
|
position[crossAxis] += delta;
|
|
245
285
|
let arrowPosition = {};
|
|
246
286
|
// All values are transformed so that 0 is at the top/left of the overlay depending on the orientation
|
|
@@ -282,7 +322,14 @@ function $5935ba4d7da2c103$export$b3ceb0cbf1056d98(opts) {
|
|
|
282
322
|
let scrollSize = $5935ba4d7da2c103$var$getScroll(scrollNode);
|
|
283
323
|
let boundaryDimensions = $5935ba4d7da2c103$var$getContainerDimensions(boundaryElement);
|
|
284
324
|
let containerDimensions = $5935ba4d7da2c103$var$getContainerDimensions(container);
|
|
325
|
+
// If the container is the HTML element wrapping the body element, the retrieved scrollTop/scrollLeft will be equal to the
|
|
326
|
+
// 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
|
|
327
|
+
// by the container scroll since they are essentially the same containing element and thus in the same coordinate system
|
|
285
328
|
let containerOffsetWithBoundary = boundaryElement.tagName === "BODY" ? $5935ba4d7da2c103$var$getOffset(container) : $5935ba4d7da2c103$var$getPosition(container, boundaryElement);
|
|
329
|
+
if (container.tagName === "HTML" && boundaryElement.tagName === "BODY") {
|
|
330
|
+
containerDimensions.scroll.top = 0;
|
|
331
|
+
containerDimensions.scroll.left = 0;
|
|
332
|
+
}
|
|
286
333
|
return $5935ba4d7da2c103$export$6839422d1f33cee9(placement, childOffset, overlaySize, scrollSize, margins, padding, shouldFlip, boundaryDimensions, containerDimensions, containerOffsetWithBoundary, offset, crossOffset, isContainerPositioned, maxHeight, arrowSize, arrowBoundaryOffset);
|
|
287
334
|
}
|
|
288
335
|
function $5935ba4d7da2c103$var$getOffset(node) {
|
|
@@ -418,8 +465,21 @@ function $cd94b4896dd97759$export$d39e1813b3bdd0e1(props) {
|
|
|
418
465
|
arrowBoundaryOffset,
|
|
419
466
|
arrowSize
|
|
420
467
|
];
|
|
468
|
+
// Note, the position freezing breaks if body sizes itself dynamicly with the visual viewport but that might
|
|
469
|
+
// just be a non-realistic use case
|
|
470
|
+
// Upon opening a overlay, record the current visual viewport scale so we can freeze the overlay styles
|
|
471
|
+
let lastScale = (0, $6Zb2x$react.useRef)($cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.scale);
|
|
472
|
+
(0, $6Zb2x$react.useEffect)(()=>{
|
|
473
|
+
if (isOpen) lastScale.current = $cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.scale;
|
|
474
|
+
}, [
|
|
475
|
+
isOpen
|
|
476
|
+
]);
|
|
421
477
|
let updatePosition = (0, $6Zb2x$react.useCallback)(()=>{
|
|
422
478
|
if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !scrollRef.current || !boundaryElement) return;
|
|
479
|
+
if (($cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.scale) !== lastScale.current) return;
|
|
480
|
+
// Always reset the overlay's previous max height if not defined by the user so that we can compensate for
|
|
481
|
+
// RAC collections populating after a second render and properly set a correct max height + positioning when it populates.
|
|
482
|
+
if (!maxHeight && overlayRef.current) overlayRef.current.style.maxHeight = "none";
|
|
423
483
|
let position = (0, $5935ba4d7da2c103$export$b3ceb0cbf1056d98)({
|
|
424
484
|
placement: $cd94b4896dd97759$var$translateRTL(placement, direction),
|
|
425
485
|
overlayNode: overlayRef.current,
|
|
@@ -465,11 +525,16 @@ function $cd94b4896dd97759$export$d39e1813b3bdd0e1(props) {
|
|
|
465
525
|
}, 500);
|
|
466
526
|
updatePosition();
|
|
467
527
|
};
|
|
528
|
+
// Only reposition the overlay if a scroll event happens immediately as a result of resize (aka the virtual keyboard has appears)
|
|
529
|
+
// We don't want to reposition the overlay if the user has pinch zoomed in and is scrolling the viewport around.
|
|
530
|
+
let onScroll = ()=>{
|
|
531
|
+
if (isResizing.current) onResize();
|
|
532
|
+
};
|
|
468
533
|
$cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.addEventListener("resize", onResize);
|
|
469
|
-
$cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.addEventListener("scroll",
|
|
534
|
+
$cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.addEventListener("scroll", onScroll);
|
|
470
535
|
return ()=>{
|
|
471
536
|
$cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.removeEventListener("resize", onResize);
|
|
472
|
-
$cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.removeEventListener("scroll",
|
|
537
|
+
$cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.removeEventListener("scroll", onScroll);
|
|
473
538
|
};
|
|
474
539
|
}, [
|
|
475
540
|
updatePosition
|
|
@@ -551,7 +616,7 @@ function $82711f9cb668ecdb$export$ea8f71083e90600f(props, ref) {
|
|
|
551
616
|
isOpen,
|
|
552
617
|
ref
|
|
553
618
|
]);
|
|
554
|
-
// Only hide the overlay when it is the topmost visible overlay in the stack
|
|
619
|
+
// Only hide the overlay when it is the topmost visible overlay in the stack
|
|
555
620
|
let onHide = ()=>{
|
|
556
621
|
if ($82711f9cb668ecdb$var$visibleOverlays[$82711f9cb668ecdb$var$visibleOverlays.length - 1] === ref && onClose) onClose();
|
|
557
622
|
};
|
|
@@ -726,8 +791,9 @@ function $5c2f5cd01815d369$var$preventScrollStandard() {
|
|
|
726
791
|
//
|
|
727
792
|
// 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling
|
|
728
793
|
// on the window.
|
|
729
|
-
// 2.
|
|
730
|
-
// top or bottom.
|
|
794
|
+
// 2. Set `overscroll-behavior: contain` on nested scrollable regions so they do not scroll the page when at
|
|
795
|
+
// the top or bottom. Work around a bug where this does not work when the element does not actually overflow
|
|
796
|
+
// by preventing default in a `touchmove` event.
|
|
731
797
|
// 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.
|
|
732
798
|
// 4. When focusing an input, apply a transform to trick Safari into thinking the input is at the top
|
|
733
799
|
// of the page, which prevents it from scrolling the page. After the input is focused, scroll the element
|
|
@@ -739,12 +805,15 @@ function $5c2f5cd01815d369$var$preventScrollStandard() {
|
|
|
739
805
|
// to navigate to an input with the next/previous buttons that's outside a modal.
|
|
740
806
|
function $5c2f5cd01815d369$var$preventScrollMobileSafari() {
|
|
741
807
|
let scrollable;
|
|
742
|
-
let
|
|
808
|
+
let restoreScrollableStyles;
|
|
743
809
|
let onTouchStart = (e)=>{
|
|
744
810
|
// Store the nearest scrollable parent element from the element that the user touched.
|
|
745
|
-
scrollable = (0, $6Zb2x$reactariautils.getScrollParent)(e.target);
|
|
811
|
+
scrollable = (0, $6Zb2x$reactariautils.getScrollParent)(e.target, true);
|
|
746
812
|
if (scrollable === document.documentElement && scrollable === document.body) return;
|
|
747
|
-
|
|
813
|
+
// Prevent scrolling up when at the top and scrolling down when at the bottom
|
|
814
|
+
// of a nested scrollable area, otherwise mobile Safari will start scrolling
|
|
815
|
+
// the window instead.
|
|
816
|
+
if (scrollable instanceof HTMLElement && window.getComputedStyle(scrollable).overscrollBehavior === "auto") restoreScrollableStyles = $5c2f5cd01815d369$var$setStyle(scrollable, "overscrollBehavior", "contain");
|
|
748
817
|
};
|
|
749
818
|
let onTouchMove = (e)=>{
|
|
750
819
|
// Prevent scrolling the window.
|
|
@@ -752,22 +821,20 @@ function $5c2f5cd01815d369$var$preventScrollMobileSafari() {
|
|
|
752
821
|
e.preventDefault();
|
|
753
822
|
return;
|
|
754
823
|
}
|
|
755
|
-
//
|
|
756
|
-
//
|
|
757
|
-
// the
|
|
758
|
-
//
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
if (bottom === 0) return;
|
|
763
|
-
if (scrollTop <= 0 && y > lastY || scrollTop >= bottom && y < lastY) e.preventDefault();
|
|
764
|
-
lastY = y;
|
|
824
|
+
// overscroll-behavior should prevent scroll chaining, but currently does not
|
|
825
|
+
// if the element doesn't actually overflow. https://bugs.webkit.org/show_bug.cgi?id=243452
|
|
826
|
+
// This checks that both the width and height do not overflow, otherwise we might
|
|
827
|
+
// block horizontal scrolling too. In that case, adding `touch-action: pan-x` to
|
|
828
|
+
// the element will prevent vertical page scrolling. We can't add that automatically
|
|
829
|
+
// because it must be set before the touchstart event.
|
|
830
|
+
if (scrollable.scrollHeight === scrollable.clientHeight && scrollable.scrollWidth === scrollable.clientWidth) e.preventDefault();
|
|
765
831
|
};
|
|
766
832
|
let onTouchEnd = (e)=>{
|
|
767
833
|
let target = e.target;
|
|
768
834
|
// Apply this change if we're not already focused on the target element
|
|
769
835
|
if ($5c2f5cd01815d369$var$willOpenKeyboard(target) && target !== document.activeElement) {
|
|
770
836
|
e.preventDefault();
|
|
837
|
+
setupStyles();
|
|
771
838
|
// Apply a transform to trick Safari into thinking the input is at the top of the page
|
|
772
839
|
// so it doesn't try to scroll it into view. When tapping on an input, this needs to
|
|
773
840
|
// be done before the "focus" event, so we have to focus the element ourselves.
|
|
@@ -777,10 +844,12 @@ function $5c2f5cd01815d369$var$preventScrollMobileSafari() {
|
|
|
777
844
|
target.style.transform = "";
|
|
778
845
|
});
|
|
779
846
|
}
|
|
847
|
+
if (restoreScrollableStyles) restoreScrollableStyles();
|
|
780
848
|
};
|
|
781
849
|
let onFocus = (e)=>{
|
|
782
850
|
let target = e.target;
|
|
783
851
|
if ($5c2f5cd01815d369$var$willOpenKeyboard(target)) {
|
|
852
|
+
setupStyles();
|
|
784
853
|
// Transform also needs to be applied in the focus event in cases where focus moves
|
|
785
854
|
// other than tapping on an input directly, e.g. the next/previous buttons in the
|
|
786
855
|
// software keyboard. In these cases, it seems applying the transform in the focus event
|
|
@@ -805,19 +874,25 @@ function $5c2f5cd01815d369$var$preventScrollMobileSafari() {
|
|
|
805
874
|
});
|
|
806
875
|
}
|
|
807
876
|
};
|
|
808
|
-
let
|
|
809
|
-
|
|
810
|
-
|
|
877
|
+
let restoreStyles = null;
|
|
878
|
+
let setupStyles = ()=>{
|
|
879
|
+
if (restoreStyles) return;
|
|
880
|
+
let onWindowScroll = ()=>{
|
|
881
|
+
// Last resort. If the window scrolled, scroll it back to the top.
|
|
882
|
+
// It should always be at the top because the body will have a negative margin (see below).
|
|
883
|
+
window.scrollTo(0, 0);
|
|
884
|
+
};
|
|
885
|
+
// Record the original scroll position so we can restore it.
|
|
886
|
+
// Then apply a negative margin to the body to offset it by the scroll position. This will
|
|
887
|
+
// enable us to scroll the window to the top, which is required for the rest of this to work.
|
|
888
|
+
let scrollX = window.pageXOffset;
|
|
889
|
+
let scrollY = window.pageYOffset;
|
|
890
|
+
restoreStyles = (0, $6Zb2x$reactariautils.chain)($5c2f5cd01815d369$var$addEvent(window, "scroll", onWindowScroll), $5c2f5cd01815d369$var$setStyle(document.documentElement, "paddingRight", `${window.innerWidth - document.documentElement.clientWidth}px`), $5c2f5cd01815d369$var$setStyle(document.documentElement, "overflow", "hidden"), $5c2f5cd01815d369$var$setStyle(document.body, "marginTop", `-${scrollY}px`), ()=>{
|
|
891
|
+
window.scrollTo(scrollX, scrollY);
|
|
892
|
+
});
|
|
893
|
+
// Scroll to the top. The negative margin on the body will make this appear the same.
|
|
811
894
|
window.scrollTo(0, 0);
|
|
812
895
|
};
|
|
813
|
-
// Record the original scroll position so we can restore it.
|
|
814
|
-
// Then apply a negative margin to the body to offset it by the scroll position. This will
|
|
815
|
-
// enable us to scroll the window to the top, which is required for the rest of this to work.
|
|
816
|
-
let scrollX = window.pageXOffset;
|
|
817
|
-
let scrollY = window.pageYOffset;
|
|
818
|
-
let restoreStyles = (0, $6Zb2x$reactariautils.chain)($5c2f5cd01815d369$var$setStyle(document.documentElement, "paddingRight", `${window.innerWidth - document.documentElement.clientWidth}px`), $5c2f5cd01815d369$var$setStyle(document.documentElement, "overflow", "hidden"), $5c2f5cd01815d369$var$setStyle(document.body, "marginTop", `-${scrollY}px`));
|
|
819
|
-
// Scroll to the top. The negative margin on the body will make this appear the same.
|
|
820
|
-
window.scrollTo(0, 0);
|
|
821
896
|
let removeEvents = (0, $6Zb2x$reactariautils.chain)($5c2f5cd01815d369$var$addEvent(document, "touchstart", onTouchStart, {
|
|
822
897
|
passive: false,
|
|
823
898
|
capture: true
|
|
@@ -827,12 +902,12 @@ function $5c2f5cd01815d369$var$preventScrollMobileSafari() {
|
|
|
827
902
|
}), $5c2f5cd01815d369$var$addEvent(document, "touchend", onTouchEnd, {
|
|
828
903
|
passive: false,
|
|
829
904
|
capture: true
|
|
830
|
-
}), $5c2f5cd01815d369$var$addEvent(document, "focus", onFocus, true)
|
|
905
|
+
}), $5c2f5cd01815d369$var$addEvent(document, "focus", onFocus, true));
|
|
831
906
|
return ()=>{
|
|
832
907
|
// Restore styles and scroll the page back to where it was.
|
|
833
|
-
|
|
908
|
+
restoreScrollableStyles === null || restoreScrollableStyles === void 0 ? void 0 : restoreScrollableStyles();
|
|
909
|
+
restoreStyles === null || restoreStyles === void 0 ? void 0 : restoreStyles();
|
|
834
910
|
removeEvents();
|
|
835
|
-
window.scrollTo(scrollX, scrollY);
|
|
836
911
|
};
|
|
837
912
|
}
|
|
838
913
|
// Sets a CSS property on an element, and returns a function to revert it to the previous value.
|
|
@@ -1222,7 +1297,7 @@ $90f032faf016e1fb$exports = {
|
|
|
1222
1297
|
|
|
1223
1298
|
function $f69bb3e6457495cc$export$2317d149ed6f78c4(props) {
|
|
1224
1299
|
let { onDismiss: onDismiss, ...otherProps } = props;
|
|
1225
|
-
let stringFormatter = (0, $6Zb2x$reactariai18n.useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($90f032faf016e1fb$exports))));
|
|
1300
|
+
let stringFormatter = (0, $6Zb2x$reactariai18n.useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($90f032faf016e1fb$exports))), "@react-aria/overlays");
|
|
1226
1301
|
let labels = (0, $6Zb2x$reactariautils.useLabels)(otherProps, stringFormatter.format("dismiss"));
|
|
1227
1302
|
let onClick = ()=>{
|
|
1228
1303
|
if (onDismiss) onDismiss();
|
|
@@ -1230,7 +1305,11 @@ function $f69bb3e6457495cc$export$2317d149ed6f78c4(props) {
|
|
|
1230
1305
|
return /*#__PURE__*/ (0, ($parcel$interopDefault($6Zb2x$react))).createElement((0, $6Zb2x$reactariavisuallyhidden.VisuallyHidden), null, /*#__PURE__*/ (0, ($parcel$interopDefault($6Zb2x$react))).createElement("button", {
|
|
1231
1306
|
...labels,
|
|
1232
1307
|
tabIndex: -1,
|
|
1233
|
-
onClick: onClick
|
|
1308
|
+
onClick: onClick,
|
|
1309
|
+
style: {
|
|
1310
|
+
width: 1,
|
|
1311
|
+
height: 1
|
|
1312
|
+
}
|
|
1234
1313
|
}));
|
|
1235
1314
|
}
|
|
1236
1315
|
|
|
@@ -1365,23 +1444,24 @@ function $08ef1685902b6011$export$1c3ebcada18427bf(targets, root = document.body
|
|
|
1365
1444
|
|
|
1366
1445
|
|
|
1367
1446
|
function $6c2dfcdee3e15e20$export$542a6fd13ac93354(props, state) {
|
|
1368
|
-
let { triggerRef: triggerRef, popoverRef: popoverRef, isNonModal: isNonModal, isKeyboardDismissDisabled: isKeyboardDismissDisabled, ...otherProps } = props;
|
|
1447
|
+
let { triggerRef: triggerRef, popoverRef: popoverRef, isNonModal: isNonModal, isKeyboardDismissDisabled: isKeyboardDismissDisabled, shouldCloseOnInteractOutside: shouldCloseOnInteractOutside, ...otherProps } = props;
|
|
1369
1448
|
let { overlayProps: overlayProps, underlayProps: underlayProps } = (0, $82711f9cb668ecdb$export$ea8f71083e90600f)({
|
|
1370
1449
|
isOpen: state.isOpen,
|
|
1371
1450
|
onClose: state.close,
|
|
1372
1451
|
shouldCloseOnBlur: true,
|
|
1373
1452
|
isDismissable: !isNonModal,
|
|
1374
|
-
isKeyboardDismissDisabled: isKeyboardDismissDisabled
|
|
1453
|
+
isKeyboardDismissDisabled: isKeyboardDismissDisabled,
|
|
1454
|
+
shouldCloseOnInteractOutside: shouldCloseOnInteractOutside
|
|
1375
1455
|
}, popoverRef);
|
|
1376
1456
|
let { overlayProps: positionProps, arrowProps: arrowProps, placement: placement } = (0, $cd94b4896dd97759$export$d39e1813b3bdd0e1)({
|
|
1377
1457
|
...otherProps,
|
|
1378
1458
|
targetRef: triggerRef,
|
|
1379
1459
|
overlayRef: popoverRef,
|
|
1380
1460
|
isOpen: state.isOpen,
|
|
1381
|
-
onClose: null
|
|
1461
|
+
onClose: isNonModal ? state.close : null
|
|
1382
1462
|
});
|
|
1383
1463
|
(0, $5c2f5cd01815d369$export$ee0f7cc6afcd1c18)({
|
|
1384
|
-
isDisabled: isNonModal
|
|
1464
|
+
isDisabled: isNonModal || !state.isOpen
|
|
1385
1465
|
});
|
|
1386
1466
|
(0, $6Zb2x$reactariautils.useLayoutEffect)(()=>{
|
|
1387
1467
|
if (state.isOpen && !isNonModal && popoverRef.current) return (0, $08ef1685902b6011$export$1c3ebcada18427bf)([
|