File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -349,6 +349,12 @@ export class IronListAdapter {
349349 }
350350
351351 this . __previousScrollTop = this . _scrollTop ;
352+
353+ // If the first visible index is not 0 when scrolled to the top,
354+ // add some scroll offset to enable the user to continue scrolling.
355+ if ( this . _scrollTop === 0 && this . firstVisibleIndex !== 0 ) {
356+ this . _scrollTop = 1 ;
357+ }
352358 }
353359
354360 /** @private */
Original file line number Diff line number Diff line change 1+ import { expect } from '@esm-bundle/chai' ;
2+ import { fixtureSync , nextFrame } from '@vaadin/testing-helpers' ;
3+ import { Virtualizer } from '../src/virtualizer.js' ;
4+
5+ describe ( 'virtualizer - variable row height' , ( ) => {
6+ let virtualizer ;
7+ let scrollTarget ;
8+
9+ beforeEach ( ( ) => {
10+ scrollTarget = fixtureSync ( `
11+ <div style="height: 500px; width: 200px;">
12+ <div></div>
13+ </div>
14+ ` ) ;
15+ const scrollContainer = scrollTarget . firstElementChild ;
16+
17+ virtualizer = new Virtualizer ( {
18+ createElements : ( count ) => Array . from ( Array ( count ) ) . map ( ( ) => document . createElement ( 'div' ) ) ,
19+ updateElement : ( el , index ) => {
20+ el . style . height = `${ 30 + index } px` ;
21+ el . textContent = `Item ${ index } ` ;
22+ } ,
23+ scrollTarget,
24+ scrollContainer,
25+ } ) ;
26+
27+ virtualizer . size = 100 ;
28+ } ) ;
29+
30+ it ( 'should be able to scroll back to the top' , async ( ) => {
31+ // Scroll down
32+ scrollTarget . scrollTop = 1000 ;
33+ await nextFrame ( ) ;
34+
35+ // Try scrolling back to the top until the first visible index is 0
36+ let attempts = 100 ;
37+ while ( attempts > 0 && virtualizer . firstVisibleIndex !== 0 ) {
38+ attempts -= 1 ;
39+ scrollTarget . scrollTop = 0 ;
40+ await nextFrame ( ) ;
41+ }
42+
43+ expect ( virtualizer . firstVisibleIndex ) . to . equal ( 0 ) ;
44+ } ) ;
45+ } ) ;
You can’t perform that action at this time.
0 commit comments