File tree 2 files changed +56
-8
lines changed
2 files changed +56
-8
lines changed Original file line number Diff line number Diff line change @@ -670,12 +670,22 @@ export default function useAlign(
670
670
onPopupAlign ?.( popupEle , nextAlignInfo ) ;
671
671
672
672
// Additional calculate right & bottom position
673
- const offsetX4Right =
673
+ let offsetX4Right =
674
674
popupMirrorRect . right - popupRect . x - ( nextOffsetX + popupRect . width ) ;
675
- const offsetY4Bottom =
675
+ let offsetY4Bottom =
676
676
popupMirrorRect . bottom - popupRect . y - ( nextOffsetY + popupRect . height ) ;
677
677
678
- setOffsetInfo ( {
678
+ if ( scaleX === 1 ) {
679
+ nextOffsetX = Math . round ( nextOffsetX ) ;
680
+ offsetX4Right = Math . round ( offsetX4Right ) ;
681
+ }
682
+
683
+ if ( scaleY === 1 ) {
684
+ nextOffsetY = Math . round ( nextOffsetY ) ;
685
+ offsetY4Bottom = Math . round ( offsetY4Bottom ) ;
686
+ }
687
+
688
+ const nextOffsetInfo = {
679
689
ready : true ,
680
690
offsetX : nextOffsetX / scaleX ,
681
691
offsetY : nextOffsetY / scaleY ,
@@ -686,7 +696,9 @@ export default function useAlign(
686
696
scaleX,
687
697
scaleY,
688
698
align : nextAlignInfo ,
689
- } ) ;
699
+ } ;
700
+
701
+ setOffsetInfo ( nextOffsetInfo ) ;
690
702
}
691
703
} ) ;
692
704
Original file line number Diff line number Diff line change @@ -16,13 +16,18 @@ export const triggerResize = (target: Element) => {
16
16
describe ( 'Trigger.Align' , ( ) => {
17
17
let targetVisible = true ;
18
18
19
+ let rectX = 100 ;
20
+ let rectY = 100 ;
21
+ let rectWidth = 100 ;
22
+ let rectHeight = 100 ;
23
+
19
24
beforeAll ( ( ) => {
20
25
spyElementPrototypes ( HTMLDivElement , {
21
26
getBoundingClientRect : ( ) => ( {
22
- x : 100 ,
23
- y : 100 ,
24
- width : 100 ,
25
- height : 100 ,
27
+ x : rectX ,
28
+ y : rectY ,
29
+ width : rectWidth ,
30
+ height : rectHeight ,
26
31
right : 200 ,
27
32
bottom : 200 ,
28
33
} ) ,
@@ -42,6 +47,12 @@ describe('Trigger.Align', () => {
42
47
43
48
beforeEach ( ( ) => {
44
49
targetVisible = true ;
50
+
51
+ rectX = 100 ;
52
+ rectY = 100 ;
53
+ rectWidth = 100 ;
54
+ rectHeight = 100 ;
55
+
45
56
jest . useFakeTimers ( ) ;
46
57
} ) ;
47
58
@@ -258,4 +269,29 @@ describe('Trigger.Align', () => {
258
269
bottom : `100px` ,
259
270
} ) ;
260
271
} ) ;
272
+
273
+ it ( 'round when decimal precision' , async ( ) => {
274
+ rectX = 22.6 ;
275
+ rectY = 33.4 ;
276
+ rectWidth = 33.7 ;
277
+ rectHeight = 55.9 ;
278
+
279
+ render (
280
+ < Trigger
281
+ popupVisible
282
+ popup = { < span className = "bamboo" /> }
283
+ popupAlign = { {
284
+ points : [ 'tl' , 'bl' ] ,
285
+ } }
286
+ >
287
+ < div />
288
+ </ Trigger > ,
289
+ ) ;
290
+
291
+ await awaitFakeTimer ( ) ;
292
+
293
+ expect ( document . querySelector ( '.rc-trigger-popup' ) ) . toHaveStyle ( {
294
+ top : `56px` ,
295
+ } ) ;
296
+ } ) ;
261
297
} ) ;
You can’t perform that action at this time.
0 commit comments