Skip to content

Commit b368da1

Browse files
committed
fix: add top placement fix
1 parent e88a533 commit b368da1

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

.changeset/little-buckets-thank.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@ultraviolet/ui": patch
33
---
44

5-
`Menu` & `Popup`: when `placement='bottom'`, avoid negative values for "translate3d" to prevent negative positioning/x-overflow
5+
`Menu` & `Popup`: when `placement='bottom'` or `placement='top'`, avoid negative values for "translate3d" to prevent negative positioning/x-overflow

packages/ui/src/components/Popup/helpers.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,15 @@ export const computePositions = ({
455455
arrowWidth -
456456
SPACE
457457

458+
const computedPositionX = !isAligned
459+
? positionX + popupOverflow
460+
: positionX
461+
462+
// To make sure the popup does not overflow (negative X position)
463+
const finalPositionX = isPopupPortalTargetBody
464+
? Math.max(computedPositionX, 0)
465+
: computedPositionX
466+
458467
return {
459468
arrowLeft: isAligned
460469
? childrenWidth / 2 - arrowWidth
@@ -463,11 +472,9 @@ export const computePositions = ({
463472
arrowTransform: '',
464473
placement: 'top',
465474
popupInitialPosition: `translate3d(${
466-
!isAligned ? positionX + popupOverflow : positionX
475+
finalPositionX
467476
}px, ${positionY + TOTAL_USED_SPACE}px, 0)`,
468-
popupPosition: `translate3d(${
469-
!isAligned ? positionX + popupOverflow : positionX
470-
}px, ${positionY}px, 0)`,
477+
popupPosition: `translate3d(${finalPositionX}px, ${positionY}px, 0)`,
471478
rotate: 0,
472479
}
473480
}

0 commit comments

Comments
 (0)