Skip to content

Commit 85c9139

Browse files
authored
Merge pull request #14224 from IgniteUI/mkirova/fix-14138-17.2.x-new
fix(igxGrid): Enable check for whether container size changes when gr…
2 parents 36e1d4c + 37f3c27 commit 85c9139

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,19 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
920920
}
921921
}
922922

923+
924+
/**
925+
* @hidden
926+
* @internal
927+
*/
928+
public updateScroll(): void {
929+
if (this.igxForScrollOrientation === "horizontal") {
930+
const scrollAmount = this.scrollComponent.nativeElement["scrollLeft"];
931+
this.scrollComponent.scrollAmount = scrollAmount;
932+
this._updateScrollOffset();
933+
}
934+
}
935+
923936
protected updateSizes() {
924937
if (!this.scrollComponent.nativeElement.isConnected) return;
925938
const scrollable = this.isScrollable();

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3615,6 +3615,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
36153615
// the vert. scrollbar showing/hiding
36163616
this.notifyChanges(true);
36173617
this.cdr.detectChanges();
3618+
Promise.resolve().then(() => this.headerContainer.updateScroll());
36183619
});
36193620

36203621

@@ -6296,12 +6297,8 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
62966297
// in case state is no longer valid - update it.
62976298
const rowForOf = row.virtDirRow;
62986299
const gridScrLeft = rowForOf.getScroll().scrollLeft;
6299-
const left = -parseInt(rowForOf.dc.instance._viewContainer.element.nativeElement.style.left, 10);
6300-
const actualScrollLeft = left + rowForOf.getColumnScrollLeft(rowForOf.state.startIndex);
6301-
if (gridScrLeft !== actualScrollLeft) {
6302-
rowForOf.onHScroll(gridScrLeft);
6303-
rowForOf.cdr.detectChanges();
6304-
}
6300+
rowForOf.onHScroll(gridScrLeft);
6301+
rowForOf.cdr.detectChanges();
63056302
}
63066303

63076304
protected changeRowEditingOverlayStateOnScroll(row: RowType) {
@@ -6849,7 +6846,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
68496846
let res = !parentElement ||
68506847
parentElement.clientHeight === 0 ||
68516848
parentElement.clientHeight === renderedHeight;
6852-
if ((!this.platform.isChromium && !this.platform.isFirefox) || this._autoSize) {
6849+
if (parentElement && (res || this._autoSize)) {
68536850
// If grid causes the parent container to extend (for example when container is flex)
68546851
// we should always auto-size since the actual size of the container will continuously change as the grid renders elements.
68556852
this._autoSize = false;

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,20 @@ describe('IgxGrid Component Tests #grid', () => {
14421442
fix.componentInstance.data = fix.componentInstance.fullData;
14431443
}));
14441444

1445+
it('should not auto-size when container has display:contents and size is determinable ', fakeAsync(() => {
1446+
const fix = TestBed.createComponent(IgxGridWrappedInContComponent);
1447+
fix.componentInstance.display = "contents";
1448+
fix.componentInstance.data = fix.componentInstance.fullData;
1449+
tick();
1450+
fix.detectChanges();
1451+
const defaultHeight = fix.debugElement.query(By.css(TBODY_CLASS)).styles.height;
1452+
const defaultHeightNum = parseInt(defaultHeight, 10);
1453+
expect(defaultHeight).not.toBeFalsy();
1454+
1455+
expect(defaultHeightNum).toBeGreaterThan(fix.componentInstance.grid.renderedRowHeight * 10);
1456+
expect(fix.componentInstance.grid.calcHeight).toBeGreaterThan(fix.componentInstance.grid.renderedRowHeight * 10);
1457+
}));
1458+
14451459
it('should render correct columns if after scrolling right container size changes so that all columns become visible.',
14461460
async () => {
14471461
const fix = TestBed.createComponent(IgxGridDefaultRenderingComponent);
@@ -2983,7 +2997,7 @@ export class IgxGridWithCustomFooterComponent extends IgxGridTestComponent {
29832997
public override data = SampleTestData.foodProductData();
29842998
}
29852999
@Component({
2986-
template: `<div [style.width.px]="outerWidth" [style.height.px]="outerHeight">
3000+
template: `<div [style.display]="display" [style.width.px]="outerWidth" [style.height.px]="outerHeight">
29873001
<igx-grid #grid [data]="data" [displayDensity]="density" [autoGenerate]="true">
29883002
<igx-paginator *ngIf="paging" [perPage]="pageSize"></igx-paginator>
29893003
</igx-grid>
@@ -3034,6 +3048,7 @@ export class IgxGridWrappedInContComponent extends IgxGridTestComponent {
30343048
public density: DisplayDensity = DisplayDensity.comfortable;
30353049
public outerWidth = 800;
30363050
public outerHeight: number;
3051+
public display: string = "";
30373052
}
30383053

30393054
@Component({

src/app/grid-auto-size/grid-auto-size.sample.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
<div class="wrapper">
2-
<div class="sample-content">
3-
<div class="sample-column">
1+
<div class="wrapper" style="width:100%; height:100%;">
2+
<div class="sample-content" style="width:100%; height:100%;">
3+
<div class="sample-column" style="width:100%; height:100%;">
44
<div class="density-chooser">
55
<igx-buttongroup [values]="displayDensities" (selected)="selectDensity($event)"></igx-buttongroup>
66
</div>
77
<div>
8+
<button igxButton="contained" (click)="gridContainer.style.display = 'contents'">Set container display: contents</button>
9+
<button igxButton="contained" (click)="gridContainer.style.display = 'block'">Set container display: block</button>
810
<button igxButton="contained" (click)="gridContainerHidden = !gridContainerHidden">Toggle Container Visibility</button>
911
<button igxButton="contained" (click)="containerHeight = '400px'">Set container height px</button>
1012
<button igxButton="contained" (click)="containerHeight = '100%'">Set container height %</button>
@@ -19,7 +21,7 @@
1921
<button igxButton="contained" (click)="setData(0)">Set no data</button>
2022
<button igxButton="contained" (click)="checkCols()">Check cols</button>
2123
</div>
22-
<div [hidden]="gridContainerHidden" [style.height]="containerHeight">
24+
<div #gridContainer [hidden]="gridContainerHidden" [style.height]="containerHeight">
2325
<igx-grid
2426
#grid1
2527
[data]="data"

0 commit comments

Comments
 (0)