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

Commit

Permalink
Merge branch 'dev' into project-orgnames
Browse files Browse the repository at this point in the history
  • Loading branch information
HexaField authored Aug 17, 2024
2 parents 4b77f59 + 76cda41 commit d5699d7
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 d5699d7

Please sign in to comment.