Skip to content

Commit d2a69cc

Browse files
authored
Merge branch 'master' into angular-11
2 parents 2a0c2a1 + dc83c5c commit d2a69cc

File tree

6 files changed

+121
-9
lines changed

6 files changed

+121
-9
lines changed

projects/igniteui-angular/src/lib/directives/for-of/base.helper.component.ts

+36-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ import {
66
ChangeDetectorRef,
77
OnDestroy,
88
Directive,
9-
AfterViewInit
9+
AfterViewInit,
10+
Inject,
11+
NgZone
1012
} from '@angular/core';
13+
import { DOCUMENT } from '@angular/common';
14+
import { Subject } from 'rxjs';
15+
import { takeUntil, throttleTime } from 'rxjs/operators';
16+
import { resizeObservable, isIE } from '../../core/utils';
1117

1218
@Directive({
1319
selector: '[igxVirtualHelperBase]'
@@ -21,16 +27,25 @@ export class VirtualHelperBaseDirective implements OnDestroy, AfterViewInit {
2127

2228
private _afterViewInit = false;
2329
private _scrollNativeSize: number;
30+
private _detached = false;
31+
protected destroy$ = new Subject<any>();
32+
2433

2534
ngAfterViewInit() {
2635
this._afterViewInit = true;
36+
const delayTime = isIE() ? 40 : 0;
37+
this._zone.runOutsideAngular(() => {
38+
resizeObservable(this.nativeElement).pipe(
39+
throttleTime(delayTime),
40+
takeUntil(this.destroy$)).subscribe((event) => this.handleMutations(event));
41+
});
2742
}
2843

2944
@HostListener('scroll', ['$event'])
3045
onScroll(event) {
3146
this.scrollAmount = event.target.scrollTop || event.target.scrollLeft;
3247
}
33-
constructor(public elementRef: ElementRef, public cdr: ChangeDetectorRef) {
48+
constructor(public elementRef: ElementRef, public cdr: ChangeDetectorRef, protected _zone: NgZone, @Inject(DOCUMENT) public document) {
3449
this._scrollNativeSize = this.calculateScrollNativeSize();
3550
}
3651

@@ -40,6 +55,8 @@ export class VirtualHelperBaseDirective implements OnDestroy, AfterViewInit {
4055

4156
public ngOnDestroy() {
4257
this.destroyed = true;
58+
this.destroy$.next(true);
59+
this.destroy$.complete();
4360
}
4461

4562
public set size(value) {
@@ -60,6 +77,23 @@ export class VirtualHelperBaseDirective implements OnDestroy, AfterViewInit {
6077
return this._scrollNativeSize;
6178
}
6279

80+
protected get isAttachedToDom(): boolean {
81+
return this.document.body.contains(this.nativeElement);
82+
}
83+
84+
protected handleMutations(event) {
85+
const hasSize = !(event[0].contentRect.height === 0 && event[0].contentRect.width === 0);
86+
if (!hasSize && !this.isAttachedToDom) {
87+
// scroll bar detached from DOM
88+
this._detached = true;
89+
} else if (this._detached && hasSize && this.isAttachedToDom) {
90+
// attached back now.
91+
this.restoreScroll();
92+
}
93+
}
94+
95+
protected restoreScroll() {}
96+
6397
public calculateScrollNativeSize() {
6498
const div = document.createElement('div');
6599
const style = div.style;

projects/igniteui-angular/src/lib/directives/for-of/horizontal.virtual.helper.component.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { Component, ElementRef, HostBinding, Input, ViewChild, ViewContainerRef, ChangeDetectorRef } from '@angular/core';
1+
import { Component, ElementRef, HostBinding, Input, ViewChild, ViewContainerRef, ChangeDetectorRef, Inject, NgZone } from '@angular/core';
22
import { VirtualHelperBaseDirective } from './base.helper.component';
3+
import { DOCUMENT } from '@angular/common';
34

45
/**
56
* @hidden
@@ -14,7 +15,11 @@ export class HVirtualHelperComponent extends VirtualHelperBaseDirective {
1415
@HostBinding('class')
1516
public cssClasses = 'igx-vhelper--horizontal';
1617

17-
constructor(public elementRef: ElementRef, public cdr: ChangeDetectorRef) {
18-
super(elementRef, cdr);
19-
}
18+
constructor(public elementRef: ElementRef, public cdr: ChangeDetectorRef, protected _zone: NgZone, @Inject(DOCUMENT) public document) {
19+
super(elementRef, cdr, _zone, document);
20+
}
21+
22+
protected restoreScroll() {
23+
this.nativeElement.scrollLeft = this.scrollAmount;
24+
}
2025
}

projects/igniteui-angular/src/lib/directives/for-of/virtual.helper.component.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Component, ElementRef, HostBinding, Input, ViewChild, ViewContainerRef,
2-
ChangeDetectorRef, OnDestroy, OnInit } from '@angular/core';
2+
ChangeDetectorRef, OnDestroy, OnInit, Inject, NgZone } from '@angular/core';
33
import { VirtualHelperBaseDirective } from './base.helper.component';
4+
import { DOCUMENT } from '@angular/common';
45

56
@Component({
67
selector: 'igx-virtual-helper',
@@ -20,11 +21,15 @@ export class VirtualHelperComponent extends VirtualHelperBaseDirective implement
2021
@HostBinding('class')
2122
public cssClasses = 'igx-vhelper--vertical';
2223

23-
constructor(public elementRef: ElementRef, public cdr: ChangeDetectorRef) {
24-
super(elementRef, cdr);
24+
constructor(public elementRef: ElementRef, public cdr: ChangeDetectorRef, protected _zone: NgZone, @Inject(DOCUMENT) public document) {
25+
super(elementRef, cdr, _zone, document);
2526
}
2627

2728
ngOnInit() {
2829
this.scrollWidth = this.scrollNativeSize;
2930
}
31+
32+
protected restoreScroll() {
33+
this.nativeElement.scrollTop = this.scrollAmount;
34+
}
3035
}

projects/igniteui-angular/src/lib/grids/grid/grid.component.spec.ts

+33
Original file line numberDiff line numberDiff line change
@@ -1990,6 +1990,39 @@ describe('IgxGrid Component Tests #grid', () => {
19901990
expect(parseInt(window.getComputedStyle(gridBody.nativeElement).height, 10)).toBe(expectedHeight);
19911991
expect(parseInt(window.getComputedStyle(grid.nativeElement).height, 10)).toBe(300);
19921992
});
1993+
1994+
it('IgxTabs: should persist scroll position after changing tabs.', async () => {
1995+
const grid = fix.componentInstance.grid2;
1996+
fix.detectChanges();
1997+
const tab = fix.componentInstance.tabs;
1998+
1999+
tab.tabs.toArray()[1].select();
2000+
await wait(100);
2001+
fix.detectChanges();
2002+
2003+
grid.navigateTo(grid.data.length - 1, grid.columns.length - 1);
2004+
await wait(100);
2005+
fix.detectChanges();
2006+
2007+
const scrTop = grid.verticalScrollContainer.getScroll().scrollTop;
2008+
const scrLeft = grid.dataRowList.first.virtDirRow.getScroll().scrollLeft;
2009+
2010+
expect(scrTop).not.toBe(0);
2011+
expect(scrLeft).not.toBe(0);
2012+
2013+
tab.tabs.toArray()[0].select();
2014+
await wait(100);
2015+
fix.detectChanges();
2016+
2017+
tab.tabs.toArray()[1].select();
2018+
await wait(100);
2019+
fix.detectChanges();
2020+
await wait(100);
2021+
2022+
// check scrollTop/scrollLeft was persisted.
2023+
expect(grid.verticalScrollContainer.getScroll().scrollTop).toBe(scrTop);
2024+
expect(grid.dataRowList.first.virtDirRow.getScroll().scrollLeft).toBe(scrLeft);
2025+
});
19932026
});
19942027

19952028
describe('IgxGrid - footer section', () => {

src/app/tabs/tabs.sample.html

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ <h3>Tab 3 Content</h3>
5959
sit amet nulla at consequat. Duis volutpat tristique luctus.</p>
6060
</div>
6161
</igx-tabs-group>
62+
<igx-tabs-group label="Tab with Grid" icon="folder">
63+
<igx-grid #grid1 [data]="data" [width]="'800px'" [height]="'500px'" [autoGenerate]='true'>
64+
</igx-grid>
65+
</igx-tabs-group>
6266
<igx-tabs-group label="Tab 4 Lorem ipsum dolor sit amet, consectetur adipiscing elit" icon="folder">
6367
<div class="my-tab-content">
6468
<h3>Tab 4 Content</h3>

src/app/tabs/tabs.sample.ts

+31
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,37 @@ import {Component, ViewEncapsulation} from '@angular/core';
88
})
99
export class TabsSampleComponent {
1010

11+
public data = [
12+
// tslint:disable:max-line-length
13+
{ 'ID': 'ALFKI', 'CompanyName': 'Alfreds Futterkiste', 'ContactName': 'Maria Anders', 'ContactTitle': 'Sales Representative', 'Address': 'Obere Str. 57', 'City': 'Berlin', 'Region': null, 'PostalCode': '12209', 'Country': 'Germany', 'Phone': '030-0074321', 'Fax': '030-0076545' },
14+
{ 'ID': 'ANATR', 'CompanyName': 'Ana Trujillo Emparedados y helados', 'ContactName': 'Ana Trujillo', 'ContactTitle': 'Owner', 'Address': 'Avda. de la Constitución 2222', 'City': 'México D.F.', 'Region': null, 'PostalCode': '05021', 'Country': 'Mexico', 'Phone': '(5) 555-4729', 'Fax': '(5) 555-3745' },
15+
{ 'ID': 'ANTON', 'CompanyName': 'Antonio Moreno Taquería', 'ContactName': 'Antonio Moreno', 'ContactTitle': 'Owner', 'Address': 'Mataderos 2312', 'City': 'México D.F.', 'Region': null, 'PostalCode': '05023', 'Country': 'Mexico', 'Phone': '(5) 555-3932', 'Fax': null },
16+
{ 'ID': 'AROUT', 'CompanyName': 'Around the Horn', 'ContactName': 'Thomas Hardy', 'ContactTitle': 'Sales Representative', 'Address': '120 Hanover Sq.', 'City': 'London', 'Region': null, 'PostalCode': 'WA1 1DP', 'Country': 'UK', 'Phone': '(171) 555-7788', 'Fax': '(171) 555-6750' },
17+
{ 'ID': 'BERGS', 'CompanyName': 'Berglunds snabbköp', 'ContactName': 'Christina Berglund', 'ContactTitle': 'Order Administrator', 'Address': 'Berguvsvägen 8', 'City': 'Luleå', 'Region': null, 'PostalCode': 'S-958 22', 'Country': 'Sweden', 'Phone': '0921-12 34 65', 'Fax': '0921-12 34 67' },
18+
{ 'ID': 'BLAUS', 'CompanyName': 'Blauer See Delikatessen', 'ContactName': 'Hanna Moos', 'ContactTitle': 'Sales Representative', 'Address': 'Forsterstr. 57', 'City': 'Mannheim', 'Region': null, 'PostalCode': '68306', 'Country': 'Germany', 'Phone': '0621-08460', 'Fax': '0621-08924' },
19+
{ 'ID': 'BLONP', 'CompanyName': 'Blondesddsl père et fils', 'ContactName': 'Frédérique Citeaux', 'ContactTitle': 'Marketing Manager', 'Address': '24, place Kléber', 'City': 'Strasbourg', 'Region': null, 'PostalCode': '67000', 'Country': 'France', 'Phone': '88.60.15.31', 'Fax': '88.60.15.32' },
20+
{ 'ID': 'BOLID', 'CompanyName': 'Bólido Comidas preparadas', 'ContactName': 'Martín Sommer', 'ContactTitle': 'Owner', 'Address': 'C/ Araquil, 67', 'City': 'Madrid', 'Region': null, 'PostalCode': '28023', 'Country': 'Spain', 'Phone': '(91) 555 22 82', 'Fax': '(91) 555 91 99' },
21+
{ 'ID': 'BONAP', 'CompanyName': 'Bon app\'', 'ContactName': 'Laurence Lebihan', 'ContactTitle': 'Owner', 'Address': '12, rue des Bouchers', 'City': 'Marseille', 'Region': null, 'PostalCode': '13008', 'Country': 'France', 'Phone': '91.24.45.40', 'Fax': '91.24.45.41' },
22+
{ 'ID': 'BOTTM', 'CompanyName': 'Bottom-Dollar Markets', 'ContactName': 'Elizabeth Lincoln', 'ContactTitle': 'Accounting Manager', 'Address': '23 Tsawassen Blvd.', 'City': 'Tsawassen', 'Region': 'BC', 'PostalCode': 'T2F 8M4', 'Country': 'Canada', 'Phone': '(604) 555-4729', 'Fax': '(604) 555-3745' },
23+
{ 'ID': 'BSBEV', 'CompanyName': 'B\'s Beverages', 'ContactName': 'Victoria Ashworth', 'ContactTitle': 'Sales Representative', 'Address': 'Fauntleroy Circus', 'City': 'London', 'Region': null, 'PostalCode': 'EC2 5NT', 'Country': 'UK', 'Phone': '(171) 555-1212', 'Fax': null },
24+
{ 'ID': 'CACTU', 'CompanyName': 'Cactus Comidas para llevar', 'ContactName': 'Patricio Simpson', 'ContactTitle': 'Sales Agent', 'Address': 'Cerrito 333', 'City': 'Buenos Aires', 'Region': null, 'PostalCode': '1010', 'Country': 'Argentina', 'Phone': '(1) 135-5555', 'Fax': '(1) 135-4892' },
25+
{ 'ID': 'CENTC', 'CompanyName': 'Centro comercial Moctezuma', 'ContactName': 'Francisco Chang', 'ContactTitle': 'Marketing Manager', 'Address': 'Sierras de Granada 9993', 'City': 'México D.F.', 'Region': null, 'PostalCode': '05022', 'Country': 'Mexico', 'Phone': '(5) 555-3392', 'Fax': '(5) 555-7293' },
26+
{ 'ID': 'CHOPS', 'CompanyName': 'Chop-suey Chinese', 'ContactName': 'Yang Wang', 'ContactTitle': 'Owner', 'Address': 'Hauptstr. 29', 'City': 'Bern', 'Region': null, 'PostalCode': '3012', 'Country': 'Switzerland', 'Phone': '0452-076545', 'Fax': null },
27+
{ 'ID': 'COMMI', 'CompanyName': 'Comércio Mineiro', 'ContactName': 'Pedro Afonso', 'ContactTitle': 'Sales Associate', 'Address': 'Av. dos Lusíadas, 23', 'City': 'Sao Paulo', 'Region': 'SP', 'PostalCode': '05432-043', 'Country': 'Brazil', 'Phone': '(11) 555-7647', 'Fax': null },
28+
{ 'ID': 'CONSH', 'CompanyName': 'Consolidated Holdings', 'ContactName': 'Elizabeth Brown', 'ContactTitle': 'Sales Representative', 'Address': 'Berkeley Gardens 12 Brewery', 'City': 'London', 'Region': null, 'PostalCode': 'WX1 6LT', 'Country': 'UK', 'Phone': '(171) 555-2282', 'Fax': '(171) 555-9199' },
29+
{ 'ID': 'DRACD', 'CompanyName': 'Drachenblut Delikatessen', 'ContactName': 'Sven Ottlieb', 'ContactTitle': 'Order Administrator', 'Address': 'Walserweg 21', 'City': 'Aachen', 'Region': null, 'PostalCode': '52066', 'Country': 'Germany', 'Phone': '0241-039123', 'Fax': '0241-059428' },
30+
{ 'ID': 'DUMON', 'CompanyName': 'Du monde entier', 'ContactName': 'Janine Labrune', 'ContactTitle': 'Owner', 'Address': '67, rue des Cinquante Otages', 'City': 'Nantes', 'Region': null, 'PostalCode': '44000', 'Country': 'France', 'Phone': '40.67.88.88', 'Fax': '40.67.89.89' },
31+
{ 'ID': 'EASTC', 'CompanyName': 'Eastern Connection', 'ContactName': 'Ann Devon', 'ContactTitle': 'Sales Agent', 'Address': '35 King George', 'City': 'London', 'Region': null, 'PostalCode': 'WX3 6FW', 'Country': 'UK', 'Phone': '(171) 555-0297', 'Fax': '(171) 555-3373' },
32+
{ 'ID': 'ERNSH', 'CompanyName': 'Ernst Handel', 'ContactName': 'Roland Mendel', 'ContactTitle': 'Sales Manager', 'Address': 'Kirchgasse 6', 'City': 'Graz', 'Region': null, 'PostalCode': '8010', 'Country': 'Austria', 'Phone': '7675-3425', 'Fax': '7675-3426' },
33+
{ 'ID': 'FAMIA', 'CompanyName': 'Familia Arquibaldo', 'ContactName': 'Aria Cruz', 'ContactTitle': 'Marketing Assistant', 'Address': 'Rua Orós, 92', 'City': 'Sao Paulo', 'Region': 'SP', 'PostalCode': '05442-030', 'Country': 'Brazil', 'Phone': '(11) 555-9857', 'Fax': null },
34+
{ 'ID': 'FISSA', 'CompanyName': 'FISSA Fabrica Inter. Salchichas S.A.', 'ContactName': 'Diego Roel', 'ContactTitle': 'Accounting Manager', 'Address': 'C/ Moralzarzal, 86', 'City': 'Madrid', 'Region': null, 'PostalCode': '28034', 'Country': 'Spain', 'Phone': '(91) 555 94 44', 'Fax': '(91) 555 55 93' },
35+
{ 'ID': 'FOLIG', 'CompanyName': 'Folies gourmandes', 'ContactName': 'Martine Rancé', 'ContactTitle': 'Assistant Sales Agent', 'Address': '184, chaussée de Tournai', 'City': 'Lille', 'Region': null, 'PostalCode': '59000', 'Country': 'France', 'Phone': '20.16.10.16', 'Fax': '20.16.10.17' },
36+
{ 'ID': 'FOLKO', 'CompanyName': 'Folk och fä HB', 'ContactName': 'Maria Larsson', 'ContactTitle': 'Owner', 'Address': 'Åkergatan 24', 'City': 'Bräcke', 'Region': null, 'PostalCode': 'S-844 67', 'Country': 'Sweden', 'Phone': '0695-34 67 21', 'Fax': null },
37+
{ 'ID': 'FRANK', 'CompanyName': 'Frankenversand', 'ContactName': 'Peter Franken', 'ContactTitle': 'Marketing Manager', 'Address': 'Berliner Platz 43', 'City': 'München', 'Region': null, 'PostalCode': '80805', 'Country': 'Germany', 'Phone': '089-0877310', 'Fax': '089-0877451' },
38+
{ 'ID': 'FRANR', 'CompanyName': 'France restauration', 'ContactName': 'Carine Schmitt', 'ContactTitle': 'Marketing Manager', 'Address': '54, rue Royale', 'City': 'Nantes', 'Region': null, 'PostalCode': '44000', 'Country': 'France', 'Phone': '40.32.21.21', 'Fax': '40.32.21.20' },
39+
{ 'ID': 'FRANS', 'CompanyName': 'Franchi S.p.A.', 'ContactName': 'Paolo Accorti', 'ContactTitle': 'Sales Representative', 'Address': 'Via Monte Bianco 34', 'City': 'Torino', 'Region': null, 'PostalCode': '10100', 'Country': 'Italy', 'Phone': '011-4988260', 'Fax': '011-4988261' }
40+
];
41+
1142
contacts: any[] = [{
1243
avatar: 'assets/images/avatar/1.jpg',
1344
favorite: true,

0 commit comments

Comments
 (0)