Skip to content

Commit 6f4d382

Browse files
authored
Merge branch '9.0.x' into sstoychev/ref-int-tests-90
2 parents 36e5f8f + 5bb752a commit 6f4d382

File tree

4 files changed

+78
-3
lines changed

4 files changed

+78
-3
lines changed

projects/igniteui-angular/src/lib/directives/for-of/for_of.directive.spec.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ describe('IgxForOf directive -', () => {
197197
horizontalScroller = fix.nativeElement.querySelector('igx-horizontal-virtual-helper');
198198
});
199199

200+
200201
it('should initialize directive with vertical virtualization', async () => {
201202
expect(displayContainer).not.toBeNull();
202203
expect(verticalScroller).not.toBeNull();
@@ -1088,6 +1089,57 @@ describe('IgxForOf directive -', () => {
10881089
}
10891090
});
10901091
});
1092+
1093+
describe('on destroy', () => {
1094+
let fix: ComponentFixture<VerticalVirtualDestroyComponent>;
1095+
1096+
configureTestSuite();
1097+
beforeAll(async(() => {
1098+
TestBed.configureTestingModule({
1099+
declarations: [
1100+
TestIgxForOfDirective,
1101+
VerticalVirtualDestroyComponent
1102+
],
1103+
imports: [IgxForOfModule],
1104+
providers: [{ provide: NgZone, useFactory: () => zone = new TestNgZone() }]
1105+
}).compileComponents();
1106+
}));
1107+
1108+
beforeEach(() => {
1109+
fix = TestBed.createComponent(VerticalVirtualDestroyComponent);
1110+
fix.componentInstance.data = dg.generateVerticalData(fix.componentInstance.cols);
1111+
fix.componentRef.hostView.detectChanges();
1112+
fix.detectChanges();
1113+
});
1114+
it('should reset scroll position if component is destroyed and recreated.', async () => {
1115+
let scrollComponent = fix.debugElement.query(By.css(VERTICAL_SCROLLER)).componentInstance;
1116+
expect(scrollComponent.scrollAmount).toBe(0);
1117+
expect(scrollComponent.destroyed).toBeFalsy();
1118+
1119+
scrollComponent.nativeElement.scrollTop = 500;
1120+
fix.detectChanges();
1121+
await wait();
1122+
expect(scrollComponent.scrollAmount).toBe(500);
1123+
1124+
fix.componentInstance.exists = false;
1125+
fix.detectChanges();
1126+
await wait();
1127+
1128+
expect(scrollComponent.destroyed).toBeTruthy();
1129+
1130+
fix.componentInstance.exists = true;
1131+
fix.detectChanges();
1132+
await wait();
1133+
1134+
scrollComponent = fix.debugElement.query(By.css(VERTICAL_SCROLLER)).componentInstance;
1135+
expect(scrollComponent.scrollAmount).toBe(0);
1136+
expect(scrollComponent.destroyed).toBeFalsy();
1137+
1138+
displayContainer = fix.nativeElement.querySelector(DISPLAY_CONTAINER);
1139+
const firstInnerDisplayContainer = displayContainer.children[0];
1140+
expect(firstInnerDisplayContainer.children[0].textContent).toBe('0');
1141+
});
1142+
});
10911143
});
10921144

10931145
class DataGenerator {
@@ -1329,6 +1381,28 @@ export class VerticalVirtualComponent extends VirtualComponent {
13291381
public itemSize = '50px';
13301382
}
13311383

1384+
@Component({
1385+
template: `
1386+
<div *ngIf='exists' #container [style.width]='width' [style.height]='height'>
1387+
<ng-template #scrollContainer igxForTest let-rowData [igxForOf]="data"
1388+
[igxForScrollOrientation]="'vertical'"
1389+
[igxForContainerSize]='height'
1390+
[igxForItemSize]='itemSize'>
1391+
<div [style.display]="'flex'" [style.height]="rowData.height || itemSize || '50px'">
1392+
<div [style.min-width]=cols[0].width>{{rowData['1']}}</div>
1393+
<div [style.min-width]=cols[1].width>{{rowData['2']}}</div>
1394+
<div [style.min-width]=cols[2].width>{{rowData['3']}}</div>
1395+
<div [style.min-width]=cols[3].width>{{rowData['4']}}</div>
1396+
<div [style.min-width]=cols[4].width>{{rowData['5']}}</div>
1397+
</div>
1398+
</ng-template>
1399+
</div>
1400+
`
1401+
})
1402+
export class VerticalVirtualDestroyComponent extends VerticalVirtualComponent {
1403+
public exists = true;
1404+
}
1405+
13321406
/** Only horizontally virtualized component */
13331407
@Component({
13341408
template: `

projects/igniteui-angular/src/lib/directives/for-of/for_of.directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
390390
this.scrollComponent = this.syncScrollService.getScrollMaster(this.igxForScrollOrientation);
391391
this.state.chunkSize = this._calculateChunkSize();
392392
this.dc.instance.notVirtual = !(this.igxForContainerSize && this.state.chunkSize < this.igxForOf.length);
393-
if (this.scrollComponent) {
393+
if (this.scrollComponent && !this.scrollComponent.destroyed) {
394394
this.state.startIndex = Math.min(this.getIndexAt(this.scrollPosition, this.sizesCache, 0),
395395
this.igxForOf.length - this.state.chunkSize);
396396
}

src/app/list-performance/list-performance.sample.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ <h4 class="sample-title">Performance sample</h4>
1313
<igx-icon>clear</igx-icon>
1414
</igx-suffix>
1515
</igx-input-group>
16-
16+
<button igxButton (click)='showList = !showList'>Toggle List</button>
1717
<igx-card>
18-
<igx-list>
18+
<igx-list *ngIf='showList'>
1919
<igx-list-item [isHeader]="true">Contacts</igx-list-item>
2020
<div class="virtualized-items" [style.height]="'500px'" [style.overflow]="'hidden'" [style.position]="'relative'">
2121
<igx-list-item igxRipple="pink" igxRippleTarget=".igx-list__item" *igxFor="let item of data | igxFilter: fo1; scrollOrientation : 'vertical'; containerSize: '500px'; itemSize: '56px'">

src/app/list-performance/list-performance.sample.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { IgxFilterOptions } from 'igniteui-angular';
99
export class ListPerformanceSampleComponent {
1010
search1: string;
1111
options = {};
12+
showList = true;
1213

1314
data = [{
1415
key: 1,

0 commit comments

Comments
 (0)