@@ -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