@@ -928,6 +928,34 @@ describe('CdkVirtualScrollViewport', () => {
928928 expect ( testComponent . trackBy ) . toHaveBeenCalled ( ) ;
929929 } ) ) ;
930930 } ) ;
931+
932+ describe ( 'with append only' , ( ) => {
933+ let fixture : ComponentFixture < VirtualScrollWithAppendOnly > ;
934+ let testComponent : VirtualScrollWithAppendOnly ;
935+ let viewport : CdkVirtualScrollViewport ;
936+
937+ beforeEach ( waitForAsync ( ( ) => {
938+ TestBed . configureTestingModule ( {
939+ imports : [ ScrollingModule , CommonModule ] ,
940+ declarations : [ VirtualScrollWithAppendOnly ] ,
941+ } ) . compileComponents ( ) ;
942+ fixture = TestBed . createComponent ( VirtualScrollWithAppendOnly ) ;
943+ testComponent = fixture . componentInstance ;
944+ viewport = testComponent . viewport ;
945+ } ) ) ;
946+
947+ it ( 'should not remove item that have already been rendered' , fakeAsync ( ( ) => {
948+ finishInit ( fixture ) ;
949+ viewport . setRenderedRange ( { start : 100 , end : 200 } ) ;
950+ fixture . detectChanges ( ) ;
951+ flush ( ) ;
952+ viewport . setRenderedRange ( { start : 10 , end : 50 } ) ;
953+ fixture . detectChanges ( ) ;
954+ flush ( ) ;
955+
956+ expect ( viewport . getRenderedRange ( ) ) . toEqual ( { start : 0 , end : 200 } ) ;
957+ } ) ) ;
958+ } ) ;
931959} ) ;
932960
933961
@@ -1182,3 +1210,36 @@ class DelayedInitializationVirtualScroll {
11821210 trackBy = jasmine . createSpy ( 'trackBy' ) . and . callFake ( ( item : unknown ) => item ) ;
11831211 renderVirtualFor = false ;
11841212}
1213+
1214+ @Component ( {
1215+ template : `
1216+ <cdk-virtual-scroll-viewport appendOnly itemSize="50">
1217+ <div class="item" *cdkVirtualFor="let item of items">{{item}}</div>
1218+ </cdk-virtual-scroll-viewport>
1219+ ` ,
1220+ styles : [ `
1221+ .cdk-virtual-scroll-content-wrapper {
1222+ display: flex;
1223+ flex-direction: column;
1224+ }
1225+
1226+ .cdk-virtual-scroll-viewport {
1227+ width: 200px;
1228+ height: 200px;
1229+ background-color: #f5f5f5;
1230+ }
1231+
1232+ .item {
1233+ width: 100%;
1234+ height: 50px;
1235+ box-sizing: border-box;
1236+ border: 1px dashed #ccc;
1237+ }
1238+ ` ] ,
1239+ encapsulation : ViewEncapsulation . None
1240+ } )
1241+ class VirtualScrollWithAppendOnly {
1242+ @ViewChild ( CdkVirtualScrollViewport , { static : true } ) viewport : CdkVirtualScrollViewport ;
1243+ itemSize = 50 ;
1244+ items = Array ( 20000 ) . fill ( 0 ) . map ( ( _ , i ) => i ) ;
1245+ }
0 commit comments