@@ -80,8 +80,10 @@ const builtinPlacements = {
8080
8181describe ( 'Trigger.Flip+Shift' , ( ) => {
8282 let spanRect = { x : 0 , y : 0 , left : 0 , top : 0 , width : 0 , height : 0 } ;
83+ let popupHeight = 300 ;
8384
8485 beforeEach ( ( ) => {
86+ popupHeight = 300 ;
8587 spanRect = {
8688 x : 0 ,
8789 y : 100 ,
@@ -118,7 +120,7 @@ describe('Trigger.Flip+Shift', () => {
118120 left : 0 ,
119121 top : 0 ,
120122 width : 100 ,
121- height : 300 ,
123+ height : popupHeight ,
122124 } ;
123125 } ,
124126 } ) ;
@@ -170,6 +172,59 @@ describe('Trigger.Flip+Shift', () => {
170172 } ) ;
171173 } ) ;
172174
175+ it . each ( [
176+ { placement : 'top' , offset : - 4 , targetY : 100 , top : '100px' } ,
177+ { placement : 'bottom' , offset : 4 , targetY : 100 , top : '100px' } ,
178+ { placement : 'top' , offset : - 4 , targetY : 200 , top : '0px' } ,
179+ { placement : 'bottom' , offset : 4 , targetY : 200 , top : '0px' } ,
180+ ] ) (
181+ '$placement 在目标位于 $targetY 时,平移不应被偏移量推回视口外' ,
182+ async ( { placement, offset, targetY, top } ) => {
183+ spanRect . y = targetY ;
184+ spanRect . top = targetY ;
185+
186+ render (
187+ < Trigger
188+ popupVisible
189+ popupPlacement = { placement }
190+ builtinPlacements = { builtinPlacements }
191+ popupAlign = { { offset : [ 0 , offset ] } }
192+ popup = { < strong > 日期面板</ strong > }
193+ >
194+ < span className = "target" />
195+ </ Trigger > ,
196+ ) ;
197+
198+ await act ( async ( ) => {
199+ await Promise . resolve ( ) ;
200+ } ) ;
201+
202+ expect ( document . querySelector ( '.rc-trigger-popup' ) ) . toHaveStyle ( { top } ) ;
203+ } ,
204+ ) ;
205+
206+ it ( '面板高于视口时优先保留顶部内容' , async ( ) => {
207+ popupHeight = 500 ;
208+ render (
209+ < Trigger
210+ popupVisible
211+ popupPlacement = "top"
212+ builtinPlacements = { builtinPlacements }
213+ popup = { < strong > 日期面板</ strong > }
214+ >
215+ < span className = "target" />
216+ </ Trigger > ,
217+ ) ;
218+
219+ await act ( async ( ) => {
220+ await Promise . resolve ( ) ;
221+ } ) ;
222+
223+ expect ( document . querySelector ( '.rc-trigger-popup' ) ) . toHaveStyle ( {
224+ top : '0px' ,
225+ } ) ;
226+ } ) ;
227+
173228 it ( 'top with visibleFirst region' , async ( ) => {
174229 spanRect . x = - 1000 ;
175230 document . documentElement . scrollLeft = 500 ;
0 commit comments