Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
[IR-3773]: fix calculateAndApplyOffset regression (#10939)
Browse files Browse the repository at this point in the history
* reposition for topOverflow in calculateAndApplyOffset

* rm popupRef dependency

---------

Co-authored-by: Aditya Mitra <55396651+aditya-mitra@users.noreply.github.com>
  • Loading branch information
dtlehrer and aditya-mitra authored Aug 17, 2024
1 parent 64f7afd commit 76cda41
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/common/src/utils/offsets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,21 @@ export const calculateAndApplyYOffset = (element: HTMLElement | null, additional
const popupBounds = getBounds(element)
const viewportBounds = getViewportBounds(new Bounds())

const overflowTop = viewportBounds.top - (popupBounds?.top ?? 0)
const overflowBottom =
(popupBounds?.top ?? 0) + (popupBounds?.height ?? 0) - (viewportBounds.top + viewportBounds.height)

let offsetY = 0

if (overflowBottom > 0) {
offsetY = -(popupBounds?.height ?? 0) + additionalOffset
if (overflowTop > 0) {
// popup is overflowing at the top, move it down
offsetY = overflowTop
} else if (overflowBottom > 0) {
// popup is overflowing at the bottom, move it up
offsetY = -overflowBottom
}

offsetY += additionalOffset

element.style.transform = `translateY(${offsetY}px)`
}

0 comments on commit 76cda41

Please sign in to comment.