@@ -287,7 +287,7 @@ export default function useAlign(
287287
288288 // Offset
289289 const { offset, targetOffset } = placementInfo ;
290- const [ popupOffsetX , popupOffsetY ] = getNumberOffset ( popupRect , offset ) ;
290+ let [ popupOffsetX , popupOffsetY ] = getNumberOffset ( popupRect , offset ) ;
291291 const [ targetOffsetX , targetOffsetY ] = getNumberOffset (
292292 targetRect ,
293293 targetOffset ,
@@ -417,6 +417,7 @@ export default function useAlign(
417417 ) {
418418 prevFlipRef . current . bt = true ;
419419 nextOffsetY = tmpNextOffsetY ;
420+ popupOffsetY = - popupOffsetY ;
420421
421422 nextAlignInfo . points = [
422423 reversePoints ( popupPoints , 0 ) ,
@@ -462,6 +463,7 @@ export default function useAlign(
462463 ) {
463464 prevFlipRef . current . tb = true ;
464465 nextOffsetY = tmpNextOffsetY ;
466+ popupOffsetY = - popupOffsetY ;
465467
466468 nextAlignInfo . points = [
467469 reversePoints ( popupPoints , 0 ) ,
@@ -514,6 +516,7 @@ export default function useAlign(
514516 ) {
515517 prevFlipRef . current . rl = true ;
516518 nextOffsetX = tmpNextOffsetX ;
519+ popupOffsetX = - popupOffsetX ;
517520
518521 nextAlignInfo . points = [
519522 reversePoints ( popupPoints , 1 ) ,
@@ -559,6 +562,7 @@ export default function useAlign(
559562 ) {
560563 prevFlipRef . current . lr = true ;
561564 nextOffsetX = tmpNextOffsetX ;
565+ popupOffsetX = - popupOffsetX ;
562566
563567 nextAlignInfo . points = [
564568 reversePoints ( popupPoints , 1 ) ,
@@ -576,7 +580,7 @@ export default function useAlign(
576580 if ( typeof numShiftX === 'number' ) {
577581 // Left
578582 if ( nextPopupX < visibleRegionArea . left ) {
579- nextOffsetX -= nextPopupX - visibleRegionArea . left ;
583+ nextOffsetX -= nextPopupX - visibleRegionArea . left - popupOffsetX ;
580584
581585 if ( targetRect . x + targetWidth < visibleRegionArea . left + numShiftX ) {
582586 nextOffsetX +=
@@ -586,7 +590,8 @@ export default function useAlign(
586590
587591 // Right
588592 if ( nextPopupRight > visibleRegionArea . right ) {
589- nextOffsetX -= nextPopupRight - visibleRegionArea . right ;
593+ nextOffsetX -=
594+ nextPopupRight - visibleRegionArea . right - popupOffsetX ;
590595
591596 if ( targetRect . x > visibleRegionArea . right - numShiftX ) {
592597 nextOffsetX += targetRect . x - visibleRegionArea . right + numShiftX ;
@@ -598,8 +603,10 @@ export default function useAlign(
598603 if ( typeof numShiftY === 'number' ) {
599604 // Top
600605 if ( nextPopupY < visibleRegionArea . top ) {
601- nextOffsetY -= nextPopupY - visibleRegionArea . top + popupOffsetY ;
606+ nextOffsetY -= nextPopupY - visibleRegionArea . top - popupOffsetY ;
602607
608+ // When target if far away from visible area
609+ // Stop shift
603610 if ( targetRect . y + targetHeight < visibleRegionArea . top + numShiftY ) {
604611 nextOffsetY +=
605612 targetRect . y - visibleRegionArea . top + targetHeight - numShiftY ;
@@ -608,7 +615,8 @@ export default function useAlign(
608615
609616 // Bottom
610617 if ( nextPopupBottom > visibleRegionArea . bottom ) {
611- nextOffsetY -= nextPopupBottom - visibleRegionArea . bottom - popupOffsetY ;
618+ nextOffsetY -=
619+ nextPopupBottom - visibleRegionArea . bottom - popupOffsetY ;
612620
613621 if ( targetRect . y > visibleRegionArea . bottom - numShiftY ) {
614622 nextOffsetY += targetRect . y - visibleRegionArea . bottom + numShiftY ;
0 commit comments