Skip to content

Commit 7535a21

Browse files
authored
Merge pull request #7723 from IgniteUI/mkirova/fix-7698-10.0.x
fix(igxGrid): Inject unique instances of the scroll sync service for …
2 parents 9f01eeb + 582a540 commit 7535a21

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

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

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,47 @@ describe('IgxForOf directive -', () => {
11421142
expect(firstInnerDisplayContainer.children[0].textContent).toBe('0');
11431143
});
11441144
});
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+
});
11451186
});
11461187

11471188
class DataGenerator {
@@ -1405,6 +1446,45 @@ export class VerticalVirtualDestroyComponent extends VerticalVirtualComponent {
14051446
public exists = true;
14061447
}
14071448

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+
14081488
/** Only horizontally virtualized component */
14091489
@Component({
14101490
template: `

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export class IgxForOfContext<T> {
6868

6969
}
7070

71-
@Directive({ selector: '[igxFor][igxForOf]' })
71+
@Directive({ selector: '[igxFor][igxForOf]',
72+
providers: [ IgxForOfScrollSyncService ] })
7273
export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestroy, AfterViewInit {
7374

7475
/**

0 commit comments

Comments
 (0)