Skip to content

Commit b5c7026

Browse files
committed
update test case
1 parent a7847b7 commit b5c7026

3 files changed

Lines changed: 589 additions & 14 deletions

File tree

src/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,17 +514,17 @@ export function generateTrigger(
514514
return;
515515
}
516516

517-
const nextInSafeArea = isInSafeHoverArea({
517+
const inSafeHoverArea = isInSafeHoverArea({
518518
clientX: mouseEvent.clientX,
519519
clientY: mouseEvent.clientY,
520-
originX,
521-
originY,
520+
originX: originX,
521+
originY: originX,
522522
target: nextTargetEle,
523523
popup: nextPopupEle,
524524
align: alignInfo,
525525
});
526526

527-
if (nextInSafeArea) {
527+
if (inSafeHoverArea) {
528528
triggerOpen(false, mouseLeaveDelay);
529529
} else {
530530
stopSafeHoverMonitor();

src/safeHover.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ type Polygon = Point[];
55
type Side = 'top' | 'bottom' | 'left' | 'right';
66

77
interface Rect {
8-
x: number;
9-
y: number;
108
width: number;
119
height: number;
1210
top: number;
@@ -32,8 +30,8 @@ function isPointInPolygon(point: Point, polygon: Polygon) {
3230
const length = polygon.length;
3331

3432
for (let i = 0, j = length - 1; i < length; j = i++) {
35-
const [xi, yi] = polygon[i] || [0, 0];
36-
const [xj, yj] = polygon[j] || [0, 0];
33+
const [xi, yi] = polygon[i];
34+
const [xj, yj] = polygon[j];
3735
const intersect =
3836
yi >= y !== yj >= y && x <= ((xj - xi) * (y - yi)) / (yj - yi) + xi;
3937

@@ -56,14 +54,11 @@ function isInside(point: Point, rect: Rect) {
5654

5755
function getRect(element: HTMLElement): Rect {
5856
const rect = element.getBoundingClientRect();
59-
const left = rect.left ?? rect.x;
60-
const top = rect.top ?? rect.y;
57+
const { left, top } = rect;
6158
const width = rect.width;
6259
const height = rect.height;
6360

6461
return {
65-
x: rect.x ?? left,
66-
y: rect.y ?? top,
6762
width,
6863
height,
6964
left,
@@ -220,8 +215,6 @@ export function isInSafeHoverArea(options: SafeHoverAreaOptions) {
220215
[popupRect.left + 1, bottom],
221216
];
222217
break;
223-
default:
224-
break;
225218
}
226219

227220
if (isPointInPolygon(clientPoint, rectPoly)) {

0 commit comments

Comments
 (0)