Skip to content

Commit 664a19a

Browse files
committed
fix: menu bottom overflow (#5656)
* fix: menu bottom overflow * fix: add top placement fix
1 parent 79f552d commit 664a19a

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

.changeset/little-buckets-thank.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ultraviolet/ui": patch
3+
---
4+
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: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,15 @@ export const computePositions = ({
309309
arrowWidth +
310310
SPACE
311311

312+
const computedPositionX = !isAligned
313+
? positionX + popupOverflow
314+
: positionX
315+
316+
// To make sure the popup does not overflow (negative X position)
317+
const finalPositionX = isPopupPortalTargetBody
318+
? Math.max(computedPositionX, 0)
319+
: computedPositionX
320+
312321
return {
313322
arrowLeft: isAligned
314323
? childrenWidth / 2 - arrowWidth
@@ -317,11 +326,9 @@ export const computePositions = ({
317326
arrowTransform: '',
318327
placement: 'bottom',
319328
popupInitialPosition: `translate3d(${
320-
!isAligned ? positionX + popupOverflow : positionX
329+
finalPositionX
321330
}px, ${positionY - TOTAL_USED_SPACE}px, 0)`,
322-
popupPosition: `translate3d(${
323-
!isAligned ? positionX + popupOverflow : positionX
324-
}px, ${positionY}px, 0)`,
331+
popupPosition: `translate3d(${finalPositionX}px, ${positionY}px, 0)`,
325332
rotate: 180,
326333
}
327334
}
@@ -448,6 +455,15 @@ export const computePositions = ({
448455
arrowWidth -
449456
SPACE
450457

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+
451467
return {
452468
arrowLeft: isAligned
453469
? childrenWidth / 2 - arrowWidth
@@ -456,11 +472,9 @@ export const computePositions = ({
456472
arrowTransform: '',
457473
placement: 'top',
458474
popupInitialPosition: `translate3d(${
459-
!isAligned ? positionX + popupOverflow : positionX
475+
finalPositionX
460476
}px, ${positionY + TOTAL_USED_SPACE}px, 0)`,
461-
popupPosition: `translate3d(${
462-
!isAligned ? positionX + popupOverflow : positionX
463-
}px, ${positionY}px, 0)`,
477+
popupPosition: `translate3d(${finalPositionX}px, ${positionY}px, 0)`,
464478
rotate: 0,
465479
}
466480
}

0 commit comments

Comments
 (0)