Skip to content

Commit ad3d5e6

Browse files
committed
fix: DOMRect value issues
1 parent 7984a14 commit ad3d5e6

File tree

6 files changed

+39
-3
lines changed

6 files changed

+39
-3
lines changed

src/hooks/useAlign.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,11 @@ export default function useAlign(
212212
};
213213
} else {
214214
const rect = target.getBoundingClientRect();
215+
rect.x = rect.x || rect.left;
216+
rect.y = rect.y || rect.top
215217
targetRect = {
216-
x: rect.x || rect.left,
217-
y: rect.y || rect.top,
218+
x: rect.x,
219+
y: rect.y,
218220
width: rect.width,
219221
height: rect.height,
220222
};

tests/align.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ describe('Trigger.Align', () => {
2626
getBoundingClientRect: () => ({
2727
x: rectX,
2828
y: rectY,
29+
left: rectX,
30+
top: rectY,
2931
width: rectWidth,
3032
height: rectHeight,
3133
right: 200,

tests/arrow.test.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ describe('Trigger.Arrow', () => {
5353
() => ({
5454
x: 200,
5555
y: 200,
56+
left: 200,
57+
top: 200,
5658
width: 100,
5759
height: 50,
5860
}),

tests/flip-visibleFirst.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,26 @@ describe('Trigger.VisibleFirst', () => {
5656
let containerRect = {
5757
x: 0,
5858
y: 0,
59+
left: 0,
60+
top: 0,
5961
width: 100,
6062
height: 100,
6163
};
6264

6365
let targetRect = {
6466
x: 0,
6567
y: 0,
68+
left: 0,
69+
top: 0,
6670
width: 1,
6771
height: 1,
6872
};
6973

7074
let popupRect = {
7175
x: 0,
7276
y: 0,
77+
left: 0,
78+
top: 0,
7379
width: 100,
7480
height: 100,
7581
};
@@ -84,18 +90,24 @@ describe('Trigger.VisibleFirst', () => {
8490
containerRect = {
8591
x: 0,
8692
y: 0,
93+
left: 0,
94+
top: 0,
8795
width: 100,
8896
height: 100,
8997
};
9098
targetRect = {
9199
x: 250,
92100
y: 250,
101+
left: 250,
102+
top: 250,
93103
width: 1,
94104
height: 1,
95105
};
96106
popupRect = {
97107
x: 0,
98108
y: 0,
109+
left: 0,
110+
top: 0,
99111
width: 100,
100112
height: 100,
101113
};

tests/flip.test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,17 @@ describe('Trigger.Align', () => {
5858
let spanRect = {
5959
x: 0,
6060
y: 0,
61+
left: 0,
62+
top: 0,
6163
width: 1,
6264
height: 1,
6365
};
6466

6567
let popupRect = {
6668
x: 0,
6769
y: 0,
70+
left: 0,
71+
top: 0,
6872
width: 100,
6973
height: 100,
7074
};
@@ -112,12 +116,16 @@ describe('Trigger.Align', () => {
112116
spanRect = {
113117
x: 0,
114118
y: 0,
119+
left: 0,
120+
top: 0,
115121
width: 1,
116122
height: 1,
117123
};
118124
popupRect = {
119125
x: 0,
120126
y: 0,
127+
left: 0,
128+
top: 0,
121129
width: 100,
122130
height: 100,
123131
};
@@ -253,6 +261,8 @@ describe('Trigger.Align', () => {
253261
popupRect = {
254262
x: 100,
255263
y: 1,
264+
left: 100,
265+
top: 1,
256266
width: 100,
257267
height: 100,
258268
};
@@ -339,6 +349,8 @@ describe('Trigger.Align', () => {
339349
({
340350
x: 100,
341351
y: 100,
352+
left: 100,
353+
top: 100,
342354
width: 300,
343355
height: 300,
344356
} as any);
@@ -384,6 +396,8 @@ describe('Trigger.Align', () => {
384396
popupRect = {
385397
x: 0,
386398
y: 0,
399+
left: 0,
400+
top: 0,
387401
width: 200,
388402
height: 200,
389403
};

tests/flipShift.test.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,14 @@ const builtinPlacements = {
7979
};
8080

8181
describe('Trigger.Flip+Shift', () => {
82-
let spanRect = { x: 0, y: 0, width: 0, height: 0 };
82+
let spanRect = { x: 0, y: 0, left: 0, top: 0, width: 0, height: 0 };
8383

8484
beforeEach(() => {
8585
spanRect = {
8686
x: 0,
8787
y: 100,
88+
left: 0,
89+
top: 100,
8890
width: 100,
8991
height: 100,
9092
};
@@ -113,6 +115,8 @@ describe('Trigger.Flip+Shift', () => {
113115
return {
114116
x: 0,
115117
y: 0,
118+
left: 0,
119+
top: 0,
116120
width: 100,
117121
height: 300,
118122
};

0 commit comments

Comments
 (0)