@react-aria/overlays 3.22.0 → 3.23.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/DismissButton.main.js +2 -2
- package/dist/DismissButton.mjs +3 -3
- package/dist/DismissButton.module.js +2 -2
- package/dist/Overlay.mjs +1 -1
- package/dist/PortalProvider.mjs +1 -1
- package/dist/ar-AE.mjs +1 -1
- package/dist/ariaHideOutside.main.js +7 -7
- package/dist/ariaHideOutside.mjs +8 -8
- package/dist/ariaHideOutside.module.js +7 -7
- package/dist/bg-BG.mjs +1 -1
- package/dist/calculatePosition.main.js +40 -40
- package/dist/calculatePosition.main.js.map +1 -1
- package/dist/calculatePosition.mjs +41 -41
- package/dist/calculatePosition.module.js +40 -40
- package/dist/calculatePosition.module.js.map +1 -1
- package/dist/cs-CZ.mjs +1 -1
- package/dist/da-DK.mjs +1 -1
- package/dist/de-DE.mjs +1 -1
- package/dist/el-GR.mjs +1 -1
- package/dist/en-US.mjs +1 -1
- package/dist/es-ES.mjs +1 -1
- package/dist/et-EE.mjs +1 -1
- package/dist/fi-FI.mjs +1 -1
- package/dist/fr-FR.mjs +1 -1
- package/dist/he-IL.mjs +1 -1
- package/dist/hr-HR.mjs +1 -1
- package/dist/hu-HU.mjs +1 -1
- package/dist/intlStrings.mjs +1 -1
- package/dist/it-IT.mjs +1 -1
- package/dist/ja-JP.mjs +1 -1
- package/dist/ko-KR.mjs +1 -1
- package/dist/lt-LT.mjs +1 -1
- package/dist/lv-LV.mjs +1 -1
- package/dist/nb-NO.mjs +1 -1
- package/dist/nl-NL.mjs +1 -1
- package/dist/pl-PL.mjs +1 -1
- package/dist/pt-BR.mjs +1 -1
- package/dist/pt-PT.mjs +1 -1
- package/dist/ro-RO.mjs +1 -1
- package/dist/ru-RU.mjs +1 -1
- package/dist/sk-SK.mjs +1 -1
- package/dist/sl-SI.mjs +1 -1
- package/dist/sr-SP.mjs +1 -1
- package/dist/sv-SE.mjs +1 -1
- package/dist/tr-TR.mjs +1 -1
- package/dist/types.d.ts +10 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/uk-UA.mjs +1 -1
- package/dist/useCloseOnScroll.main.js +6 -2
- package/dist/useCloseOnScroll.main.js.map +1 -1
- package/dist/useCloseOnScroll.mjs +7 -3
- package/dist/useCloseOnScroll.module.js +6 -2
- package/dist/useCloseOnScroll.module.js.map +1 -1
- package/dist/useModal.main.js +4 -4
- package/dist/useModal.mjs +5 -5
- package/dist/useModal.module.js +4 -4
- package/dist/useModalOverlay.main.js.map +1 -1
- package/dist/useModalOverlay.mjs +1 -1
- package/dist/useModalOverlay.module.js.map +1 -1
- package/dist/useOverlay.main.js +1 -1
- package/dist/useOverlay.main.js.map +1 -1
- package/dist/useOverlay.mjs +2 -2
- package/dist/useOverlay.module.js +1 -1
- package/dist/useOverlay.module.js.map +1 -1
- package/dist/useOverlayPosition.main.js +62 -19
- package/dist/useOverlayPosition.main.js.map +1 -1
- package/dist/useOverlayPosition.mjs +63 -20
- package/dist/useOverlayPosition.module.js +62 -19
- package/dist/useOverlayPosition.module.js.map +1 -1
- package/dist/useOverlayTrigger.main.js +5 -5
- package/dist/useOverlayTrigger.main.js.map +1 -1
- package/dist/useOverlayTrigger.mjs +6 -6
- package/dist/useOverlayTrigger.module.js +5 -5
- package/dist/useOverlayTrigger.module.js.map +1 -1
- package/dist/usePopover.main.js.map +1 -1
- package/dist/usePopover.mjs +1 -1
- package/dist/usePopover.module.js.map +1 -1
- package/dist/usePreventScroll.main.js +22 -22
- package/dist/usePreventScroll.mjs +23 -23
- package/dist/usePreventScroll.module.js +22 -22
- package/dist/zh-CN.mjs +1 -1
- package/dist/zh-TW.mjs +1 -1
- package/package.json +14 -14
- package/src/calculatePosition.ts +3 -3
- package/src/useCloseOnScroll.ts +10 -2
- package/src/useModalOverlay.ts +3 -3
- package/src/useOverlay.ts +4 -4
- package/src/useOverlayPosition.ts +58 -11
- package/src/useOverlayTrigger.ts +3 -3
- package/src/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;IACF;IAEA,kDAAkD;IAClD,CAAA,GAAA,yBAAiB,EAAE;aAAC;QAAK,mBAAmB,iBAAiB,SAAS,oBAAoB;gCAAM;IAAsB;IAEtH,IAAI,oBAAC,gBAAgB,EAAC,GAAG,CAAA,GAAA,qBAAa,EAAE;QACtC,YAAY,CAAC;QACb,cAAc,CAAC;YACb,gFAAgF;YAChF,8GAA8G;YAC9G,6FAA6F;YAC7F,sDAAsD;YACtD,sDAAsD;YACtD,EAAE;YACF,2EAA2E;YAC3E,yEAAyE;YACzE,kEAAkE;YAClE,IAAI,CAAC,EAAE,aAAa,IAAI,CAAA,GAAA,oCAA4B,EAAE,EAAE,aAAa,GACnE;YAGF,IAAI,CAAC,gCAAgC,6BAA6B,EAAE,aAAa,GAC/E;QAEJ;IACF;IAEA,IAAI,wBAAwB,CAAA;QAC1B,wGAAwG;QACxG,IAAI,EAAE,MAAM,KAAK,EAAE,aAAa,EAC9B,EAAE,cAAc;IAEpB;IAEA,OAAO;QACL,cAAc;uBACZ;YACA,GAAG,gBAAgB;QACrB;QACA,eAAe;YACb,eAAe;QACjB;IACF;AACF","sources":["packages/@react-aria/overlays/src/useOverlay.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 {DOMAttributes, RefObject} from '@react-types/shared';\nimport {isElementInChildOfActiveScope} from '@react-aria/focus';\nimport {useEffect} from 'react';\nimport {useFocusWithin, useInteractOutside} from '@react-aria/interactions';\n\nexport interface AriaOverlayProps {\n /** Whether the overlay is currently open. */\n isOpen?: boolean,\n\n /** Handler that is called when the overlay should close. */\n onClose?: () => void,\n\n /**\n * Whether to close the overlay when the user interacts outside it.\n * @default false\n */\n isDismissable?: boolean,\n\n /** Whether the overlay should close when focus is lost or moves outside it. */\n shouldCloseOnBlur?: boolean,\n\n /**\n * Whether pressing the escape key to close the overlay should be disabled.\n * @default false\n */\n isKeyboardDismissDisabled?: boolean,\n\n /**\n * When user interacts with the argument element outside of the overlay ref,\n * return true if onClose should be called. This gives you a chance to filter\n * out interaction with elements that should not dismiss the overlay.\n * By default, onClose will always be called on interaction outside the overlay ref.\n */\n shouldCloseOnInteractOutside?: (element: Element) => boolean\n}\n\nexport interface OverlayAria {\n /** Props to apply to the overlay container element. */\n overlayProps: DOMAttributes,\n /** Props to apply to the underlay element, if any. */\n underlayProps: DOMAttributes\n}\n\nconst visibleOverlays: RefObject<Element | null>[] = [];\n\n/**\n * Provides the behavior for overlays such as dialogs, popovers, and menus.\n * Hides the overlay when the user interacts outside it, when the Escape key is pressed,\n * or optionally, on blur. Only the top-most overlay will close at once.\n */\nexport function useOverlay(props: AriaOverlayProps, ref: RefObject<Element | null>): OverlayAria {\n let {\n onClose,\n shouldCloseOnBlur,\n isOpen,\n isDismissable = false,\n isKeyboardDismissDisabled = false,\n shouldCloseOnInteractOutside\n } = props;\n\n // Add the overlay ref to the stack of visible overlays on mount, and remove on unmount.\n useEffect(() => {\n if (isOpen) {\n visibleOverlays.push(ref);\n }\n\n return () => {\n let index = visibleOverlays.indexOf(ref);\n if (index >= 0) {\n visibleOverlays.splice(index, 1);\n }\n };\n }, [isOpen, ref]);\n\n // Only hide the overlay when it is the topmost visible overlay in the stack\n let onHide = () => {\n if (visibleOverlays[visibleOverlays.length - 1] === ref && onClose) {\n onClose();\n }\n };\n\n let onInteractOutsideStart = (e: PointerEvent) => {\n if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.target as Element)) {\n if (visibleOverlays[visibleOverlays.length - 1] === ref) {\n e.stopPropagation();\n e.preventDefault();\n }\n }\n };\n\n let onInteractOutside = (e: PointerEvent) => {\n if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.target as Element)) {\n if (visibleOverlays[visibleOverlays.length - 1] === ref) {\n e.stopPropagation();\n e.preventDefault();\n }\n onHide();\n }\n };\n\n // Handle the escape key\n let onKeyDown = (e) => {\n if (e.key === 'Escape' && !isKeyboardDismissDisabled && !e.nativeEvent.isComposing) {\n e.stopPropagation();\n e.preventDefault();\n onHide();\n }\n };\n\n // Handle clicking outside the overlay to close it\n useInteractOutside({ref, onInteractOutside: isDismissable && isOpen ? onInteractOutside : null, onInteractOutsideStart});\n\n let {focusWithinProps} = useFocusWithin({\n isDisabled: !shouldCloseOnBlur,\n onBlurWithin: (e) => {\n // Do not close if relatedTarget is null, which means focus is lost to the body.\n // That can happen when switching tabs, or due to a VoiceOver/Chrome bug with Control+Option+Arrow navigation.\n // Clicking on the body to close the overlay should already be handled by useInteractOutside.\n // https://github.com/adobe/react-spectrum/issues/4130\n // https://github.com/adobe/react-spectrum/issues/4922\n //\n // If focus is moving into a child focus scope (e.g. menu inside a dialog),\n // do not close the outer overlay. At this point, the active scope should\n // still be the outer overlay, since blur events run before focus.\n if (!e.relatedTarget || isElementInChildOfActiveScope(e.relatedTarget)) {\n return;\n }\n\n if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.relatedTarget as Element)) {\n onClose();\n }\n }\n });\n\n let onPointerDownUnderlay = e => {\n // fixes a firefox issue that starts text selection https://bugzilla.mozilla.org/show_bug.cgi?id=1675846\n if (e.target === e.currentTarget) {\n e.preventDefault();\n }\n };\n\n return {\n overlayProps: {\n onKeyDown,\n ...focusWithinProps\n },\n underlayProps: {\n onPointerDown: onPointerDownUnderlay\n }\n };\n}\n"],"names":[],"version":3,"file":"useOverlay.module.js.map"}
|
|
@@ -26,10 +26,10 @@ $parcel$export(module.exports, "useOverlayPosition", () => $cd94b4896dd97759$exp
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
// @ts-ignore
|
|
29
|
-
let $cd94b4896dd97759$var$visualViewport = typeof document !==
|
|
29
|
+
let $cd94b4896dd97759$var$visualViewport = typeof document !== 'undefined' && window.visualViewport;
|
|
30
30
|
function $cd94b4896dd97759$export$d39e1813b3bdd0e1(props) {
|
|
31
31
|
let { direction: direction } = (0, $6TXnl$reactariai18n.useLocale)();
|
|
32
|
-
let { arrowSize: arrowSize = 0, targetRef: targetRef, overlayRef: overlayRef, scrollRef: scrollRef = overlayRef, placement: placement =
|
|
32
|
+
let { arrowSize: arrowSize = 0, targetRef: targetRef, overlayRef: overlayRef, scrollRef: scrollRef = overlayRef, placement: placement = 'bottom', containerPadding: containerPadding = 12, shouldFlip: shouldFlip = true, boundaryElement: boundaryElement = typeof document !== 'undefined' ? document.body : null, offset: offset = 0, crossOffset: crossOffset = 0, shouldUpdatePosition: shouldUpdatePosition = true, isOpen: isOpen = true, onClose: onClose, maxHeight: maxHeight, arrowBoundaryOffset: arrowBoundaryOffset = 0 } = props;
|
|
33
33
|
let [position, setPosition] = (0, $6TXnl$react.useState)({
|
|
34
34
|
position: {},
|
|
35
35
|
arrowOffsetLeft: undefined,
|
|
@@ -64,16 +64,42 @@ function $cd94b4896dd97759$export$d39e1813b3bdd0e1(props) {
|
|
|
64
64
|
isOpen
|
|
65
65
|
]);
|
|
66
66
|
let updatePosition = (0, $6TXnl$react.useCallback)(()=>{
|
|
67
|
-
if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !
|
|
67
|
+
if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !boundaryElement) return;
|
|
68
68
|
if (($cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.scale) !== lastScale.current) return;
|
|
69
|
+
// Determine a scroll anchor based on the focused element.
|
|
70
|
+
// This stores the offset of the anchor element from the scroll container
|
|
71
|
+
// so it can be restored after repositioning. This way if the overlay height
|
|
72
|
+
// changes, the focused element appears to stay in the same position.
|
|
73
|
+
let anchor = null;
|
|
74
|
+
if (scrollRef.current && scrollRef.current.contains(document.activeElement)) {
|
|
75
|
+
let anchorRect = document.activeElement.getBoundingClientRect();
|
|
76
|
+
let scrollRect = scrollRef.current.getBoundingClientRect();
|
|
77
|
+
// Anchor from the top if the offset is in the top half of the scrollable element,
|
|
78
|
+
// otherwise anchor from the bottom.
|
|
79
|
+
anchor = {
|
|
80
|
+
type: 'top',
|
|
81
|
+
offset: anchorRect.top - scrollRect.top
|
|
82
|
+
};
|
|
83
|
+
if (anchor.offset > scrollRect.height / 2) {
|
|
84
|
+
anchor.type = 'bottom';
|
|
85
|
+
anchor.offset = anchorRect.bottom - scrollRect.bottom;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
69
88
|
// Always reset the overlay's previous max height if not defined by the user so that we can compensate for
|
|
70
89
|
// RAC collections populating after a second render and properly set a correct max height + positioning when it populates.
|
|
71
|
-
|
|
90
|
+
let overlay = overlayRef.current;
|
|
91
|
+
if (!maxHeight && overlayRef.current) {
|
|
92
|
+
var _window_visualViewport;
|
|
93
|
+
overlay.style.top = '0px';
|
|
94
|
+
overlay.style.bottom = '';
|
|
95
|
+
var _window_visualViewport_height;
|
|
96
|
+
overlay.style.maxHeight = ((_window_visualViewport_height = (_window_visualViewport = window.visualViewport) === null || _window_visualViewport === void 0 ? void 0 : _window_visualViewport.height) !== null && _window_visualViewport_height !== void 0 ? _window_visualViewport_height : window.innerHeight) + 'px';
|
|
97
|
+
}
|
|
72
98
|
let position = (0, $5935ba4d7da2c103$exports.calculatePosition)({
|
|
73
99
|
placement: $cd94b4896dd97759$var$translateRTL(placement, direction),
|
|
74
100
|
overlayNode: overlayRef.current,
|
|
75
101
|
targetNode: targetRef.current,
|
|
76
|
-
scrollNode: scrollRef.current,
|
|
102
|
+
scrollNode: scrollRef.current || overlayRef.current,
|
|
77
103
|
padding: containerPadding,
|
|
78
104
|
shouldFlip: shouldFlip,
|
|
79
105
|
boundaryElement: boundaryElement,
|
|
@@ -85,8 +111,19 @@ function $cd94b4896dd97759$export$d39e1813b3bdd0e1(props) {
|
|
|
85
111
|
});
|
|
86
112
|
// Modify overlay styles directly so positioning happens immediately without the need of a second render
|
|
87
113
|
// This is so we don't have to delay autoFocus scrolling or delay applying preventScroll for popovers
|
|
88
|
-
|
|
89
|
-
|
|
114
|
+
overlay.style.top = '';
|
|
115
|
+
overlay.style.bottom = '';
|
|
116
|
+
overlay.style.left = '';
|
|
117
|
+
overlay.style.right = '';
|
|
118
|
+
Object.keys(position.position).forEach((key)=>overlay.style[key] = position.position[key] + 'px');
|
|
119
|
+
overlay.style.maxHeight = position.maxHeight != null ? position.maxHeight + 'px' : undefined;
|
|
120
|
+
// Restore scroll position relative to anchor element.
|
|
121
|
+
if (anchor) {
|
|
122
|
+
let anchorRect = document.activeElement.getBoundingClientRect();
|
|
123
|
+
let scrollRect = scrollRef.current.getBoundingClientRect();
|
|
124
|
+
let newOffset = anchorRect[anchor.type] - scrollRect[anchor.type];
|
|
125
|
+
scrollRef.current.scrollTop += newOffset - anchor.offset;
|
|
126
|
+
}
|
|
90
127
|
// Trigger a set state for a second render anyway for arrow positioning
|
|
91
128
|
setPosition(position);
|
|
92
129
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -101,6 +138,11 @@ function $cd94b4896dd97759$export$d39e1813b3bdd0e1(props) {
|
|
|
101
138
|
ref: overlayRef,
|
|
102
139
|
onResize: updatePosition
|
|
103
140
|
});
|
|
141
|
+
// Update position when the target changes size (might need to flip).
|
|
142
|
+
(0, $6TXnl$reactariautils.useResizeObserver)({
|
|
143
|
+
ref: targetRef,
|
|
144
|
+
onResize: updatePosition
|
|
145
|
+
});
|
|
104
146
|
// Reposition the overlay and do not close on scroll while the visual viewport is resizing.
|
|
105
147
|
// This will ensure that overlays adjust their positioning when the iOS virtual keyboard appears.
|
|
106
148
|
let isResizing = (0, $6TXnl$react.useRef)(false);
|
|
@@ -119,11 +161,11 @@ function $cd94b4896dd97759$export$d39e1813b3bdd0e1(props) {
|
|
|
119
161
|
let onScroll = ()=>{
|
|
120
162
|
if (isResizing.current) onResize();
|
|
121
163
|
};
|
|
122
|
-
$cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.addEventListener(
|
|
123
|
-
$cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.addEventListener(
|
|
164
|
+
$cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.addEventListener('resize', onResize);
|
|
165
|
+
$cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.addEventListener('scroll', onScroll);
|
|
124
166
|
return ()=>{
|
|
125
|
-
$cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.removeEventListener(
|
|
126
|
-
$cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.removeEventListener(
|
|
167
|
+
$cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.removeEventListener('resize', onResize);
|
|
168
|
+
$cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.removeEventListener('scroll', onScroll);
|
|
127
169
|
};
|
|
128
170
|
}, [
|
|
129
171
|
updatePosition
|
|
@@ -141,19 +183,20 @@ function $cd94b4896dd97759$export$d39e1813b3bdd0e1(props) {
|
|
|
141
183
|
isOpen: isOpen,
|
|
142
184
|
onClose: onClose && close
|
|
143
185
|
});
|
|
186
|
+
var _position_maxHeight;
|
|
144
187
|
return {
|
|
145
188
|
overlayProps: {
|
|
146
189
|
style: {
|
|
147
|
-
position:
|
|
190
|
+
position: 'absolute',
|
|
148
191
|
zIndex: 100000,
|
|
149
192
|
...position.position,
|
|
150
|
-
maxHeight: position.maxHeight
|
|
193
|
+
maxHeight: (_position_maxHeight = position.maxHeight) !== null && _position_maxHeight !== void 0 ? _position_maxHeight : '100vh'
|
|
151
194
|
}
|
|
152
195
|
},
|
|
153
196
|
placement: position.placement,
|
|
154
197
|
arrowProps: {
|
|
155
|
-
|
|
156
|
-
role:
|
|
198
|
+
'aria-hidden': 'true',
|
|
199
|
+
role: 'presentation',
|
|
157
200
|
style: {
|
|
158
201
|
left: position.arrowOffsetLeft,
|
|
159
202
|
top: position.arrowOffsetTop
|
|
@@ -164,17 +207,17 @@ function $cd94b4896dd97759$export$d39e1813b3bdd0e1(props) {
|
|
|
164
207
|
}
|
|
165
208
|
function $cd94b4896dd97759$var$useResize(onResize) {
|
|
166
209
|
(0, $6TXnl$reactariautils.useLayoutEffect)(()=>{
|
|
167
|
-
window.addEventListener(
|
|
210
|
+
window.addEventListener('resize', onResize, false);
|
|
168
211
|
return ()=>{
|
|
169
|
-
window.removeEventListener(
|
|
212
|
+
window.removeEventListener('resize', onResize, false);
|
|
170
213
|
};
|
|
171
214
|
}, [
|
|
172
215
|
onResize
|
|
173
216
|
]);
|
|
174
217
|
}
|
|
175
218
|
function $cd94b4896dd97759$var$translateRTL(position, direction) {
|
|
176
|
-
if (direction ===
|
|
177
|
-
return position.replace(
|
|
219
|
+
if (direction === 'rtl') return position.replace('start', 'right').replace('end', 'left');
|
|
220
|
+
return position.replace('start', 'left').replace('end', 'right');
|
|
178
221
|
}
|
|
179
222
|
|
|
180
223
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAgED,aAAa;AACb,IAAI,uCAAiB,OAAO,aAAa,eAAe,OAAO,cAAc;AAMtE,SAAS,0CAAmB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AI,QAAQ,CAAA,GAAA,wBAAU,EAAE;QACtB,IAAI,CAAC,WAAW,OAAO,EACrB;IAEJ,GAAG;QAAC;QAAS;KAAW;IAExB,kFAAkF;IAClF,mEAAmE;IACnE,CAAA,GAAA,0CAAe,EAAE;QACf,YAAY;gBACZ;QACA,SAAS,WAAW;IACtB;IAEA,OAAO;QACL,cAAc;YACZ,OAAO;gBACL,UAAU;gBACV,QAAQ;gBACR,GAAG,SAAS,QAAQ;gBACpB,WAAW,SAAS,SAAS;YAC/B;QACF;QACA,WAAW,SAAS,SAAS;QAC7B,YAAY;YACV,eAAe;YACf,MAAM;YACN,OAAO;gBACL,MAAM,SAAS,eAAe;gBAC9B,KAAK,SAAS,cAAc;YAC9B;QACF;wBACA;IACF;AACF;AAEA,SAAS,gCAAU,QAAQ;IACzB,CAAA,GAAA,qCAAc,EAAE;QACd,OAAO,gBAAgB,CAAC,UAAU,UAAU;QAC5C,OAAO;YACL,OAAO,mBAAmB,CAAC,UAAU,UAAU;QACjD;IACF,GAAG;QAAC;KAAS;AACf;AAEA,SAAS,mCAAa,QAAQ,EAAE,SAAS;IACvC,IAAI,cAAc,OAChB,OAAO,SAAS,OAAO,CAAC,SAAS,SAAS,OAAO,CAAC,OAAO;IAE3D,OAAO,SAAS,OAAO,CAAC,SAAS,QAAQ,OAAO,CAAC,OAAO;AAC1D","sources":["packages/@react-aria/overlays/src/useOverlayPosition.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 {calculatePosition, PositionResult} from './calculatePosition';\nimport {DOMAttributes} from '@react-types/shared';\nimport {Placement, PlacementAxis, PositionProps} from '@react-types/overlays';\nimport {RefObject, useCallback, useEffect, useRef, useState} from 'react';\nimport {useCloseOnScroll} from './useCloseOnScroll';\nimport {useLayoutEffect, useResizeObserver} from '@react-aria/utils';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface AriaPositionProps extends PositionProps {\n /**\n * Cross size of the overlay arrow in pixels.\n * @default 0\n */\n arrowSize?: number,\n /**\n * Element that that serves as the positioning boundary.\n * @default document.body\n */\n boundaryElement?: Element,\n /**\n * The ref for the element which the overlay positions itself with respect to.\n */\n targetRef: RefObject<Element>,\n /**\n * The ref for the overlay element.\n */\n overlayRef: RefObject<Element>,\n /**\n * A ref for the scrollable region within the overlay.\n * @default overlayRef\n */\n scrollRef?: RefObject<Element>,\n /**\n * Whether the overlay should update its position automatically.\n * @default true\n */\n shouldUpdatePosition?: boolean,\n /** Handler that is called when the overlay should close. */\n onClose?: () => void,\n /**\n * The maxHeight specified for the overlay element.\n * By default, it will take all space up to the current viewport height.\n */\n maxHeight?: number,\n /**\n * The minimum distance the arrow's edge should be from the edge of the overlay element.\n * @default 0\n */\n arrowBoundaryOffset?: number\n}\n\nexport interface PositionAria {\n /** Props for the overlay container element. */\n overlayProps: DOMAttributes,\n /** Props for the overlay tip arrow if any. */\n arrowProps: DOMAttributes,\n /** Placement of the overlay with respect to the overlay trigger. */\n placement: PlacementAxis,\n /** Updates the position of the overlay. */\n updatePosition(): void\n}\n\n// @ts-ignore\nlet visualViewport = typeof document !== 'undefined' && window.visualViewport;\n\n/**\n * Handles positioning overlays like popovers and menus relative to a trigger\n * element, and updating the position when the window resizes.\n */\nexport function useOverlayPosition(props: AriaPositionProps): PositionAria {\n let {direction} = useLocale();\n let {\n arrowSize = 0,\n targetRef,\n overlayRef,\n scrollRef = overlayRef,\n placement = 'bottom' as Placement,\n containerPadding = 12,\n shouldFlip = true,\n boundaryElement = typeof document !== 'undefined' ? document.body : null,\n offset = 0,\n crossOffset = 0,\n shouldUpdatePosition = true,\n isOpen = true,\n onClose,\n maxHeight,\n arrowBoundaryOffset = 0\n } = props;\n let [position, setPosition] = useState<PositionResult>({\n position: {},\n arrowOffsetLeft: undefined,\n arrowOffsetTop: undefined,\n maxHeight: undefined,\n placement: undefined\n });\n\n let deps = [\n shouldUpdatePosition,\n placement,\n overlayRef.current,\n targetRef.current,\n scrollRef.current,\n containerPadding,\n shouldFlip,\n boundaryElement,\n offset,\n crossOffset,\n isOpen,\n direction,\n maxHeight,\n arrowBoundaryOffset,\n arrowSize\n ];\n\n // Note, the position freezing breaks if body sizes itself dynamicly with the visual viewport but that might\n // just be a non-realistic use case\n // Upon opening a overlay, record the current visual viewport scale so we can freeze the overlay styles\n let lastScale = useRef(visualViewport?.scale);\n useEffect(() => {\n if (isOpen) {\n lastScale.current = visualViewport?.scale;\n }\n }, [isOpen]);\n\n let updatePosition = useCallback(() => {\n if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !scrollRef.current || !boundaryElement) {\n return;\n }\n\n if (visualViewport?.scale !== lastScale.current) {\n return;\n }\n\n // Always reset the overlay's previous max height if not defined by the user so that we can compensate for\n // RAC collections populating after a second render and properly set a correct max height + positioning when it populates.\n if (!maxHeight && overlayRef.current) {\n (overlayRef.current as HTMLElement).style.maxHeight = 'none';\n }\n\n let position = calculatePosition({\n placement: translateRTL(placement, direction),\n overlayNode: overlayRef.current,\n targetNode: targetRef.current,\n scrollNode: scrollRef.current,\n padding: containerPadding,\n shouldFlip,\n boundaryElement,\n offset,\n crossOffset,\n maxHeight,\n arrowSize,\n arrowBoundaryOffset\n });\n\n // Modify overlay styles directly so positioning happens immediately without the need of a second render\n // This is so we don't have to delay autoFocus scrolling or delay applying preventScroll for popovers\n Object.keys(position.position).forEach(key => (overlayRef.current as HTMLElement).style[key] = position.position[key] + 'px');\n (overlayRef.current as HTMLElement).style.maxHeight = position.maxHeight != null ? position.maxHeight + 'px' : undefined;\n\n // Trigger a set state for a second render anyway for arrow positioning\n setPosition(position);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n\n // Update position when anything changes\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(updatePosition, deps);\n\n // Update position on window resize\n useResize(updatePosition);\n\n // Update position when the overlay changes size (might need to flip).\n useResizeObserver({\n ref: overlayRef,\n onResize: updatePosition\n });\n\n // Reposition the overlay and do not close on scroll while the visual viewport is resizing.\n // This will ensure that overlays adjust their positioning when the iOS virtual keyboard appears.\n let isResizing = useRef(false);\n useLayoutEffect(() => {\n let timeout: ReturnType<typeof setTimeout>;\n let onResize = () => {\n isResizing.current = true;\n clearTimeout(timeout);\n\n timeout = setTimeout(() => {\n isResizing.current = false;\n }, 500);\n\n updatePosition();\n };\n\n // Only reposition the overlay if a scroll event happens immediately as a result of resize (aka the virtual keyboard has appears)\n // We don't want to reposition the overlay if the user has pinch zoomed in and is scrolling the viewport around.\n let onScroll = () => {\n if (isResizing.current) {\n onResize();\n }\n };\n\n visualViewport?.addEventListener('resize', onResize);\n visualViewport?.addEventListener('scroll', onScroll);\n return () => {\n visualViewport?.removeEventListener('resize', onResize);\n visualViewport?.removeEventListener('scroll', onScroll);\n };\n }, [updatePosition]);\n\n let close = useCallback(() => {\n if (!isResizing.current) {\n onClose();\n }\n }, [onClose, isResizing]);\n\n // When scrolling a parent scrollable region of the trigger (other than the body),\n // we hide the popover. Otherwise, its position would be incorrect.\n useCloseOnScroll({\n triggerRef: targetRef,\n isOpen,\n onClose: onClose && close\n });\n\n return {\n overlayProps: {\n style: {\n position: 'absolute',\n zIndex: 100000, // should match the z-index in ModalTrigger\n ...position.position,\n maxHeight: position.maxHeight\n }\n },\n placement: position.placement,\n arrowProps: {\n 'aria-hidden': 'true',\n role: 'presentation',\n style: {\n left: position.arrowOffsetLeft,\n top: position.arrowOffsetTop\n }\n },\n updatePosition\n };\n}\n\nfunction useResize(onResize) {\n useLayoutEffect(() => {\n window.addEventListener('resize', onResize, false);\n return () => {\n window.removeEventListener('resize', onResize, false);\n };\n }, [onResize]);\n}\n\nfunction translateRTL(position, direction) {\n if (direction === 'rtl') {\n return position.replace('start', 'right').replace('end', 'left');\n }\n return position.replace('start', 'left').replace('end', 'right');\n}\n"],"names":[],"version":3,"file":"useOverlayPosition.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAqED,aAAa;AACb,IAAI,uCAAiB,OAAO,aAAa,eAAe,OAAO,cAAc;AAMtE,SAAS,0CAAmB,KAAwB;IACzD,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,8BAAQ;IAC1B,IAAI,aACF,YAAY,cACZ,SAAS,cACT,UAAU,aACV,YAAY,uBACZ,YAAY,4BACZ,mBAAmB,gBACnB,aAAa,uBACb,kBAAkB,OAAO,aAAa,cAAc,SAAS,IAAI,GAAG,cACpE,SAAS,gBACT,cAAc,yBACd,uBAAuB,cACvB,SAAS,eACT,OAAO,aACP,SAAS,uBACT,sBAAsB,GACvB,GAAG;IACJ,IAAI,CAAC,UAAU,YAAY,GAAG,CAAA,GAAA,qBAAO,EAAkB;QACrD,UAAU,CAAC;QACX,iBAAiB;QACjB,gBAAgB;QAChB,WAAW;QACX,WAAW;IACb;IAEA,IAAI,OAAO;QACT;QACA;QACA,WAAW,OAAO;QAClB,UAAU,OAAO;QACjB,UAAU,OAAO;QACjB;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;KACD;IAED,4GAA4G;IAC5G,mCAAmC;IACnC,uGAAuG;IACvG,IAAI,YAAY,CAAA,GAAA,mBAAK,EAAE,iDAAA,2DAAA,qCAAgB,KAAK;IAC5C,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,QACF,UAAU,OAAO,GAAG,iDAAA,2DAAA,qCAAgB,KAAK;IAE7C,GAAG;QAAC;KAAO;IAEX,IAAI,iBAAiB,CAAA,GAAA,wBAAU,EAAE;QAC/B,IAAI,yBAAyB,SAAS,CAAC,UAAU,CAAC,WAAW,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* 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 {calculatePosition, PositionResult} from './calculatePosition';\nimport {DOMAttributes, RefObject} from '@react-types/shared';\nimport {Placement, PlacementAxis, PositionProps} from '@react-types/overlays';\nimport {useCallback, useEffect, useRef, useState} from 'react';\nimport {useCloseOnScroll} from './useCloseOnScroll';\nimport {useLayoutEffect, useResizeObserver} from '@react-aria/utils';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface AriaPositionProps extends PositionProps {\n /**\n * Cross size of the overlay arrow in pixels.\n * @default 0\n */\n arrowSize?: number,\n /**\n * Element that that serves as the positioning boundary.\n * @default document.body\n */\n boundaryElement?: Element,\n /**\n * The ref for the element which the overlay positions itself with respect to.\n */\n targetRef: RefObject<Element | null>,\n /**\n * The ref for the overlay element.\n */\n overlayRef: RefObject<Element | null>,\n /**\n * A ref for the scrollable region within the overlay.\n * @default overlayRef\n */\n scrollRef?: RefObject<Element | null>,\n /**\n * Whether the overlay should update its position automatically.\n * @default true\n */\n shouldUpdatePosition?: boolean,\n /** Handler that is called when the overlay should close. */\n onClose?: () => void,\n /**\n * The maxHeight specified for the overlay element.\n * By default, it will take all space up to the current viewport height.\n */\n maxHeight?: number,\n /**\n * The minimum distance the arrow's edge should be from the edge of the overlay element.\n * @default 0\n */\n arrowBoundaryOffset?: number\n}\n\nexport interface PositionAria {\n /** Props for the overlay container element. */\n overlayProps: DOMAttributes,\n /** Props for the overlay tip arrow if any. */\n arrowProps: DOMAttributes,\n /** Placement of the overlay with respect to the overlay trigger. */\n placement: PlacementAxis,\n /** Updates the position of the overlay. */\n updatePosition(): void\n}\n\ninterface ScrollAnchor {\n type: 'top' | 'bottom',\n offset: number\n}\n\n// @ts-ignore\nlet visualViewport = typeof document !== 'undefined' && window.visualViewport;\n\n/**\n * Handles positioning overlays like popovers and menus relative to a trigger\n * element, and updating the position when the window resizes.\n */\nexport function useOverlayPosition(props: AriaPositionProps): PositionAria {\n let {direction} = useLocale();\n let {\n arrowSize = 0,\n targetRef,\n overlayRef,\n scrollRef = overlayRef,\n placement = 'bottom' as Placement,\n containerPadding = 12,\n shouldFlip = true,\n boundaryElement = typeof document !== 'undefined' ? document.body : null,\n offset = 0,\n crossOffset = 0,\n shouldUpdatePosition = true,\n isOpen = true,\n onClose,\n maxHeight,\n arrowBoundaryOffset = 0\n } = props;\n let [position, setPosition] = useState<PositionResult>({\n position: {},\n arrowOffsetLeft: undefined,\n arrowOffsetTop: undefined,\n maxHeight: undefined,\n placement: undefined\n });\n\n let deps = [\n shouldUpdatePosition,\n placement,\n overlayRef.current,\n targetRef.current,\n scrollRef.current,\n containerPadding,\n shouldFlip,\n boundaryElement,\n offset,\n crossOffset,\n isOpen,\n direction,\n maxHeight,\n arrowBoundaryOffset,\n arrowSize\n ];\n\n // Note, the position freezing breaks if body sizes itself dynamicly with the visual viewport but that might\n // just be a non-realistic use case\n // Upon opening a overlay, record the current visual viewport scale so we can freeze the overlay styles\n let lastScale = useRef(visualViewport?.scale);\n useEffect(() => {\n if (isOpen) {\n lastScale.current = visualViewport?.scale;\n }\n }, [isOpen]);\n\n let updatePosition = useCallback(() => {\n if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !boundaryElement) {\n return;\n }\n\n if (visualViewport?.scale !== lastScale.current) {\n return;\n }\n\n // Determine a scroll anchor based on the focused element.\n // This stores the offset of the anchor element from the scroll container\n // so it can be restored after repositioning. This way if the overlay height\n // changes, the focused element appears to stay in the same position.\n let anchor: ScrollAnchor | null = null;\n if (scrollRef.current && scrollRef.current.contains(document.activeElement)) {\n let anchorRect = document.activeElement.getBoundingClientRect();\n let scrollRect = scrollRef.current.getBoundingClientRect();\n // Anchor from the top if the offset is in the top half of the scrollable element,\n // otherwise anchor from the bottom.\n anchor = {\n type: 'top',\n offset: anchorRect.top - scrollRect.top\n };\n if (anchor.offset > scrollRect.height / 2) {\n anchor.type = 'bottom';\n anchor.offset = anchorRect.bottom - scrollRect.bottom;\n }\n }\n\n // Always reset the overlay's previous max height if not defined by the user so that we can compensate for\n // RAC collections populating after a second render and properly set a correct max height + positioning when it populates.\n let overlay = (overlayRef.current as HTMLElement);\n if (!maxHeight && overlayRef.current) {\n overlay.style.top = '0px';\n overlay.style.bottom = '';\n overlay.style.maxHeight = (window.visualViewport?.height ?? window.innerHeight) + 'px';\n }\n\n let position = calculatePosition({\n placement: translateRTL(placement, direction),\n overlayNode: overlayRef.current,\n targetNode: targetRef.current,\n scrollNode: scrollRef.current || overlayRef.current,\n padding: containerPadding,\n shouldFlip,\n boundaryElement,\n offset,\n crossOffset,\n maxHeight,\n arrowSize,\n arrowBoundaryOffset\n });\n\n // Modify overlay styles directly so positioning happens immediately without the need of a second render\n // This is so we don't have to delay autoFocus scrolling or delay applying preventScroll for popovers\n overlay.style.top = '';\n overlay.style.bottom = '';\n overlay.style.left = '';\n overlay.style.right = '';\n\n Object.keys(position.position).forEach(key => overlay.style[key] = position.position[key] + 'px');\n overlay.style.maxHeight = position.maxHeight != null ? position.maxHeight + 'px' : undefined;\n\n // Restore scroll position relative to anchor element.\n if (anchor) {\n let anchorRect = document.activeElement.getBoundingClientRect();\n let scrollRect = scrollRef.current.getBoundingClientRect();\n let newOffset = anchorRect[anchor.type] - scrollRect[anchor.type];\n scrollRef.current.scrollTop += newOffset - anchor.offset;\n }\n\n // Trigger a set state for a second render anyway for arrow positioning\n setPosition(position);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n\n // Update position when anything changes\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(updatePosition, deps);\n\n // Update position on window resize\n useResize(updatePosition);\n\n // Update position when the overlay changes size (might need to flip).\n useResizeObserver({\n ref: overlayRef,\n onResize: updatePosition\n });\n\n // Update position when the target changes size (might need to flip).\n useResizeObserver({\n ref: targetRef,\n onResize: updatePosition\n });\n\n // Reposition the overlay and do not close on scroll while the visual viewport is resizing.\n // This will ensure that overlays adjust their positioning when the iOS virtual keyboard appears.\n let isResizing = useRef(false);\n useLayoutEffect(() => {\n let timeout: ReturnType<typeof setTimeout>;\n let onResize = () => {\n isResizing.current = true;\n clearTimeout(timeout);\n\n timeout = setTimeout(() => {\n isResizing.current = false;\n }, 500);\n\n updatePosition();\n };\n\n // Only reposition the overlay if a scroll event happens immediately as a result of resize (aka the virtual keyboard has appears)\n // We don't want to reposition the overlay if the user has pinch zoomed in and is scrolling the viewport around.\n let onScroll = () => {\n if (isResizing.current) {\n onResize();\n }\n };\n\n visualViewport?.addEventListener('resize', onResize);\n visualViewport?.addEventListener('scroll', onScroll);\n return () => {\n visualViewport?.removeEventListener('resize', onResize);\n visualViewport?.removeEventListener('scroll', onScroll);\n };\n }, [updatePosition]);\n\n let close = useCallback(() => {\n if (!isResizing.current) {\n onClose();\n }\n }, [onClose, isResizing]);\n\n // When scrolling a parent scrollable region of the trigger (other than the body),\n // we hide the popover. Otherwise, its position would be incorrect.\n useCloseOnScroll({\n triggerRef: targetRef,\n isOpen,\n onClose: onClose && close\n });\n\n return {\n overlayProps: {\n style: {\n position: 'absolute',\n zIndex: 100000, // should match the z-index in ModalTrigger\n ...position.position,\n maxHeight: position.maxHeight ?? '100vh'\n }\n },\n placement: position.placement,\n arrowProps: {\n 'aria-hidden': 'true',\n role: 'presentation',\n style: {\n left: position.arrowOffsetLeft,\n top: position.arrowOffsetTop\n }\n },\n updatePosition\n };\n}\n\nfunction useResize(onResize) {\n useLayoutEffect(() => {\n window.addEventListener('resize', onResize, false);\n return () => {\n window.removeEventListener('resize', onResize, false);\n };\n }, [onResize]);\n}\n\nfunction translateRTL(position, direction) {\n if (direction === 'rtl') {\n return position.replace('start', 'right').replace('end', 'left');\n }\n return position.replace('start', 'left').replace('end', 'right');\n}\n"],"names":[],"version":3,"file":"useOverlayPosition.main.js.map"}
|
|
@@ -20,10 +20,10 @@ import {useLocale as $39EOa$useLocale} from "@react-aria/i18n";
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
// @ts-ignore
|
|
23
|
-
let $2a41e45df1593e64$var$visualViewport = typeof document !==
|
|
23
|
+
let $2a41e45df1593e64$var$visualViewport = typeof document !== 'undefined' && window.visualViewport;
|
|
24
24
|
function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
25
25
|
let { direction: direction } = (0, $39EOa$useLocale)();
|
|
26
|
-
let { arrowSize: arrowSize = 0, targetRef: targetRef, overlayRef: overlayRef, scrollRef: scrollRef = overlayRef, placement: placement =
|
|
26
|
+
let { arrowSize: arrowSize = 0, targetRef: targetRef, overlayRef: overlayRef, scrollRef: scrollRef = overlayRef, placement: placement = 'bottom', containerPadding: containerPadding = 12, shouldFlip: shouldFlip = true, boundaryElement: boundaryElement = typeof document !== 'undefined' ? document.body : null, offset: offset = 0, crossOffset: crossOffset = 0, shouldUpdatePosition: shouldUpdatePosition = true, isOpen: isOpen = true, onClose: onClose, maxHeight: maxHeight, arrowBoundaryOffset: arrowBoundaryOffset = 0 } = props;
|
|
27
27
|
let [position, setPosition] = (0, $39EOa$useState)({
|
|
28
28
|
position: {},
|
|
29
29
|
arrowOffsetLeft: undefined,
|
|
@@ -58,16 +58,42 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
58
58
|
isOpen
|
|
59
59
|
]);
|
|
60
60
|
let updatePosition = (0, $39EOa$useCallback)(()=>{
|
|
61
|
-
if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !
|
|
61
|
+
if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !boundaryElement) return;
|
|
62
62
|
if (($2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.scale) !== lastScale.current) return;
|
|
63
|
+
// Determine a scroll anchor based on the focused element.
|
|
64
|
+
// This stores the offset of the anchor element from the scroll container
|
|
65
|
+
// so it can be restored after repositioning. This way if the overlay height
|
|
66
|
+
// changes, the focused element appears to stay in the same position.
|
|
67
|
+
let anchor = null;
|
|
68
|
+
if (scrollRef.current && scrollRef.current.contains(document.activeElement)) {
|
|
69
|
+
let anchorRect = document.activeElement.getBoundingClientRect();
|
|
70
|
+
let scrollRect = scrollRef.current.getBoundingClientRect();
|
|
71
|
+
// Anchor from the top if the offset is in the top half of the scrollable element,
|
|
72
|
+
// otherwise anchor from the bottom.
|
|
73
|
+
anchor = {
|
|
74
|
+
type: 'top',
|
|
75
|
+
offset: anchorRect.top - scrollRect.top
|
|
76
|
+
};
|
|
77
|
+
if (anchor.offset > scrollRect.height / 2) {
|
|
78
|
+
anchor.type = 'bottom';
|
|
79
|
+
anchor.offset = anchorRect.bottom - scrollRect.bottom;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
63
82
|
// Always reset the overlay's previous max height if not defined by the user so that we can compensate for
|
|
64
83
|
// RAC collections populating after a second render and properly set a correct max height + positioning when it populates.
|
|
65
|
-
|
|
84
|
+
let overlay = overlayRef.current;
|
|
85
|
+
if (!maxHeight && overlayRef.current) {
|
|
86
|
+
var _window_visualViewport;
|
|
87
|
+
overlay.style.top = '0px';
|
|
88
|
+
overlay.style.bottom = '';
|
|
89
|
+
var _window_visualViewport_height;
|
|
90
|
+
overlay.style.maxHeight = ((_window_visualViewport_height = (_window_visualViewport = window.visualViewport) === null || _window_visualViewport === void 0 ? void 0 : _window_visualViewport.height) !== null && _window_visualViewport_height !== void 0 ? _window_visualViewport_height : window.innerHeight) + 'px';
|
|
91
|
+
}
|
|
66
92
|
let position = (0, $edcf132a9284368a$export$b3ceb0cbf1056d98)({
|
|
67
93
|
placement: $2a41e45df1593e64$var$translateRTL(placement, direction),
|
|
68
94
|
overlayNode: overlayRef.current,
|
|
69
95
|
targetNode: targetRef.current,
|
|
70
|
-
scrollNode: scrollRef.current,
|
|
96
|
+
scrollNode: scrollRef.current || overlayRef.current,
|
|
71
97
|
padding: containerPadding,
|
|
72
98
|
shouldFlip: shouldFlip,
|
|
73
99
|
boundaryElement: boundaryElement,
|
|
@@ -79,8 +105,19 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
79
105
|
});
|
|
80
106
|
// Modify overlay styles directly so positioning happens immediately without the need of a second render
|
|
81
107
|
// This is so we don't have to delay autoFocus scrolling or delay applying preventScroll for popovers
|
|
82
|
-
|
|
83
|
-
|
|
108
|
+
overlay.style.top = '';
|
|
109
|
+
overlay.style.bottom = '';
|
|
110
|
+
overlay.style.left = '';
|
|
111
|
+
overlay.style.right = '';
|
|
112
|
+
Object.keys(position.position).forEach((key)=>overlay.style[key] = position.position[key] + 'px');
|
|
113
|
+
overlay.style.maxHeight = position.maxHeight != null ? position.maxHeight + 'px' : undefined;
|
|
114
|
+
// Restore scroll position relative to anchor element.
|
|
115
|
+
if (anchor) {
|
|
116
|
+
let anchorRect = document.activeElement.getBoundingClientRect();
|
|
117
|
+
let scrollRect = scrollRef.current.getBoundingClientRect();
|
|
118
|
+
let newOffset = anchorRect[anchor.type] - scrollRect[anchor.type];
|
|
119
|
+
scrollRef.current.scrollTop += newOffset - anchor.offset;
|
|
120
|
+
}
|
|
84
121
|
// Trigger a set state for a second render anyway for arrow positioning
|
|
85
122
|
setPosition(position);
|
|
86
123
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -95,6 +132,11 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
95
132
|
ref: overlayRef,
|
|
96
133
|
onResize: updatePosition
|
|
97
134
|
});
|
|
135
|
+
// Update position when the target changes size (might need to flip).
|
|
136
|
+
(0, $39EOa$useResizeObserver)({
|
|
137
|
+
ref: targetRef,
|
|
138
|
+
onResize: updatePosition
|
|
139
|
+
});
|
|
98
140
|
// Reposition the overlay and do not close on scroll while the visual viewport is resizing.
|
|
99
141
|
// This will ensure that overlays adjust their positioning when the iOS virtual keyboard appears.
|
|
100
142
|
let isResizing = (0, $39EOa$useRef)(false);
|
|
@@ -113,11 +155,11 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
113
155
|
let onScroll = ()=>{
|
|
114
156
|
if (isResizing.current) onResize();
|
|
115
157
|
};
|
|
116
|
-
$2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.addEventListener(
|
|
117
|
-
$2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.addEventListener(
|
|
158
|
+
$2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.addEventListener('resize', onResize);
|
|
159
|
+
$2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.addEventListener('scroll', onScroll);
|
|
118
160
|
return ()=>{
|
|
119
|
-
$2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.removeEventListener(
|
|
120
|
-
$2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.removeEventListener(
|
|
161
|
+
$2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.removeEventListener('resize', onResize);
|
|
162
|
+
$2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.removeEventListener('scroll', onScroll);
|
|
121
163
|
};
|
|
122
164
|
}, [
|
|
123
165
|
updatePosition
|
|
@@ -135,19 +177,20 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
135
177
|
isOpen: isOpen,
|
|
136
178
|
onClose: onClose && close
|
|
137
179
|
});
|
|
180
|
+
var _position_maxHeight;
|
|
138
181
|
return {
|
|
139
182
|
overlayProps: {
|
|
140
183
|
style: {
|
|
141
|
-
position:
|
|
184
|
+
position: 'absolute',
|
|
142
185
|
zIndex: 100000,
|
|
143
186
|
...position.position,
|
|
144
|
-
maxHeight: position.maxHeight
|
|
187
|
+
maxHeight: (_position_maxHeight = position.maxHeight) !== null && _position_maxHeight !== void 0 ? _position_maxHeight : '100vh'
|
|
145
188
|
}
|
|
146
189
|
},
|
|
147
190
|
placement: position.placement,
|
|
148
191
|
arrowProps: {
|
|
149
|
-
|
|
150
|
-
role:
|
|
192
|
+
'aria-hidden': 'true',
|
|
193
|
+
role: 'presentation',
|
|
151
194
|
style: {
|
|
152
195
|
left: position.arrowOffsetLeft,
|
|
153
196
|
top: position.arrowOffsetTop
|
|
@@ -158,19 +201,19 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
158
201
|
}
|
|
159
202
|
function $2a41e45df1593e64$var$useResize(onResize) {
|
|
160
203
|
(0, $39EOa$useLayoutEffect)(()=>{
|
|
161
|
-
window.addEventListener(
|
|
204
|
+
window.addEventListener('resize', onResize, false);
|
|
162
205
|
return ()=>{
|
|
163
|
-
window.removeEventListener(
|
|
206
|
+
window.removeEventListener('resize', onResize, false);
|
|
164
207
|
};
|
|
165
208
|
}, [
|
|
166
209
|
onResize
|
|
167
210
|
]);
|
|
168
211
|
}
|
|
169
212
|
function $2a41e45df1593e64$var$translateRTL(position, direction) {
|
|
170
|
-
if (direction ===
|
|
171
|
-
return position.replace(
|
|
213
|
+
if (direction === 'rtl') return position.replace('start', 'right').replace('end', 'left');
|
|
214
|
+
return position.replace('start', 'left').replace('end', 'right');
|
|
172
215
|
}
|
|
173
216
|
|
|
174
217
|
|
|
175
218
|
export {$2a41e45df1593e64$export$d39e1813b3bdd0e1 as useOverlayPosition};
|
|
176
|
-
//# sourceMappingURL=useOverlayPosition.
|
|
219
|
+
//# sourceMappingURL=useOverlayPosition.module.js.map
|
|
@@ -20,10 +20,10 @@ import {useLocale as $39EOa$useLocale} from "@react-aria/i18n";
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
// @ts-ignore
|
|
23
|
-
let $2a41e45df1593e64$var$visualViewport = typeof document !==
|
|
23
|
+
let $2a41e45df1593e64$var$visualViewport = typeof document !== 'undefined' && window.visualViewport;
|
|
24
24
|
function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
25
25
|
let { direction: direction } = (0, $39EOa$useLocale)();
|
|
26
|
-
let { arrowSize: arrowSize = 0, targetRef: targetRef, overlayRef: overlayRef, scrollRef: scrollRef = overlayRef, placement: placement =
|
|
26
|
+
let { arrowSize: arrowSize = 0, targetRef: targetRef, overlayRef: overlayRef, scrollRef: scrollRef = overlayRef, placement: placement = 'bottom', containerPadding: containerPadding = 12, shouldFlip: shouldFlip = true, boundaryElement: boundaryElement = typeof document !== 'undefined' ? document.body : null, offset: offset = 0, crossOffset: crossOffset = 0, shouldUpdatePosition: shouldUpdatePosition = true, isOpen: isOpen = true, onClose: onClose, maxHeight: maxHeight, arrowBoundaryOffset: arrowBoundaryOffset = 0 } = props;
|
|
27
27
|
let [position, setPosition] = (0, $39EOa$useState)({
|
|
28
28
|
position: {},
|
|
29
29
|
arrowOffsetLeft: undefined,
|
|
@@ -58,16 +58,42 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
58
58
|
isOpen
|
|
59
59
|
]);
|
|
60
60
|
let updatePosition = (0, $39EOa$useCallback)(()=>{
|
|
61
|
-
if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !
|
|
61
|
+
if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !boundaryElement) return;
|
|
62
62
|
if (($2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.scale) !== lastScale.current) return;
|
|
63
|
+
// Determine a scroll anchor based on the focused element.
|
|
64
|
+
// This stores the offset of the anchor element from the scroll container
|
|
65
|
+
// so it can be restored after repositioning. This way if the overlay height
|
|
66
|
+
// changes, the focused element appears to stay in the same position.
|
|
67
|
+
let anchor = null;
|
|
68
|
+
if (scrollRef.current && scrollRef.current.contains(document.activeElement)) {
|
|
69
|
+
let anchorRect = document.activeElement.getBoundingClientRect();
|
|
70
|
+
let scrollRect = scrollRef.current.getBoundingClientRect();
|
|
71
|
+
// Anchor from the top if the offset is in the top half of the scrollable element,
|
|
72
|
+
// otherwise anchor from the bottom.
|
|
73
|
+
anchor = {
|
|
74
|
+
type: 'top',
|
|
75
|
+
offset: anchorRect.top - scrollRect.top
|
|
76
|
+
};
|
|
77
|
+
if (anchor.offset > scrollRect.height / 2) {
|
|
78
|
+
anchor.type = 'bottom';
|
|
79
|
+
anchor.offset = anchorRect.bottom - scrollRect.bottom;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
63
82
|
// Always reset the overlay's previous max height if not defined by the user so that we can compensate for
|
|
64
83
|
// RAC collections populating after a second render and properly set a correct max height + positioning when it populates.
|
|
65
|
-
|
|
84
|
+
let overlay = overlayRef.current;
|
|
85
|
+
if (!maxHeight && overlayRef.current) {
|
|
86
|
+
var _window_visualViewport;
|
|
87
|
+
overlay.style.top = '0px';
|
|
88
|
+
overlay.style.bottom = '';
|
|
89
|
+
var _window_visualViewport_height;
|
|
90
|
+
overlay.style.maxHeight = ((_window_visualViewport_height = (_window_visualViewport = window.visualViewport) === null || _window_visualViewport === void 0 ? void 0 : _window_visualViewport.height) !== null && _window_visualViewport_height !== void 0 ? _window_visualViewport_height : window.innerHeight) + 'px';
|
|
91
|
+
}
|
|
66
92
|
let position = (0, $edcf132a9284368a$export$b3ceb0cbf1056d98)({
|
|
67
93
|
placement: $2a41e45df1593e64$var$translateRTL(placement, direction),
|
|
68
94
|
overlayNode: overlayRef.current,
|
|
69
95
|
targetNode: targetRef.current,
|
|
70
|
-
scrollNode: scrollRef.current,
|
|
96
|
+
scrollNode: scrollRef.current || overlayRef.current,
|
|
71
97
|
padding: containerPadding,
|
|
72
98
|
shouldFlip: shouldFlip,
|
|
73
99
|
boundaryElement: boundaryElement,
|
|
@@ -79,8 +105,19 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
79
105
|
});
|
|
80
106
|
// Modify overlay styles directly so positioning happens immediately without the need of a second render
|
|
81
107
|
// This is so we don't have to delay autoFocus scrolling or delay applying preventScroll for popovers
|
|
82
|
-
|
|
83
|
-
|
|
108
|
+
overlay.style.top = '';
|
|
109
|
+
overlay.style.bottom = '';
|
|
110
|
+
overlay.style.left = '';
|
|
111
|
+
overlay.style.right = '';
|
|
112
|
+
Object.keys(position.position).forEach((key)=>overlay.style[key] = position.position[key] + 'px');
|
|
113
|
+
overlay.style.maxHeight = position.maxHeight != null ? position.maxHeight + 'px' : undefined;
|
|
114
|
+
// Restore scroll position relative to anchor element.
|
|
115
|
+
if (anchor) {
|
|
116
|
+
let anchorRect = document.activeElement.getBoundingClientRect();
|
|
117
|
+
let scrollRect = scrollRef.current.getBoundingClientRect();
|
|
118
|
+
let newOffset = anchorRect[anchor.type] - scrollRect[anchor.type];
|
|
119
|
+
scrollRef.current.scrollTop += newOffset - anchor.offset;
|
|
120
|
+
}
|
|
84
121
|
// Trigger a set state for a second render anyway for arrow positioning
|
|
85
122
|
setPosition(position);
|
|
86
123
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -95,6 +132,11 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
95
132
|
ref: overlayRef,
|
|
96
133
|
onResize: updatePosition
|
|
97
134
|
});
|
|
135
|
+
// Update position when the target changes size (might need to flip).
|
|
136
|
+
(0, $39EOa$useResizeObserver)({
|
|
137
|
+
ref: targetRef,
|
|
138
|
+
onResize: updatePosition
|
|
139
|
+
});
|
|
98
140
|
// Reposition the overlay and do not close on scroll while the visual viewport is resizing.
|
|
99
141
|
// This will ensure that overlays adjust their positioning when the iOS virtual keyboard appears.
|
|
100
142
|
let isResizing = (0, $39EOa$useRef)(false);
|
|
@@ -113,11 +155,11 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
113
155
|
let onScroll = ()=>{
|
|
114
156
|
if (isResizing.current) onResize();
|
|
115
157
|
};
|
|
116
|
-
$2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.addEventListener(
|
|
117
|
-
$2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.addEventListener(
|
|
158
|
+
$2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.addEventListener('resize', onResize);
|
|
159
|
+
$2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.addEventListener('scroll', onScroll);
|
|
118
160
|
return ()=>{
|
|
119
|
-
$2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.removeEventListener(
|
|
120
|
-
$2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.removeEventListener(
|
|
161
|
+
$2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.removeEventListener('resize', onResize);
|
|
162
|
+
$2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.removeEventListener('scroll', onScroll);
|
|
121
163
|
};
|
|
122
164
|
}, [
|
|
123
165
|
updatePosition
|
|
@@ -135,19 +177,20 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
135
177
|
isOpen: isOpen,
|
|
136
178
|
onClose: onClose && close
|
|
137
179
|
});
|
|
180
|
+
var _position_maxHeight;
|
|
138
181
|
return {
|
|
139
182
|
overlayProps: {
|
|
140
183
|
style: {
|
|
141
|
-
position:
|
|
184
|
+
position: 'absolute',
|
|
142
185
|
zIndex: 100000,
|
|
143
186
|
...position.position,
|
|
144
|
-
maxHeight: position.maxHeight
|
|
187
|
+
maxHeight: (_position_maxHeight = position.maxHeight) !== null && _position_maxHeight !== void 0 ? _position_maxHeight : '100vh'
|
|
145
188
|
}
|
|
146
189
|
},
|
|
147
190
|
placement: position.placement,
|
|
148
191
|
arrowProps: {
|
|
149
|
-
|
|
150
|
-
role:
|
|
192
|
+
'aria-hidden': 'true',
|
|
193
|
+
role: 'presentation',
|
|
151
194
|
style: {
|
|
152
195
|
left: position.arrowOffsetLeft,
|
|
153
196
|
top: position.arrowOffsetTop
|
|
@@ -158,17 +201,17 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
158
201
|
}
|
|
159
202
|
function $2a41e45df1593e64$var$useResize(onResize) {
|
|
160
203
|
(0, $39EOa$useLayoutEffect)(()=>{
|
|
161
|
-
window.addEventListener(
|
|
204
|
+
window.addEventListener('resize', onResize, false);
|
|
162
205
|
return ()=>{
|
|
163
|
-
window.removeEventListener(
|
|
206
|
+
window.removeEventListener('resize', onResize, false);
|
|
164
207
|
};
|
|
165
208
|
}, [
|
|
166
209
|
onResize
|
|
167
210
|
]);
|
|
168
211
|
}
|
|
169
212
|
function $2a41e45df1593e64$var$translateRTL(position, direction) {
|
|
170
|
-
if (direction ===
|
|
171
|
-
return position.replace(
|
|
213
|
+
if (direction === 'rtl') return position.replace('start', 'right').replace('end', 'left');
|
|
214
|
+
return position.replace('start', 'left').replace('end', 'right');
|
|
172
215
|
}
|
|
173
216
|
|
|
174
217
|
|