From 331eec5fd710a490fc54354b01340e3e2200ea6c Mon Sep 17 00:00:00 2001 From: Charles Zhao Date: Sun, 23 Oct 2022 23:38:11 +0800 Subject: [PATCH] fix(console): axis calculations in use-position hook --- packages/console/src/hooks/use-position.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/console/src/hooks/use-position.ts b/packages/console/src/hooks/use-position.ts index da6bea222..6a8d88c85 100644 --- a/packages/console/src/hooks/use-position.ts +++ b/packages/console/src/hooks/use-position.ts @@ -196,12 +196,11 @@ export default function usePosition({ const anchorRect = anchorRef.current.getBoundingClientRect(); const overlayRect = overlayRef.current.getBoundingClientRect(); - const { scrollTop, scrollLeft } = document.documentElement; - const verticalTop = anchorRect.y - overlayRect.height + scrollTop - offset.vertical; + const verticalTop = anchorRect.y - overlayRect.height - offset.vertical; const verticalCenter = - anchorRect.y - anchorRect.height / 2 - overlayRect.height / 2 + scrollTop + offset.vertical; - const verticalBottom = anchorRect.y + anchorRect.height + scrollTop + offset.vertical; + anchorRect.y - anchorRect.height / 2 - overlayRect.height / 2 + offset.vertical; + const verticalBottom = anchorRect.y + anchorRect.height + offset.vertical; const verticalPositionMap = { top: verticalTop, @@ -209,11 +208,10 @@ export default function usePosition({ bottom: verticalBottom, }; - const horizontalStart = anchorRect.x + scrollLeft + offset.horizontal; + const horizontalStart = anchorRect.x + offset.horizontal; const horizontalCenter = - anchorRect.x + anchorRect.width / 2 - overlayRect.width / 2 + scrollLeft + offset.horizontal; - const horizontalEnd = - anchorRect.x + anchorRect.width - overlayRect.width + scrollLeft + offset.horizontal; + anchorRect.x + anchorRect.width / 2 - overlayRect.width / 2 + offset.horizontal; + const horizontalEnd = anchorRect.x + anchorRect.width - overlayRect.width + offset.horizontal; const horizontalPositionMap = { start: horizontalStart,