Skip to content

Commit 27935c9

Browse files
authored
Merge pull request #14355 from IgniteUI/mkirova/fix-14138-18.0.x
fix(igxGrid): Enable check for whether container size changes when gr…
2 parents 5a70555 + 3be96ab commit 27935c9

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
@@ -924,6 +924,19 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
924924
}
925925
}
926926

927+
928+
/**
929+
* @hidden
930+
* @internal
931+
*/
932+
public updateScroll(): void {
933+
if (this.igxForScrollOrientation === "horizontal") {
934+
const scrollAmount = this.scrollComponent.nativeElement["scrollLeft"];
935+
this.scrollComponent.scrollAmount = scrollAmount;
936+
this._updateScrollOffset();
937+
}
938+
}
939+
927940
protected updateSizes() {
928941
if (!this.scrollComponent.nativeElement.isConnected) return;
929942
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
@@ -3628,6 +3628,7 @@ export abstract class IgxGridBaseDirective implements GridType,
36283628
// the vert. scrollbar showing/hiding
36293629
this.notifyChanges(true);
36303630
this.cdr.detectChanges();
3631+
Promise.resolve().then(() => this.headerContainer.updateScroll());
36313632
});
36323633

36333634

@@ -6312,12 +6313,8 @@ export abstract class IgxGridBaseDirective implements GridType,
63126313
// in case state is no longer valid - update it.
63136314
const rowForOf = row.virtDirRow;
63146315
const gridScrLeft = rowForOf.getScroll().scrollLeft;
6315-
const left = -parseInt(rowForOf.dc.instance._viewContainer.element.nativeElement.style.left, 10);
6316-
const actualScrollLeft = left + rowForOf.getColumnScrollLeft(rowForOf.state.startIndex);
6317-
if (gridScrLeft !== actualScrollLeft) {
6318-
rowForOf.onHScroll(gridScrLeft);
6319-
rowForOf.cdr.detectChanges();
6320-
}
6316+
rowForOf.onHScroll(gridScrLeft);
6317+
rowForOf.cdr.detectChanges();
63216318
}
63226319

63236320
protected changeRowEditingOverlayStateOnScroll(row: RowType) {
@@ -6864,7 +6861,7 @@ export abstract class IgxGridBaseDirective implements GridType,
68646861
let res = !parentElement ||
68656862
parentElement.clientHeight === 0 ||
68666863
parentElement.clientHeight === renderedHeight;
6867-
if ((!this.platform.isChromium && !this.platform.isFirefox) || this._autoSize) {
6864+
if (parentElement && (res || this._autoSize)) {
68686865
// If grid causes the parent container to extend (for example when container is flex)
68696866
// we should always auto-size since the actual size of the container will continuously change as the grid renders elements.
68706867
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
@@ -1446,6 +1446,20 @@ describe('IgxGrid Component Tests #grid', () => {
14461446
fix.componentInstance.data = fix.componentInstance.fullData;
14471447
}));
14481448

1449+
it('should not auto-size when container has display:contents and size is determinable ', fakeAsync(() => {
1450+
const fix = TestBed.createComponent(IgxGridWrappedInContComponent);
1451+
fix.componentInstance.display = "contents";
1452+
fix.componentInstance.data = fix.componentInstance.fullData;
1453+
tick();
1454+
fix.detectChanges();
1455+
const defaultHeight = fix.debugElement.query(By.css(TBODY_CLASS)).styles.height;
1456+
const defaultHeightNum = parseInt(defaultHeight, 10);
1457+
expect(defaultHeight).not.toBeFalsy();
1458+
1459+
expect(defaultHeightNum).toBeGreaterThan(fix.componentInstance.grid.renderedRowHeight * 10);
1460+
expect(fix.componentInstance.grid.calcHeight).toBeGreaterThan(fix.componentInstance.grid.renderedRowHeight * 10);
1461+
}));
1462+
14491463
it('should render correct columns if after scrolling right container size changes so that all columns become visible.',
14501464
async () => {
14511465
const fix = TestBed.createComponent(IgxGridDefaultRenderingComponent);
@@ -3015,7 +3029,7 @@ export class IgxGridWithCustomFooterComponent extends IgxGridTestComponent {
30153029
public override data = SampleTestData.foodProductData();
30163030
}
30173031
@Component({
3018-
template: `<div [style.width.px]="outerWidth" [style.height.px]="outerHeight">
3032+
template: `<div [style.display]="display" [style.width.px]="outerWidth" [style.height.px]="outerHeight">
30193033
<igx-grid #grid [data]="data" [autoGenerate]="true">
30203034
<igx-paginator *ngIf="paging" [perPage]="pageSize"></igx-paginator>
30213035
</igx-grid>
@@ -3065,6 +3079,7 @@ export class IgxGridWrappedInContComponent extends IgxGridTestComponent {
30653079
public pageSize = 5;
30663080
public outerWidth = 800;
30673081
public outerHeight: number;
3082+
public display: string = "";
30683083
}
30693084

30703085
@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]="sizes" (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)