Skip to content

Commit 1355830

Browse files
committed
chore: pkg of adjust logic to func
1 parent 15a94cb commit 1355830

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/hooks/useAlign.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,18 @@ export default function useAlign(
240240
const overflow = placementInfo.overflow || {};
241241
const { adjustX, adjustY, shiftX, shiftY } = overflow;
242242

243+
const supportAdjust = (val: boolean | number) => {
244+
if (typeof val === 'boolean') {
245+
return val;
246+
}
247+
return val >= 0;
248+
};
249+
243250
// >>>>>>>>>> Top & Bottom
244251
const nextPopupY = popupRect.y + nextOffsetY;
245252
const nextPopupBottom = nextPopupY + popupHeight;
246253

247-
const needAdjustY = adjustY === true || adjustY >= 0;
254+
const needAdjustY = supportAdjust(adjustY);
248255

249256
// Bottom to Top
250257
if (
@@ -278,7 +285,7 @@ export default function useAlign(
278285
const nextPopupX = popupRect.x + nextOffsetX;
279286
const nextPopupRight = nextPopupX + popupWidth;
280287

281-
const needAdjustX = adjustX === true || adjustX >= 0;
288+
const needAdjustX = supportAdjust(adjustX);
282289

283290
// >>>>> Flip
284291
// Right to Left

0 commit comments

Comments
 (0)