@react-aria/overlays 3.28.0 → 3.29.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ariaHideOutside.main.js +6 -1
- package/dist/ariaHideOutside.main.js.map +1 -1
- package/dist/ariaHideOutside.mjs +6 -1
- package/dist/ariaHideOutside.module.js +6 -1
- package/dist/ariaHideOutside.module.js.map +1 -1
- package/dist/calculatePosition.main.js +41 -19
- package/dist/calculatePosition.main.js.map +1 -1
- package/dist/calculatePosition.mjs +41 -20
- package/dist/calculatePosition.module.js +41 -20
- package/dist/calculatePosition.module.js.map +1 -1
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/useOverlayPosition.main.js +8 -4
- package/dist/useOverlayPosition.main.js.map +1 -1
- package/dist/useOverlayPosition.mjs +9 -5
- package/dist/useOverlayPosition.module.js +9 -5
- package/dist/useOverlayPosition.module.js.map +1 -1
- package/dist/usePopover.main.js +3 -2
- package/dist/usePopover.main.js.map +1 -1
- package/dist/usePopover.mjs +3 -2
- package/dist/usePopover.module.js +3 -2
- package/dist/usePopover.module.js.map +1 -1
- package/package.json +11 -11
- package/src/ariaHideOutside.ts +5 -0
- package/src/calculatePosition.ts +44 -12
- package/src/useOverlayPosition.ts +15 -4
- package/src/usePopover.ts +8 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {calculatePosition as $edcf132a9284368a$export$b3ceb0cbf1056d98} from "./calculatePosition.module.js";
|
|
1
|
+
import {calculatePosition as $edcf132a9284368a$export$b3ceb0cbf1056d98, getRect as $edcf132a9284368a$export$4b834cebd9e5cebe} from "./calculatePosition.module.js";
|
|
2
2
|
import {useCloseOnScroll as $dd149f63282afbbf$export$18fc8428861184da} from "./useCloseOnScroll.module.js";
|
|
3
3
|
import {useState as $39EOa$useState, useRef as $39EOa$useRef, useEffect as $39EOa$useEffect, useCallback as $39EOa$useCallback} from "react";
|
|
4
4
|
import {useLayoutEffect as $39EOa$useLayoutEffect, useResizeObserver as $39EOa$useResizeObserver} from "@react-aria/utils";
|
|
@@ -22,13 +22,14 @@ import {useLocale as $39EOa$useLocale} from "@react-aria/i18n";
|
|
|
22
22
|
let $2a41e45df1593e64$var$visualViewport = typeof document !== 'undefined' ? window.visualViewport : null;
|
|
23
23
|
function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
24
24
|
let { direction: direction } = (0, $39EOa$useLocale)();
|
|
25
|
-
let { arrowSize: arrowSize
|
|
25
|
+
let { arrowSize: arrowSize, targetRef: targetRef, overlayRef: overlayRef, arrowRef: arrowRef, 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;
|
|
26
26
|
let [position, setPosition] = (0, $39EOa$useState)(null);
|
|
27
27
|
let deps = [
|
|
28
28
|
shouldUpdatePosition,
|
|
29
29
|
placement,
|
|
30
30
|
overlayRef.current,
|
|
31
31
|
targetRef.current,
|
|
32
|
+
arrowRef === null || arrowRef === void 0 ? void 0 : arrowRef.current,
|
|
32
33
|
scrollRef.current,
|
|
33
34
|
containerPadding,
|
|
34
35
|
shouldFlip,
|
|
@@ -96,7 +97,7 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
96
97
|
offset: offset,
|
|
97
98
|
crossOffset: crossOffset,
|
|
98
99
|
maxHeight: maxHeight,
|
|
99
|
-
arrowSize: arrowSize,
|
|
100
|
+
arrowSize: arrowSize !== null && arrowSize !== void 0 ? arrowSize : (arrowRef === null || arrowRef === void 0 ? void 0 : arrowRef.current) ? (0, $edcf132a9284368a$export$4b834cebd9e5cebe)(arrowRef.current, true).width : 0,
|
|
100
101
|
arrowBoundaryOffset: arrowBoundaryOffset
|
|
101
102
|
});
|
|
102
103
|
if (!position.position) return;
|
|
@@ -174,17 +175,20 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
174
175
|
isOpen: isOpen,
|
|
175
176
|
onClose: onClose && close
|
|
176
177
|
});
|
|
177
|
-
var _position_maxHeight, _position_placement;
|
|
178
|
+
var _position_maxHeight, _position_placement, _position_triggerAnchorPoint;
|
|
178
179
|
return {
|
|
179
180
|
overlayProps: {
|
|
180
181
|
style: {
|
|
181
|
-
position: 'absolute',
|
|
182
|
+
position: position ? 'absolute' : 'fixed',
|
|
183
|
+
top: !position ? 0 : undefined,
|
|
184
|
+
left: !position ? 0 : undefined,
|
|
182
185
|
zIndex: 100000,
|
|
183
186
|
...position === null || position === void 0 ? void 0 : position.position,
|
|
184
187
|
maxHeight: (_position_maxHeight = position === null || position === void 0 ? void 0 : position.maxHeight) !== null && _position_maxHeight !== void 0 ? _position_maxHeight : '100vh'
|
|
185
188
|
}
|
|
186
189
|
},
|
|
187
190
|
placement: (_position_placement = position === null || position === void 0 ? void 0 : position.placement) !== null && _position_placement !== void 0 ? _position_placement : null,
|
|
191
|
+
triggerAnchorPoint: (_position_triggerAnchorPoint = position === null || position === void 0 ? void 0 : position.triggerAnchorPoint) !== null && _position_triggerAnchorPoint !== void 0 ? _position_triggerAnchorPoint : null,
|
|
188
192
|
arrowProps: {
|
|
189
193
|
'aria-hidden': 'true',
|
|
190
194
|
role: 'presentation',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAqED,IAAI,uCAAiB,OAAO,aAAa,cAAc,OAAO,cAAc,GAAG;AAMxE,SAAS,0CAAmB,KAAwB;IACzD,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAC1B,IAAI,aACF,YAAY,cACZ,SAAS,cACT,UAAU,aACV,YAAY,uBACZ,YAAY,4BACZ,mBAAm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IAAI,QAAQ,CAAA,GAAA,kBAAU,EAAE;QACtB,IAAI,CAAC,WAAW,OAAO,EACrB,oBAAA,8BAAA;IAEJ,GAAG;QAAC;QAAS;KAAW;IAExB,kFAAkF;IAClF,mEAAmE;IACnE,CAAA,GAAA,yCAAe,EAAE;QACf,YAAY;gBACZ;QACA,SAAS,WAAW;IACtB;QAQiB,qBAGJ;IATb,OAAO;QACL,cAAc;YACZ,OAAO;gBACL,UAAU;gBACV,QAAQ;mBACL,qBAAA,+BAAA,SAAU,QAAQ,AAArB;gBACA,WAAW,CAAA,sBAAA,qBAAA,+BAAA,SAAU,SAAS,cAAnB,iCAAA,sBAAuB;YACpC;QACF;QACA,WAAW,CAAA,sBAAA,qBAAA,+BAAA,SAAU,SAAS,cAAnB,iCAAA,sBAAuB;QAClC,YAAY;YACV,eAAe;YACf,MAAM;YACN,OAAO;gBACL,IAAI,EAAE,qBAAA,+BAAA,SAAU,eAAe;gBAC/B,GAAG,EAAE,qBAAA,+BAAA,SAAU,cAAc;YAC/B;QACF;wBACA;IACF;AACF;AAEA,SAAS,gCAAU,QAAQ;IACzB,CAAA,GAAA,sBAAc,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, 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) | null,\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 | null,\n /** Updates the position of the overlay. */\n updatePosition(): void\n}\n\ninterface ScrollAnchor {\n type: 'top' | 'bottom',\n offset: number\n}\n\nlet visualViewport = typeof document !== 'undefined' ? window.visualViewport : null;\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 | null>(null);\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 ?? 0) - scrollRect.top\n };\n if (anchor.offset > scrollRect.height / 2) {\n anchor.type = 'bottom';\n anchor.offset = (anchorRect?.bottom ?? 0) - 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 if (!position.position) {\n return;\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' : '';\n\n // Restore scroll position relative to anchor element.\n if (anchor && document.activeElement && scrollRef.current) {\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 ?? null,\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.module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;AAAA;;;;;;;;;;CA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,SAAS,gCAAU,QAAQ;IACzB,CAAA,GAAA,sBAAc,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, getRect, 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 * The ref for the arrow element.\n */\n arrowRef?: 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) | null,\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 | null,\n /** The origin of the target in the overlay's coordinate system. Useful for animations. */\n triggerAnchorPoint: {x: number, y: number} | null,\n /** Updates the position of the overlay. */\n updatePosition(): void\n}\n\ninterface ScrollAnchor {\n type: 'top' | 'bottom',\n offset: number\n}\n\nlet visualViewport = typeof document !== 'undefined' ? window.visualViewport : null;\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,\n targetRef,\n overlayRef,\n arrowRef,\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 | null>(null);\n\n let deps = [\n shouldUpdatePosition,\n placement,\n overlayRef.current,\n targetRef.current,\n arrowRef?.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 ?? 0) - scrollRect.top\n };\n if (anchor.offset > scrollRect.height / 2) {\n anchor.type = 'bottom';\n anchor.offset = (anchorRect?.bottom ?? 0) - 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: arrowSize ?? (arrowRef?.current ? getRect(arrowRef.current, true).width : 0),\n arrowBoundaryOffset\n });\n\n if (!position.position) {\n return;\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' : '';\n\n // Restore scroll position relative to anchor element.\n if (anchor && document.activeElement && scrollRef.current) {\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: position ? 'absolute' : 'fixed',\n top: !position ? 0 : undefined,\n left: !position ? 0 : undefined,\n zIndex: 100000, // should match the z-index in ModalTrigger\n ...position?.position,\n maxHeight: position?.maxHeight ?? '100vh'\n }\n },\n placement: position?.placement ?? null,\n triggerAnchorPoint: position?.triggerAnchorPoint ?? null,\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.module.js.map"}
|
package/dist/usePopover.main.js
CHANGED
|
@@ -38,7 +38,7 @@ function $6c2dfcdee3e15e20$export$542a6fd13ac93354(props, state) {
|
|
|
38
38
|
isKeyboardDismissDisabled: isKeyboardDismissDisabled,
|
|
39
39
|
shouldCloseOnInteractOutside: shouldCloseOnInteractOutside
|
|
40
40
|
}, groupRef !== null && groupRef !== void 0 ? groupRef : popoverRef);
|
|
41
|
-
let { overlayProps: positionProps, arrowProps: arrowProps, placement: placement } = (0, $cd94b4896dd97759$exports.useOverlayPosition)({
|
|
41
|
+
let { overlayProps: positionProps, arrowProps: arrowProps, placement: placement, triggerAnchorPoint: origin } = (0, $cd94b4896dd97759$exports.useOverlayPosition)({
|
|
42
42
|
...otherProps,
|
|
43
43
|
targetRef: triggerRef,
|
|
44
44
|
overlayRef: popoverRef,
|
|
@@ -68,7 +68,8 @@ function $6c2dfcdee3e15e20$export$542a6fd13ac93354(props, state) {
|
|
|
68
68
|
popoverProps: (0, $jkVOI$reactariautils.mergeProps)(overlayProps, positionProps),
|
|
69
69
|
arrowProps: arrowProps,
|
|
70
70
|
underlayProps: underlayProps,
|
|
71
|
-
placement: placement
|
|
71
|
+
placement: placement,
|
|
72
|
+
triggerAnchorPoint: origin
|
|
72
73
|
};
|
|
73
74
|
}
|
|
74
75
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAyEM,SAAS,0CAAW,KAAuB,EAAE,KAA0B;IAC5E,IAAI,cACF,UAAU,cACV,UAAU,YACV,QAAQ,cACR,UAAU,6BACV,yBAAyB,gCACzB,4BAA4B,EAC5B,GAAG,YACJ,GAAG;IAEJ,IAAI,YAAY,UAAU,CAAC,UAAU,KAAK;IAE1C,IAAI,gBAAC,YAAY,iBAAE,aAAa,EAAC,GAAG,CAAA,GAAA,oCAAS,EAC3C;QACE,QAAQ,MAAM,MAAM;QACpB,SAAS,MAAM,KAAK;QACpB,mBAAmB;QACnB,eAAe,CAAC,cAAc;mCAC9B;sCACA;IACF,GACA,qBAAA,sBAAA,WAAY;IAGd,IAAI,EAAC,cAAc,aAAa,cAAE,UAAU,aAAE,SAAS,EAAE,oBAAoB,MAAM,EAAC,GAAG,CAAA,GAAA,4CAAiB,EAAE;QACxG,GAAG,UAAU;QACb,WAAW;QACX,YAAY;QACZ,QAAQ,MAAM,MAAM;QACpB,SAAS,cAAc,CAAC,YAAY,MAAM,KAAK,GAAG;IACpD;IAEA,CAAA,GAAA,0CAAe,EAAE;QACf,YAAY,cAAc,CAAC,MAAM,MAAM;IACzC;IAEA,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,MAAM,MAAM,IAAI,WAAW,OAAO,EAAE;gBAEjB,mBAEK;YAH1B,IAAI,YACF,OAAO,CAAA,GAAA,qCAAU,EAAE,CAAA,oBAAA,qBAAA,+BAAA,SAAU,OAAO,cAAjB,+BAAA,oBAAqB,WAAW,OAAO;iBAE1D,OAAO,CAAA,GAAA,yCAAc,EAAE;gBAAC,CAAA,qBAAA,qBAAA,+BAAA,SAAU,OAAO,cAAjB,gCAAA,qBAAqB,WAAW,OAAO;aAAC,EAAE;gBAAC,gBAAgB;YAAI;QAE3F;IACF,GAAG;QAAC;QAAY,MAAM,MAAM;QAAE;QAAY;KAAS;IAEnD,OAAO;QACL,cAAc,CAAA,GAAA,gCAAS,EAAE,cAAc;oBACvC;uBACA;mBACA;QACA,oBAAoB;IACtB;AACF","sources":["packages/@react-aria/overlays/src/usePopover.ts"],"sourcesContent":["/*\n * Copyright 2022 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 {ariaHideOutside, keepVisible} from './ariaHideOutside';\nimport {AriaPositionProps, useOverlayPosition} from './useOverlayPosition';\nimport {DOMAttributes, RefObject} from '@react-types/shared';\nimport {mergeProps} from '@react-aria/utils';\nimport {OverlayTriggerState} from '@react-stately/overlays';\nimport {PlacementAxis} from '@react-types/overlays';\nimport {useEffect} from 'react';\nimport {useOverlay} from './useOverlay';\nimport {usePreventScroll} from './usePreventScroll';\n\nexport interface AriaPopoverProps extends Omit<AriaPositionProps, 'isOpen' | 'onClose' | 'targetRef' | 'overlayRef'> {\n /**\n * The ref for the element which the popover positions itself with respect to.\n */\n triggerRef: RefObject<Element | null>,\n /**\n * The ref for the popover element.\n */\n popoverRef: RefObject<Element | null>,\n /** A ref for the popover arrow element. */\n arrowRef?: RefObject<Element | null>,\n /**\n * An optional ref for a group of popovers, e.g. submenus.\n * When provided, this element is used to detect outside interactions\n * and hiding elements from assistive technologies instead of the popoverRef.\n */\n groupRef?: RefObject<Element | null>,\n /**\n * Whether the popover is non-modal, i.e. elements outside the popover may be\n * interacted with by assistive technologies.\n *\n * Most popovers should not use this option as it may negatively impact the screen\n * reader experience. Only use with components such as combobox, which are designed\n * to handle this situation carefully.\n */\n isNonModal?: boolean,\n /**\n * Whether pressing the escape key to close the popover should be disabled.\n *\n * Most popovers should not use this option. When set to true, an alternative\n * way to close the popover with a keyboard must be provided.\n *\n * @default false\n */\n isKeyboardDismissDisabled?: boolean,\n /**\n * When user interacts with the argument element outside of the popover 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 popover.\n * By default, onClose will always be called on interaction outside the popover ref.\n */\n shouldCloseOnInteractOutside?: (element: Element) => boolean\n}\n\nexport interface PopoverAria {\n /** Props for the popover element. */\n popoverProps: DOMAttributes,\n /** Props for the popover tip arrow if any. */\n arrowProps: DOMAttributes,\n /** Props to apply to the underlay element, if any. */\n underlayProps: DOMAttributes,\n /** Placement of the popover with respect to the trigger. */\n placement: PlacementAxis | null,\n /** The origin of the target in the overlay's coordinate system. Useful for animations. */\n triggerAnchorPoint: {x: number, y: number} | null\n}\n\n/**\n * Provides the behavior and accessibility implementation for a popover component.\n * A popover is an overlay element positioned relative to a trigger.\n */\nexport function usePopover(props: AriaPopoverProps, state: OverlayTriggerState): PopoverAria {\n let {\n triggerRef,\n popoverRef,\n groupRef,\n isNonModal,\n isKeyboardDismissDisabled,\n shouldCloseOnInteractOutside,\n ...otherProps\n } = props;\n\n let isSubmenu = otherProps['trigger'] === 'SubmenuTrigger';\n\n let {overlayProps, underlayProps} = useOverlay(\n {\n isOpen: state.isOpen,\n onClose: state.close,\n shouldCloseOnBlur: true,\n isDismissable: !isNonModal || isSubmenu,\n isKeyboardDismissDisabled,\n shouldCloseOnInteractOutside\n },\n groupRef ?? popoverRef\n );\n\n let {overlayProps: positionProps, arrowProps, placement, triggerAnchorPoint: origin} = useOverlayPosition({\n ...otherProps,\n targetRef: triggerRef,\n overlayRef: popoverRef,\n isOpen: state.isOpen,\n onClose: isNonModal && !isSubmenu ? state.close : null\n });\n\n usePreventScroll({\n isDisabled: isNonModal || !state.isOpen\n });\n\n useEffect(() => {\n if (state.isOpen && popoverRef.current) {\n if (isNonModal) {\n return keepVisible(groupRef?.current ?? popoverRef.current);\n } else {\n return ariaHideOutside([groupRef?.current ?? popoverRef.current], {shouldUseInert: true});\n }\n }\n }, [isNonModal, state.isOpen, popoverRef, groupRef]);\n\n return {\n popoverProps: mergeProps(overlayProps, positionProps),\n arrowProps,\n underlayProps,\n placement,\n triggerAnchorPoint: origin\n };\n}\n"],"names":[],"version":3,"file":"usePopover.main.js.map"}
|
package/dist/usePopover.mjs
CHANGED
|
@@ -32,7 +32,7 @@ function $f2f8a6077418541e$export$542a6fd13ac93354(props, state) {
|
|
|
32
32
|
isKeyboardDismissDisabled: isKeyboardDismissDisabled,
|
|
33
33
|
shouldCloseOnInteractOutside: shouldCloseOnInteractOutside
|
|
34
34
|
}, groupRef !== null && groupRef !== void 0 ? groupRef : popoverRef);
|
|
35
|
-
let { overlayProps: positionProps, arrowProps: arrowProps, placement: placement } = (0, $2a41e45df1593e64$export$d39e1813b3bdd0e1)({
|
|
35
|
+
let { overlayProps: positionProps, arrowProps: arrowProps, placement: placement, triggerAnchorPoint: origin } = (0, $2a41e45df1593e64$export$d39e1813b3bdd0e1)({
|
|
36
36
|
...otherProps,
|
|
37
37
|
targetRef: triggerRef,
|
|
38
38
|
overlayRef: popoverRef,
|
|
@@ -62,7 +62,8 @@ function $f2f8a6077418541e$export$542a6fd13ac93354(props, state) {
|
|
|
62
62
|
popoverProps: (0, $m0yab$mergeProps)(overlayProps, positionProps),
|
|
63
63
|
arrowProps: arrowProps,
|
|
64
64
|
underlayProps: underlayProps,
|
|
65
|
-
placement: placement
|
|
65
|
+
placement: placement,
|
|
66
|
+
triggerAnchorPoint: origin
|
|
66
67
|
};
|
|
67
68
|
}
|
|
68
69
|
|
|
@@ -32,7 +32,7 @@ function $f2f8a6077418541e$export$542a6fd13ac93354(props, state) {
|
|
|
32
32
|
isKeyboardDismissDisabled: isKeyboardDismissDisabled,
|
|
33
33
|
shouldCloseOnInteractOutside: shouldCloseOnInteractOutside
|
|
34
34
|
}, groupRef !== null && groupRef !== void 0 ? groupRef : popoverRef);
|
|
35
|
-
let { overlayProps: positionProps, arrowProps: arrowProps, placement: placement } = (0, $2a41e45df1593e64$export$d39e1813b3bdd0e1)({
|
|
35
|
+
let { overlayProps: positionProps, arrowProps: arrowProps, placement: placement, triggerAnchorPoint: origin } = (0, $2a41e45df1593e64$export$d39e1813b3bdd0e1)({
|
|
36
36
|
...otherProps,
|
|
37
37
|
targetRef: triggerRef,
|
|
38
38
|
overlayRef: popoverRef,
|
|
@@ -62,7 +62,8 @@ function $f2f8a6077418541e$export$542a6fd13ac93354(props, state) {
|
|
|
62
62
|
popoverProps: (0, $m0yab$mergeProps)(overlayProps, positionProps),
|
|
63
63
|
arrowProps: arrowProps,
|
|
64
64
|
underlayProps: underlayProps,
|
|
65
|
-
placement: placement
|
|
65
|
+
placement: placement,
|
|
66
|
+
triggerAnchorPoint: origin
|
|
66
67
|
};
|
|
67
68
|
}
|
|
68
69
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;
|
|
1
|
+
{"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAyEM,SAAS,0CAAW,KAAuB,EAAE,KAA0B;IAC5E,IAAI,cACF,UAAU,cACV,UAAU,YACV,QAAQ,cACR,UAAU,6BACV,yBAAyB,gCACzB,4BAA4B,EAC5B,GAAG,YACJ,GAAG;IAEJ,IAAI,YAAY,UAAU,CAAC,UAAU,KAAK;IAE1C,IAAI,gBAAC,YAAY,iBAAE,aAAa,EAAC,GAAG,CAAA,GAAA,yCAAS,EAC3C;QACE,QAAQ,MAAM,MAAM;QACpB,SAAS,MAAM,KAAK;QACpB,mBAAmB;QACnB,eAAe,CAAC,cAAc;mCAC9B;sCACA;IACF,GACA,qBAAA,sBAAA,WAAY;IAGd,IAAI,EAAC,cAAc,aAAa,cAAE,UAAU,aAAE,SAAS,EAAE,oBAAoB,MAAM,EAAC,GAAG,CAAA,GAAA,yCAAiB,EAAE;QACxG,GAAG,UAAU;QACb,WAAW;QACX,YAAY;QACZ,QAAQ,MAAM,MAAM;QACpB,SAAS,cAAc,CAAC,YAAY,MAAM,KAAK,GAAG;IACpD;IAEA,CAAA,GAAA,yCAAe,EAAE;QACf,YAAY,cAAc,CAAC,MAAM,MAAM;IACzC;IAEA,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,MAAM,MAAM,IAAI,WAAW,OAAO,EAAE;gBAEjB,mBAEK;YAH1B,IAAI,YACF,OAAO,CAAA,GAAA,yCAAU,EAAE,CAAA,oBAAA,qBAAA,+BAAA,SAAU,OAAO,cAAjB,+BAAA,oBAAqB,WAAW,OAAO;iBAE1D,OAAO,CAAA,GAAA,yCAAc,EAAE;gBAAC,CAAA,qBAAA,qBAAA,+BAAA,SAAU,OAAO,cAAjB,gCAAA,qBAAqB,WAAW,OAAO;aAAC,EAAE;gBAAC,gBAAgB;YAAI;QAE3F;IACF,GAAG;QAAC;QAAY,MAAM,MAAM;QAAE;QAAY;KAAS;IAEnD,OAAO;QACL,cAAc,CAAA,GAAA,iBAAS,EAAE,cAAc;oBACvC;uBACA;mBACA;QACA,oBAAoB;IACtB;AACF","sources":["packages/@react-aria/overlays/src/usePopover.ts"],"sourcesContent":["/*\n * Copyright 2022 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 {ariaHideOutside, keepVisible} from './ariaHideOutside';\nimport {AriaPositionProps, useOverlayPosition} from './useOverlayPosition';\nimport {DOMAttributes, RefObject} from '@react-types/shared';\nimport {mergeProps} from '@react-aria/utils';\nimport {OverlayTriggerState} from '@react-stately/overlays';\nimport {PlacementAxis} from '@react-types/overlays';\nimport {useEffect} from 'react';\nimport {useOverlay} from './useOverlay';\nimport {usePreventScroll} from './usePreventScroll';\n\nexport interface AriaPopoverProps extends Omit<AriaPositionProps, 'isOpen' | 'onClose' | 'targetRef' | 'overlayRef'> {\n /**\n * The ref for the element which the popover positions itself with respect to.\n */\n triggerRef: RefObject<Element | null>,\n /**\n * The ref for the popover element.\n */\n popoverRef: RefObject<Element | null>,\n /** A ref for the popover arrow element. */\n arrowRef?: RefObject<Element | null>,\n /**\n * An optional ref for a group of popovers, e.g. submenus.\n * When provided, this element is used to detect outside interactions\n * and hiding elements from assistive technologies instead of the popoverRef.\n */\n groupRef?: RefObject<Element | null>,\n /**\n * Whether the popover is non-modal, i.e. elements outside the popover may be\n * interacted with by assistive technologies.\n *\n * Most popovers should not use this option as it may negatively impact the screen\n * reader experience. Only use with components such as combobox, which are designed\n * to handle this situation carefully.\n */\n isNonModal?: boolean,\n /**\n * Whether pressing the escape key to close the popover should be disabled.\n *\n * Most popovers should not use this option. When set to true, an alternative\n * way to close the popover with a keyboard must be provided.\n *\n * @default false\n */\n isKeyboardDismissDisabled?: boolean,\n /**\n * When user interacts with the argument element outside of the popover 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 popover.\n * By default, onClose will always be called on interaction outside the popover ref.\n */\n shouldCloseOnInteractOutside?: (element: Element) => boolean\n}\n\nexport interface PopoverAria {\n /** Props for the popover element. */\n popoverProps: DOMAttributes,\n /** Props for the popover tip arrow if any. */\n arrowProps: DOMAttributes,\n /** Props to apply to the underlay element, if any. */\n underlayProps: DOMAttributes,\n /** Placement of the popover with respect to the trigger. */\n placement: PlacementAxis | null,\n /** The origin of the target in the overlay's coordinate system. Useful for animations. */\n triggerAnchorPoint: {x: number, y: number} | null\n}\n\n/**\n * Provides the behavior and accessibility implementation for a popover component.\n * A popover is an overlay element positioned relative to a trigger.\n */\nexport function usePopover(props: AriaPopoverProps, state: OverlayTriggerState): PopoverAria {\n let {\n triggerRef,\n popoverRef,\n groupRef,\n isNonModal,\n isKeyboardDismissDisabled,\n shouldCloseOnInteractOutside,\n ...otherProps\n } = props;\n\n let isSubmenu = otherProps['trigger'] === 'SubmenuTrigger';\n\n let {overlayProps, underlayProps} = useOverlay(\n {\n isOpen: state.isOpen,\n onClose: state.close,\n shouldCloseOnBlur: true,\n isDismissable: !isNonModal || isSubmenu,\n isKeyboardDismissDisabled,\n shouldCloseOnInteractOutside\n },\n groupRef ?? popoverRef\n );\n\n let {overlayProps: positionProps, arrowProps, placement, triggerAnchorPoint: origin} = useOverlayPosition({\n ...otherProps,\n targetRef: triggerRef,\n overlayRef: popoverRef,\n isOpen: state.isOpen,\n onClose: isNonModal && !isSubmenu ? state.close : null\n });\n\n usePreventScroll({\n isDisabled: isNonModal || !state.isOpen\n });\n\n useEffect(() => {\n if (state.isOpen && popoverRef.current) {\n if (isNonModal) {\n return keepVisible(groupRef?.current ?? popoverRef.current);\n } else {\n return ariaHideOutside([groupRef?.current ?? popoverRef.current], {shouldUseInert: true});\n }\n }\n }, [isNonModal, state.isOpen, popoverRef, groupRef]);\n\n return {\n popoverProps: mergeProps(overlayProps, positionProps),\n arrowProps,\n underlayProps,\n placement,\n triggerAnchorPoint: origin\n };\n}\n"],"names":[],"version":3,"file":"usePopover.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/overlays",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.29.1",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -26,16 +26,16 @@
|
|
|
26
26
|
"url": "https://github.com/adobe/react-spectrum"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@react-aria/focus": "^3.21.
|
|
30
|
-
"@react-aria/i18n": "^3.12.
|
|
31
|
-
"@react-aria/interactions": "^3.25.
|
|
29
|
+
"@react-aria/focus": "^3.21.1",
|
|
30
|
+
"@react-aria/i18n": "^3.12.12",
|
|
31
|
+
"@react-aria/interactions": "^3.25.5",
|
|
32
32
|
"@react-aria/ssr": "^3.9.10",
|
|
33
|
-
"@react-aria/utils": "^3.30.
|
|
34
|
-
"@react-aria/visually-hidden": "^3.8.
|
|
35
|
-
"@react-stately/overlays": "^3.6.
|
|
36
|
-
"@react-types/button": "^3.
|
|
37
|
-
"@react-types/overlays": "^3.9.
|
|
38
|
-
"@react-types/shared": "^3.
|
|
33
|
+
"@react-aria/utils": "^3.30.1",
|
|
34
|
+
"@react-aria/visually-hidden": "^3.8.27",
|
|
35
|
+
"@react-stately/overlays": "^3.6.19",
|
|
36
|
+
"@react-types/button": "^3.14.0",
|
|
37
|
+
"@react-types/overlays": "^3.9.1",
|
|
38
|
+
"@react-types/shared": "^3.32.0",
|
|
39
39
|
"@swc/helpers": "^0.5.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "ed4815e15c9d1659208fa687e8c3a094879854bb"
|
|
49
49
|
}
|
package/src/ariaHideOutside.ts
CHANGED
|
@@ -56,6 +56,11 @@ export function ariaHideOutside(targets: Element[], options?: AriaHideOutsideOpt
|
|
|
56
56
|
element.setAttribute('aria-hidden', 'true');
|
|
57
57
|
} else {
|
|
58
58
|
element.removeAttribute('aria-hidden');
|
|
59
|
+
if (element instanceof windowObj.HTMLElement) {
|
|
60
|
+
// We only ever call setHidden with hidden = false when the nodeCount is 1 aka
|
|
61
|
+
// we are trying to make the element visible to screen readers again, so remove inert as well
|
|
62
|
+
element.inert = false;
|
|
63
|
+
}
|
|
59
64
|
}
|
|
60
65
|
};
|
|
61
66
|
|
package/src/calculatePosition.ts
CHANGED
|
@@ -67,6 +67,7 @@ export interface PositionResult {
|
|
|
67
67
|
position: Position,
|
|
68
68
|
arrowOffsetLeft?: number,
|
|
69
69
|
arrowOffsetTop?: number,
|
|
70
|
+
triggerAnchorPoint: {x: number, y: number},
|
|
70
71
|
maxHeight: number,
|
|
71
72
|
placement: PlacementAxis
|
|
72
73
|
}
|
|
@@ -126,7 +127,7 @@ function getContainerDimensions(containerNode: Element): Dimensions {
|
|
|
126
127
|
left = visualViewport.offsetLeft;
|
|
127
128
|
}
|
|
128
129
|
} else {
|
|
129
|
-
({width, height, top, left} = getOffset(containerNode));
|
|
130
|
+
({width, height, top, left} = getOffset(containerNode, false));
|
|
130
131
|
scroll.top = containerNode.scrollTop;
|
|
131
132
|
scroll.left = containerNode.scrollLeft;
|
|
132
133
|
totalWidth = width;
|
|
@@ -419,7 +420,8 @@ export function calculatePositionInternal(
|
|
|
419
420
|
// childOffset[crossAxis] + .5 * childOffset[crossSize] = absolute position with respect to the trigger's coordinate system that would place the arrow in the center of the trigger
|
|
420
421
|
// position[crossAxis] - margins[AXIS[crossAxis]] = value use to transform the position to a value with respect to the overlay's coordinate system. A child element's (aka arrow) position absolute's "0"
|
|
421
422
|
// is positioned after the margin of its parent (aka overlay) so we need to subtract it to get the proper coordinate transform
|
|
422
|
-
let
|
|
423
|
+
let origin = childOffset[crossAxis] - position[crossAxis]! - margins[AXIS[crossAxis]];
|
|
424
|
+
let preferredArrowPosition = origin + .5 * childOffset[crossSize];
|
|
423
425
|
|
|
424
426
|
// Min/Max position limits for the arrow with respect to the overlay
|
|
425
427
|
const arrowMinPosition = arrowSize / 2 + arrowBoundaryOffset;
|
|
@@ -436,12 +438,30 @@ export function calculatePositionInternal(
|
|
|
436
438
|
const arrowPositionOverlappingChild = clamp(preferredArrowPosition, arrowOverlappingChildMinEdge, arrowOverlappingChildMaxEdge);
|
|
437
439
|
arrowPosition[crossAxis] = clamp(arrowPositionOverlappingChild, arrowMinPosition, arrowMaxPosition);
|
|
438
440
|
|
|
441
|
+
// If there is an arrow, use that as the origin so that animations are smooth.
|
|
442
|
+
// Otherwise use the target edge.
|
|
443
|
+
({placement, crossPlacement} = placementInfo);
|
|
444
|
+
if (arrowSize) {
|
|
445
|
+
origin = arrowPosition[crossAxis];
|
|
446
|
+
} else if (crossPlacement === 'right') {
|
|
447
|
+
origin += childOffset[crossSize];
|
|
448
|
+
} else if (crossPlacement === 'center') {
|
|
449
|
+
origin += childOffset[crossSize] / 2;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
let crossOrigin = placement === 'left' || placement === 'top' ? overlaySize[size] : 0;
|
|
453
|
+
let triggerAnchorPoint = {
|
|
454
|
+
x: placement === 'top' || placement === 'bottom' ? origin : crossOrigin,
|
|
455
|
+
y: placement === 'left' || placement === 'right' ? origin : crossOrigin
|
|
456
|
+
};
|
|
457
|
+
|
|
439
458
|
return {
|
|
440
459
|
position,
|
|
441
460
|
maxHeight: maxHeight,
|
|
442
461
|
arrowOffsetLeft: arrowPosition.left,
|
|
443
462
|
arrowOffsetTop: arrowPosition.top,
|
|
444
|
-
placement
|
|
463
|
+
placement,
|
|
464
|
+
triggerAnchorPoint
|
|
445
465
|
};
|
|
446
466
|
}
|
|
447
467
|
|
|
@@ -468,7 +488,7 @@ export function calculatePosition(opts: PositionOpts): PositionResult {
|
|
|
468
488
|
let isViewportContainer = container === document.documentElement;
|
|
469
489
|
const containerPositionStyle = window.getComputedStyle(container).position;
|
|
470
490
|
let isContainerPositioned = !!containerPositionStyle && containerPositionStyle !== 'static';
|
|
471
|
-
let childOffset: Offset = isViewportContainer ? getOffset(targetNode) : getPosition(targetNode, container);
|
|
491
|
+
let childOffset: Offset = isViewportContainer ? getOffset(targetNode, false) : getPosition(targetNode, container, false);
|
|
472
492
|
|
|
473
493
|
if (!isViewportContainer) {
|
|
474
494
|
let {marginTop, marginLeft} = window.getComputedStyle(targetNode);
|
|
@@ -476,7 +496,7 @@ export function calculatePosition(opts: PositionOpts): PositionResult {
|
|
|
476
496
|
childOffset.left += parseInt(marginLeft, 10) || 0;
|
|
477
497
|
}
|
|
478
498
|
|
|
479
|
-
let overlaySize: Offset = getOffset(overlayNode);
|
|
499
|
+
let overlaySize: Offset = getOffset(overlayNode, true);
|
|
480
500
|
let margins = getMargins(overlayNode);
|
|
481
501
|
overlaySize.width += (margins.left ?? 0) + (margins.right ?? 0);
|
|
482
502
|
overlaySize.height += (margins.top ?? 0) + (margins.bottom ?? 0);
|
|
@@ -487,7 +507,7 @@ export function calculatePosition(opts: PositionOpts): PositionResult {
|
|
|
487
507
|
// If the container is the HTML element wrapping the body element, the retrieved scrollTop/scrollLeft will be equal to the
|
|
488
508
|
// 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
|
|
489
509
|
// by the container scroll since they are essentially the same containing element and thus in the same coordinate system
|
|
490
|
-
let containerOffsetWithBoundary: Offset = boundaryElement.tagName === 'BODY' ? getOffset(container) : getPosition(container, boundaryElement);
|
|
510
|
+
let containerOffsetWithBoundary: Offset = boundaryElement.tagName === 'BODY' ? getOffset(container, false) : getPosition(container, boundaryElement, false);
|
|
491
511
|
if (container.tagName === 'HTML' && boundaryElement.tagName === 'BODY') {
|
|
492
512
|
containerDimensions.scroll.top = 0;
|
|
493
513
|
containerDimensions.scroll.left = 0;
|
|
@@ -513,8 +533,21 @@ export function calculatePosition(opts: PositionOpts): PositionResult {
|
|
|
513
533
|
);
|
|
514
534
|
}
|
|
515
535
|
|
|
516
|
-
function
|
|
536
|
+
export function getRect(node: Element, ignoreScale: boolean) {
|
|
517
537
|
let {top, left, width, height} = node.getBoundingClientRect();
|
|
538
|
+
|
|
539
|
+
// Use offsetWidth and offsetHeight if this is an HTML element, so that
|
|
540
|
+
// the size is not affected by scale transforms.
|
|
541
|
+
if (ignoreScale && node instanceof node.ownerDocument.defaultView!.HTMLElement) {
|
|
542
|
+
width = node.offsetWidth;
|
|
543
|
+
height = node.offsetHeight;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
return {top, left, width, height};
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
function getOffset(node: Element, ignoreScale: boolean): Offset {
|
|
550
|
+
let {top, left, width, height} = getRect(node, ignoreScale);
|
|
518
551
|
let {scrollTop, scrollLeft, clientTop, clientLeft} = document.documentElement;
|
|
519
552
|
return {
|
|
520
553
|
top: top + scrollTop - clientTop,
|
|
@@ -524,15 +557,14 @@ function getOffset(node: Element): Offset {
|
|
|
524
557
|
};
|
|
525
558
|
}
|
|
526
559
|
|
|
527
|
-
function getPosition(node: Element, parent: Element): Offset {
|
|
560
|
+
function getPosition(node: Element, parent: Element, ignoreScale: boolean): Offset {
|
|
528
561
|
let style = window.getComputedStyle(node);
|
|
529
562
|
let offset: Offset;
|
|
530
563
|
if (style.position === 'fixed') {
|
|
531
|
-
|
|
532
|
-
offset = {top, left, width, height};
|
|
564
|
+
offset = getRect(node, ignoreScale);
|
|
533
565
|
} else {
|
|
534
|
-
offset = getOffset(node);
|
|
535
|
-
let parentOffset = getOffset(parent);
|
|
566
|
+
offset = getOffset(node, ignoreScale);
|
|
567
|
+
let parentOffset = getOffset(parent, ignoreScale);
|
|
536
568
|
let parentStyle = window.getComputedStyle(parent);
|
|
537
569
|
parentOffset.top += (parseInt(parentStyle.borderTopWidth, 10) || 0) - parent.scrollTop;
|
|
538
570
|
parentOffset.left += (parseInt(parentStyle.borderLeftWidth, 10) || 0) - parent.scrollLeft;
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {calculatePosition, PositionResult} from './calculatePosition';
|
|
13
|
+
import {calculatePosition, getRect, PositionResult} from './calculatePosition';
|
|
14
14
|
import {DOMAttributes, RefObject} from '@react-types/shared';
|
|
15
15
|
import {Placement, PlacementAxis, PositionProps} from '@react-types/overlays';
|
|
16
16
|
import {useCallback, useEffect, useRef, useState} from 'react';
|
|
@@ -37,6 +37,10 @@ export interface AriaPositionProps extends PositionProps {
|
|
|
37
37
|
* The ref for the overlay element.
|
|
38
38
|
*/
|
|
39
39
|
overlayRef: RefObject<Element | null>,
|
|
40
|
+
/**
|
|
41
|
+
* The ref for the arrow element.
|
|
42
|
+
*/
|
|
43
|
+
arrowRef?: RefObject<Element | null>,
|
|
40
44
|
/**
|
|
41
45
|
* A ref for the scrollable region within the overlay.
|
|
42
46
|
* @default overlayRef
|
|
@@ -68,6 +72,8 @@ export interface PositionAria {
|
|
|
68
72
|
arrowProps: DOMAttributes,
|
|
69
73
|
/** Placement of the overlay with respect to the overlay trigger. */
|
|
70
74
|
placement: PlacementAxis | null,
|
|
75
|
+
/** The origin of the target in the overlay's coordinate system. Useful for animations. */
|
|
76
|
+
triggerAnchorPoint: {x: number, y: number} | null,
|
|
71
77
|
/** Updates the position of the overlay. */
|
|
72
78
|
updatePosition(): void
|
|
73
79
|
}
|
|
@@ -86,9 +92,10 @@ let visualViewport = typeof document !== 'undefined' ? window.visualViewport : n
|
|
|
86
92
|
export function useOverlayPosition(props: AriaPositionProps): PositionAria {
|
|
87
93
|
let {direction} = useLocale();
|
|
88
94
|
let {
|
|
89
|
-
arrowSize
|
|
95
|
+
arrowSize,
|
|
90
96
|
targetRef,
|
|
91
97
|
overlayRef,
|
|
98
|
+
arrowRef,
|
|
92
99
|
scrollRef = overlayRef,
|
|
93
100
|
placement = 'bottom' as Placement,
|
|
94
101
|
containerPadding = 12,
|
|
@@ -109,6 +116,7 @@ export function useOverlayPosition(props: AriaPositionProps): PositionAria {
|
|
|
109
116
|
placement,
|
|
110
117
|
overlayRef.current,
|
|
111
118
|
targetRef.current,
|
|
119
|
+
arrowRef?.current,
|
|
112
120
|
scrollRef.current,
|
|
113
121
|
containerPadding,
|
|
114
122
|
shouldFlip,
|
|
@@ -181,7 +189,7 @@ export function useOverlayPosition(props: AriaPositionProps): PositionAria {
|
|
|
181
189
|
offset,
|
|
182
190
|
crossOffset,
|
|
183
191
|
maxHeight,
|
|
184
|
-
arrowSize,
|
|
192
|
+
arrowSize: arrowSize ?? (arrowRef?.current ? getRect(arrowRef.current, true).width : 0),
|
|
185
193
|
arrowBoundaryOffset
|
|
186
194
|
});
|
|
187
195
|
|
|
@@ -280,13 +288,16 @@ export function useOverlayPosition(props: AriaPositionProps): PositionAria {
|
|
|
280
288
|
return {
|
|
281
289
|
overlayProps: {
|
|
282
290
|
style: {
|
|
283
|
-
position: 'absolute',
|
|
291
|
+
position: position ? 'absolute' : 'fixed',
|
|
292
|
+
top: !position ? 0 : undefined,
|
|
293
|
+
left: !position ? 0 : undefined,
|
|
284
294
|
zIndex: 100000, // should match the z-index in ModalTrigger
|
|
285
295
|
...position?.position,
|
|
286
296
|
maxHeight: position?.maxHeight ?? '100vh'
|
|
287
297
|
}
|
|
288
298
|
},
|
|
289
299
|
placement: position?.placement ?? null,
|
|
300
|
+
triggerAnchorPoint: position?.triggerAnchorPoint ?? null,
|
|
290
301
|
arrowProps: {
|
|
291
302
|
'aria-hidden': 'true',
|
|
292
303
|
role: 'presentation',
|
package/src/usePopover.ts
CHANGED
|
@@ -29,6 +29,8 @@ export interface AriaPopoverProps extends Omit<AriaPositionProps, 'isOpen' | 'on
|
|
|
29
29
|
* The ref for the popover element.
|
|
30
30
|
*/
|
|
31
31
|
popoverRef: RefObject<Element | null>,
|
|
32
|
+
/** A ref for the popover arrow element. */
|
|
33
|
+
arrowRef?: RefObject<Element | null>,
|
|
32
34
|
/**
|
|
33
35
|
* An optional ref for a group of popovers, e.g. submenus.
|
|
34
36
|
* When provided, this element is used to detect outside interactions
|
|
@@ -70,7 +72,9 @@ export interface PopoverAria {
|
|
|
70
72
|
/** Props to apply to the underlay element, if any. */
|
|
71
73
|
underlayProps: DOMAttributes,
|
|
72
74
|
/** Placement of the popover with respect to the trigger. */
|
|
73
|
-
placement: PlacementAxis | null
|
|
75
|
+
placement: PlacementAxis | null,
|
|
76
|
+
/** The origin of the target in the overlay's coordinate system. Useful for animations. */
|
|
77
|
+
triggerAnchorPoint: {x: number, y: number} | null
|
|
74
78
|
}
|
|
75
79
|
|
|
76
80
|
/**
|
|
@@ -102,7 +106,7 @@ export function usePopover(props: AriaPopoverProps, state: OverlayTriggerState):
|
|
|
102
106
|
groupRef ?? popoverRef
|
|
103
107
|
);
|
|
104
108
|
|
|
105
|
-
let {overlayProps: positionProps, arrowProps, placement} = useOverlayPosition({
|
|
109
|
+
let {overlayProps: positionProps, arrowProps, placement, triggerAnchorPoint: origin} = useOverlayPosition({
|
|
106
110
|
...otherProps,
|
|
107
111
|
targetRef: triggerRef,
|
|
108
112
|
overlayRef: popoverRef,
|
|
@@ -128,6 +132,7 @@ export function usePopover(props: AriaPopoverProps, state: OverlayTriggerState):
|
|
|
128
132
|
popoverProps: mergeProps(overlayProps, positionProps),
|
|
129
133
|
arrowProps,
|
|
130
134
|
underlayProps,
|
|
131
|
-
placement
|
|
135
|
+
placement,
|
|
136
|
+
triggerAnchorPoint: origin
|
|
132
137
|
};
|
|
133
138
|
}
|