@@ -1142,6 +1142,47 @@ describe('IgxForOf directive -', () => {
1142
1142
expect ( firstInnerDisplayContainer . children [ 0 ] . textContent ) . toBe ( '0' ) ;
1143
1143
} ) ;
1144
1144
} ) ;
1145
+
1146
+ describe ( 'on create new instance' , ( ) => {
1147
+ let fix : ComponentFixture < VerticalVirtualCreateComponent > ;
1148
+
1149
+ configureTestSuite ( ) ;
1150
+ beforeAll ( async ( ( ) => {
1151
+ TestBed . configureTestingModule ( {
1152
+ declarations : [
1153
+ VerticalVirtualCreateComponent
1154
+ ] ,
1155
+ imports : [ IgxForOfModule ] ,
1156
+ providers : [ { provide : NgZone , useFactory : ( ) => zone = new TestNgZone ( ) } ]
1157
+ } ) . compileComponents ( ) ;
1158
+ } ) ) ;
1159
+
1160
+ beforeEach ( ( ) => {
1161
+ fix = TestBed . createComponent ( VerticalVirtualCreateComponent ) ;
1162
+ fix . componentInstance . data = dg . generateVerticalData ( fix . componentInstance . cols ) ;
1163
+ fix . componentRef . hostView . detectChanges ( ) ;
1164
+ fix . detectChanges ( ) ;
1165
+
1166
+ } ) ;
1167
+
1168
+ it ( 'should reset scroll position if new component is created.' , async ( ) => {
1169
+ const scrollComponent = fix . debugElement . query ( By . css ( VERTICAL_SCROLLER ) ) . componentInstance ;
1170
+ expect ( scrollComponent . scrollAmount ) . toBe ( 0 ) ;
1171
+ expect ( scrollComponent . destroyed ) . toBeFalsy ( ) ;
1172
+
1173
+ scrollComponent . nativeElement . scrollTop = 500 ;
1174
+ fix . detectChanges ( ) ;
1175
+ await wait ( 100 ) ;
1176
+ fix . detectChanges ( ) ;
1177
+ expect ( scrollComponent . scrollAmount ) . toBe ( 500 ) ;
1178
+
1179
+ fix . componentInstance . exists = true ;
1180
+ fix . detectChanges ( ) ;
1181
+ await wait ( ) ;
1182
+ const secondForOf = fix . componentInstance . secondForOfDir ;
1183
+ expect ( secondForOf . state . startIndex ) . toBe ( 0 ) ;
1184
+ } ) ;
1185
+ } ) ;
1145
1186
} ) ;
1146
1187
1147
1188
class DataGenerator {
@@ -1405,6 +1446,45 @@ export class VerticalVirtualDestroyComponent extends VerticalVirtualComponent {
1405
1446
public exists = true ;
1406
1447
}
1407
1448
1449
+ @Component ( {
1450
+ template : `
1451
+ <div #container [style.width]='width' [style.height]='height'>
1452
+ <ng-template #scrollContainer igxFor let-rowData [igxForOf]="data"
1453
+ [igxForScrollOrientation]="'vertical'"
1454
+ [igxForContainerSize]='height'
1455
+ [igxForItemSize]='itemSize'>
1456
+ <div [style.display]="'flex'" [style.height]="rowData.height || itemSize || '50px'">
1457
+ <div [style.min-width]=cols[0].width>{{rowData['1']}}</div>
1458
+ <div [style.min-width]=cols[1].width>{{rowData['2']}}</div>
1459
+ <div [style.min-width]=cols[2].width>{{rowData['3']}}</div>
1460
+ <div [style.min-width]=cols[3].width>{{rowData['4']}}</div>
1461
+ <div [style.min-width]=cols[4].width>{{rowData['5']}}</div>
1462
+ </div>
1463
+ </ng-template>
1464
+ </div>
1465
+ <div *ngIf='exists' #container [style.width]='width' [style.height]='height'>
1466
+ <ng-template #scrollContainer2 igxFor let-rowData [igxForOf]="data"
1467
+ [igxForScrollOrientation]="'vertical'"
1468
+ [igxForContainerSize]='height'
1469
+ [igxForItemSize]='itemSize'>
1470
+ <div [style.display]="'flex'" [style.height]="rowData.height || itemSize || '50px'">
1471
+ <div [style.min-width]=cols[0].width>{{rowData['1']}}</div>
1472
+ <div [style.min-width]=cols[1].width>{{rowData['2']}}</div>
1473
+ <div [style.min-width]=cols[2].width>{{rowData['3']}}</div>
1474
+ <div [style.min-width]=cols[3].width>{{rowData['4']}}</div>
1475
+ <div [style.min-width]=cols[4].width>{{rowData['5']}}</div>
1476
+ </div>
1477
+ </ng-template>
1478
+ </div>
1479
+ `
1480
+ } )
1481
+ export class VerticalVirtualCreateComponent extends VerticalVirtualComponent {
1482
+ public exists = false ;
1483
+
1484
+ @ViewChild ( 'scrollContainer2' , { read : IgxForOfDirective , static : false } )
1485
+ public secondForOfDir : IgxForOfDirective < any > ;
1486
+ }
1487
+
1408
1488
/** Only horizontally virtualized component */
1409
1489
@Component ( {
1410
1490
template : `
0 commit comments