Skip to content

Commit

Permalink
Merge c04e909 into 627d5c7
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ authored Apr 7, 2023
2 parents 627d5c7 + c04e909 commit f39cdab
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/hooks/useAlign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export default function useAlign(
const visibleR = Math.min(r, visibleArea.right);
const visibleB = Math.min(b, visibleArea.bottom);

return (visibleR - visibleL) * (visibleB - visibleT);
return Math.max(0, (visibleR - visibleL) * (visibleB - visibleT));
}

const originIntersectionVisibleArea = getIntersectionVisibleArea(
Expand Down Expand Up @@ -307,7 +307,7 @@ export default function useAlign(
}

if (
getIntersectionVisibleArea(nextOffsetX, tmpNextOffsetY) >
getIntersectionVisibleArea(nextOffsetX, tmpNextOffsetY) >=
originIntersectionVisibleArea
) {
nextOffsetY = tmpNextOffsetY;
Expand Down Expand Up @@ -335,7 +335,7 @@ export default function useAlign(
}

if (
getIntersectionVisibleArea(nextOffsetX, tmpNextOffsetY) >
getIntersectionVisibleArea(nextOffsetX, tmpNextOffsetY) >=
originIntersectionVisibleArea
) {
nextOffsetY = tmpNextOffsetY;
Expand Down Expand Up @@ -369,7 +369,7 @@ export default function useAlign(
}

if (
getIntersectionVisibleArea(tmpNextOffsetX, nextOffsetY) >
getIntersectionVisibleArea(tmpNextOffsetX, nextOffsetY) >=
originIntersectionVisibleArea
) {
nextOffsetX = tmpNextOffsetX;
Expand Down Expand Up @@ -397,7 +397,7 @@ export default function useAlign(
}

if (
getIntersectionVisibleArea(tmpNextOffsetX, nextOffsetY) >
getIntersectionVisibleArea(tmpNextOffsetX, nextOffsetY) >=
originIntersectionVisibleArea
) {
nextOffsetX = tmpNextOffsetX;
Expand Down
69 changes: 69 additions & 0 deletions tests/flip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,73 @@ describe('Trigger.Align', () => {
bottom: 400,
});
});

// e.g. adjustY + shiftX may make popup out but push back in screen
// which should keep flip
/*
************* Screen
* Popup ********************
************* *
* Target * *
********** *
* *
********************
To:
Screen
********************
********** *
* Target * *
****************** *
* Popup * *
************************
*/
it('out of screen should keep flip', async () => {
spanRect.x = -200;
spanRect.y = 0;

popupRect = {
x: 0,
y: 0,
width: 200,
height: 200,
};

render(
<Trigger
popupVisible
popupPlacement="top"
builtinPlacements={{
top: {
points: ['bc', 'tc'],
overflow: {
shiftX: true,
adjustY: true,
},
},
bottom: {
points: ['tc', 'bc'],
overflow: {
shiftX: true,
adjustY: true,
},
},
}}
popup={<strong>trigger</strong>}
>
<span className="target" />
</Trigger>,
);

await act(async () => {
await Promise.resolve();
});

expect(
document.querySelector('.rc-trigger-popup-placement-bottom'),
).toBeTruthy();
});
});

0 comments on commit f39cdab

Please sign in to comment.