@@ -48,6 +48,13 @@ const builtinPlacements = {
48
48
shiftY : true ,
49
49
} ,
50
50
} ,
51
+ topShift : {
52
+ points : [ 'bc' , 'tc' ] ,
53
+ overflow : {
54
+ shiftX : true ,
55
+ } ,
56
+ htmlRegion : 'visibleFirst' as const ,
57
+ } ,
51
58
bottom : {
52
59
points : [ 'tc' , 'bc' ] ,
53
60
overflow : {
@@ -72,7 +79,24 @@ const builtinPlacements = {
72
79
} ;
73
80
74
81
describe ( 'Trigger.Flip+Shift' , ( ) => {
82
+ let spanRect = { x : 0 , y : 0 , width : 0 , height : 0 } ;
83
+
84
+ beforeEach ( ( ) => {
85
+ spanRect = {
86
+ x : 0 ,
87
+ y : 100 ,
88
+ width : 100 ,
89
+ height : 100 ,
90
+ } ;
91
+
92
+ document . documentElement . scrollLeft = 0 ;
93
+ } ) ;
94
+
75
95
beforeAll ( ( ) => {
96
+ jest
97
+ . spyOn ( document . documentElement , 'scrollWidth' , 'get' )
98
+ . mockReturnValue ( 1000 ) ;
99
+
76
100
// Viewport size
77
101
spyElementPrototypes ( HTMLElement , {
78
102
clientWidth : {
@@ -96,12 +120,7 @@ describe('Trigger.Flip+Shift', () => {
96
120
} ) ;
97
121
spyElementPrototypes ( HTMLSpanElement , {
98
122
getBoundingClientRect ( ) {
99
- return {
100
- x : 0 ,
101
- y : 100 ,
102
- width : 100 ,
103
- height : 100 ,
104
- } ;
123
+ return spanRect ;
105
124
} ,
106
125
} ) ;
107
126
spyElementPrototypes ( HTMLElement , {
@@ -146,4 +165,29 @@ describe('Trigger.Flip+Shift', () => {
146
165
top : '100px' ,
147
166
} ) ;
148
167
} ) ;
168
+
169
+ it ( 'top with visibleFirst region' , async ( ) => {
170
+ spanRect . x = - 1000 ;
171
+ document . documentElement . scrollLeft = 500 ;
172
+
173
+ render (
174
+ < Trigger
175
+ popupVisible
176
+ popupPlacement = "topShift"
177
+ builtinPlacements = { builtinPlacements }
178
+ popup = { < strong > trigger</ strong > }
179
+ >
180
+ < span className = "target" />
181
+ </ Trigger > ,
182
+ ) ;
183
+
184
+ await act ( async ( ) => {
185
+ await Promise . resolve ( ) ;
186
+ } ) ;
187
+
188
+ // Just need check left < 0
189
+ expect ( document . querySelector ( '.rc-trigger-popup' ) ) . toHaveStyle ( {
190
+ left : '-900px' ,
191
+ } ) ;
192
+ } ) ;
149
193
} ) ;
0 commit comments