File tree 2 files changed +51
-0
lines changed
2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 163
163
start : newStart ,
164
164
end : newEnd
165
165
} ) ;
166
+
167
+ if ( newStart < start ) {
168
+ let d = 0 ;
169
+
170
+ for ( let i = newStart ; i < start ; i += 1 ) {
171
+ const expectedHeight = this . heightMap [ i ] ;
172
+ const actualHeight = this . rows [ i - newStart ] . offsetHeight ;
173
+
174
+ d += actualHeight - expectedHeight ;
175
+ }
176
+
177
+ this . refs . viewport . scrollTo ( 0 , this . refs . viewport . scrollTop + d ) ;
178
+ }
166
179
}
167
180
}
168
181
} ;
Original file line number Diff line number Diff line change @@ -260,5 +260,43 @@ test('updates when items change from an empty list', t => {
260
260
list . destroy ( ) ;
261
261
} ) ;
262
262
263
+ test ( 'handles unexpected height changes when scrolling up' , async t => {
264
+ const Row = svelte . create ( `
265
+ <div style="height: {rowHeight}px;">test</div>
266
+ ` ) ;
267
+
268
+ const list = new VirtualList ( {
269
+ target,
270
+ data : {
271
+ items : Array ( 20 ) . fill ( ) . map ( ( ) => ( { } ) ) ,
272
+ component : Row ,
273
+ height : '500px' ,
274
+ rowHeight : 50
275
+ }
276
+ } ) ;
277
+
278
+ const { viewport } = list . refs ;
279
+
280
+ await scroll ( viewport , 500 ) ;
281
+ assert . equal ( viewport . scrollTop , 500 ) ;
282
+
283
+ list . set ( { rowHeight : 100 } ) ;
284
+ await scroll ( viewport , 475 ) ;
285
+ assert . equal ( viewport . scrollTop , 525 ) ;
286
+
287
+ list . destroy ( ) ;
288
+ } ) ;
289
+
290
+ function scroll ( element , y ) {
291
+ return new Promise ( fulfil => {
292
+ element . addEventListener ( 'scroll' , function handler ( ) {
293
+ element . removeEventListener ( 'scroll' , handler ) ;
294
+ fulfil ( ) ;
295
+ } ) ;
296
+
297
+ element . scrollTo ( 0 , y ) ;
298
+ } ) ;
299
+ }
300
+
263
301
// this allows us to close puppeteer once tests have completed
264
302
window . done = done ;
You can’t perform that action at this time.
0 commit comments