@@ -287,7 +287,7 @@ export default function useAlign(
287
287
288
288
// Offset
289
289
const { offset, targetOffset } = placementInfo ;
290
- const [ popupOffsetX , popupOffsetY ] = getNumberOffset ( popupRect , offset ) ;
290
+ let [ popupOffsetX , popupOffsetY ] = getNumberOffset ( popupRect , offset ) ;
291
291
const [ targetOffsetX , targetOffsetY ] = getNumberOffset (
292
292
targetRect ,
293
293
targetOffset ,
@@ -417,6 +417,7 @@ export default function useAlign(
417
417
) {
418
418
prevFlipRef . current . bt = true ;
419
419
nextOffsetY = tmpNextOffsetY ;
420
+ popupOffsetY = - popupOffsetY ;
420
421
421
422
nextAlignInfo . points = [
422
423
reversePoints ( popupPoints , 0 ) ,
@@ -462,6 +463,7 @@ export default function useAlign(
462
463
) {
463
464
prevFlipRef . current . tb = true ;
464
465
nextOffsetY = tmpNextOffsetY ;
466
+ popupOffsetY = - popupOffsetY ;
465
467
466
468
nextAlignInfo . points = [
467
469
reversePoints ( popupPoints , 0 ) ,
@@ -514,6 +516,7 @@ export default function useAlign(
514
516
) {
515
517
prevFlipRef . current . rl = true ;
516
518
nextOffsetX = tmpNextOffsetX ;
519
+ popupOffsetX = - popupOffsetX ;
517
520
518
521
nextAlignInfo . points = [
519
522
reversePoints ( popupPoints , 1 ) ,
@@ -559,6 +562,7 @@ export default function useAlign(
559
562
) {
560
563
prevFlipRef . current . lr = true ;
561
564
nextOffsetX = tmpNextOffsetX ;
565
+ popupOffsetX = - popupOffsetX ;
562
566
563
567
nextAlignInfo . points = [
564
568
reversePoints ( popupPoints , 1 ) ,
@@ -576,7 +580,7 @@ export default function useAlign(
576
580
if ( typeof numShiftX === 'number' ) {
577
581
// Left
578
582
if ( nextPopupX < visibleRegionArea . left ) {
579
- nextOffsetX -= nextPopupX - visibleRegionArea . left ;
583
+ nextOffsetX -= nextPopupX - visibleRegionArea . left - popupOffsetX ;
580
584
581
585
if ( targetRect . x + targetWidth < visibleRegionArea . left + numShiftX ) {
582
586
nextOffsetX +=
@@ -586,7 +590,8 @@ export default function useAlign(
586
590
587
591
// Right
588
592
if ( nextPopupRight > visibleRegionArea . right ) {
589
- nextOffsetX -= nextPopupRight - visibleRegionArea . right ;
593
+ nextOffsetX -=
594
+ nextPopupRight - visibleRegionArea . right - popupOffsetX ;
590
595
591
596
if ( targetRect . x > visibleRegionArea . right - numShiftX ) {
592
597
nextOffsetX += targetRect . x - visibleRegionArea . right + numShiftX ;
@@ -598,8 +603,10 @@ export default function useAlign(
598
603
if ( typeof numShiftY === 'number' ) {
599
604
// Top
600
605
if ( nextPopupY < visibleRegionArea . top ) {
601
- nextOffsetY -= nextPopupY - visibleRegionArea . top + popupOffsetY ;
606
+ nextOffsetY -= nextPopupY - visibleRegionArea . top - popupOffsetY ;
602
607
608
+ // When target if far away from visible area
609
+ // Stop shift
603
610
if ( targetRect . y + targetHeight < visibleRegionArea . top + numShiftY ) {
604
611
nextOffsetY +=
605
612
targetRect . y - visibleRegionArea . top + targetHeight - numShiftY ;
@@ -608,7 +615,8 @@ export default function useAlign(
608
615
609
616
// Bottom
610
617
if ( nextPopupBottom > visibleRegionArea . bottom ) {
611
- nextOffsetY -= nextPopupBottom - visibleRegionArea . bottom - popupOffsetY ;
618
+ nextOffsetY -=
619
+ nextPopupBottom - visibleRegionArea . bottom - popupOffsetY ;
612
620
613
621
if ( targetRect . y > visibleRegionArea . bottom - numShiftY ) {
614
622
nextOffsetY += targetRect . y - visibleRegionArea . bottom + numShiftY ;
0 commit comments