Skip to content

Commit 1ddb6a2

Browse files
authored
fix(igxGrid): Fix timing issue between forof resetting and the grid h… (#14079)
1 parent 40c0239 commit 1ddb6a2

File tree

7 files changed

+41
-17
lines changed

7 files changed

+41
-17
lines changed

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

+16-11
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,9 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
546546
}
547547
const containerSize = 'igxForContainerSize';
548548
if (containerSize in changes && !changes[containerSize].firstChange && this.igxForOf) {
549-
this._recalcOnContainerChange();
549+
const prevSize = parseInt(changes[containerSize].previousValue, 10);
550+
const newSize = parseInt(changes[containerSize].currentValue, 10);
551+
this._recalcOnContainerChange({prevSize, newSize});
550552
}
551553
}
552554

@@ -1316,24 +1318,25 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
13161318
return end;
13171319
}
13181320

1319-
protected _recalcScrollBarSize() {
1321+
protected _recalcScrollBarSize(containerSizeInfo = null) {
13201322
const count = this.isRemote ? this.totalItemCount : (this.igxForOf ? this.igxForOf.length : 0);
13211323
this.dc.instance.notVirtual = !(this.igxForContainerSize && this.dc && this.state.chunkSize < count);
1322-
const scrollable = this.isScrollable();
1324+
const scrollable = containerSizeInfo ? this.scrollComponent.size > containerSizeInfo.prevSize : this.isScrollable();
13231325
if (this.igxForScrollOrientation === 'horizontal') {
13241326
const totalWidth = parseInt(this.igxForContainerSize, 10) > 0 ? this._calcSize() : 0;
1325-
this.scrollComponent.nativeElement.style.width = this.igxForContainerSize + 'px';
1326-
this.scrollComponent.size = totalWidth;
13271327
if (totalWidth <= parseInt(this.igxForContainerSize, 10)) {
13281328
this.resetScrollPosition();
13291329
}
1330+
this.scrollComponent.nativeElement.style.width = this.igxForContainerSize + 'px';
1331+
this.scrollComponent.size = totalWidth;
13301332
}
13311333
if (this.igxForScrollOrientation === 'vertical') {
1332-
this.scrollComponent.nativeElement.style.height = parseInt(this.igxForContainerSize, 10) + 'px';
1333-
this.scrollComponent.size = this._calcSize();
1334-
if (this.scrollComponent.size <= parseInt(this.igxForContainerSize, 10)) {
1334+
const totalHeight = this._calcSize();
1335+
if (totalHeight <= parseInt(this.igxForContainerSize, 10)) {
13351336
this.resetScrollPosition();
13361337
}
1338+
this.scrollComponent.nativeElement.style.height = parseInt(this.igxForContainerSize, 10) + 'px';
1339+
this.scrollComponent.size = totalHeight;
13371340
}
13381341
if (scrollable !== this.isScrollable()) {
13391342
// scrollbar visibility has changed
@@ -1356,10 +1359,10 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
13561359
return size;
13571360
}
13581361

1359-
protected _recalcOnContainerChange() {
1362+
protected _recalcOnContainerChange(containerSizeInfo = null) {
13601363
const prevChunkSize = this.state.chunkSize;
13611364
this.applyChunkSizeChange();
1362-
this._recalcScrollBarSize();
1365+
this._recalcScrollBarSize(containerSizeInfo);
13631366
if (prevChunkSize !== this.state.chunkSize) {
13641367
this.chunkLoad.emit(this.state);
13651368
}
@@ -1616,7 +1619,9 @@ export class IgxGridForOfDirective<T, U extends T[] = T[]> extends IgxForOfDirec
16161619
}
16171620
const containerSize = 'igxForContainerSize';
16181621
if (containerSize in changes && !changes[containerSize].firstChange && this.igxForOf) {
1619-
this._recalcOnContainerChange();
1622+
const prevSize = parseInt(changes[containerSize].previousValue, 10);
1623+
const newSize = parseInt(changes[containerSize].currentValue, 10);
1624+
this._recalcOnContainerChange({prevSize, newSize});
16201625
}
16211626
}
16221627

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

+19-5
Original file line numberDiff line numberDiff line change
@@ -3617,6 +3617,14 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
36173617
this.cdr.detectChanges();
36183618
});
36193619

3620+
3621+
this.headerContainer?.scrollbarVisibilityChanged.pipe(filter(() => !this._init), destructor).subscribe(() => {
3622+
// the horizontal scrollbar showing/hiding
3623+
// update scrollbar visibility and recalc heights
3624+
this.notifyChanges(true);
3625+
this.cdr.detectChanges();
3626+
});
3627+
36203628
this.verticalScrollContainer.contentSizeChange.pipe(filter(() => !this._init), throttleTime(30), destructor).subscribe(() => {
36213629
this.notifyChanges(true);
36223630
});
@@ -4225,10 +4233,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
42254233
/**
42264234
* @hidden @internal
42274235
*/
4228-
public get isHorizontalScrollHidden() {
4229-
const diff = this.unpinnedWidth - this.totalWidth;
4230-
return this.width === null || diff >= 0;
4231-
}
4236+
public isHorizontalScrollHidden = false;
42324237

42334238
/**
42344239
* @hidden @internal
@@ -6071,7 +6076,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
60716076
* @hidden @internal
60726077
*/
60736078
public hasHorizontalScroll() {
6074-
return this.totalWidth - this.unpinnedWidth > 0;
6079+
return this.totalWidth - this.unpinnedWidth > 0 && this.width !== null;
60756080
}
60766081

60776082
/**
@@ -6651,6 +6656,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
66516656
this.resetCaches(recalcFeatureWidth);
66526657

66536658
const hasScroll = this.hasVerticalScroll();
6659+
const hasHScroll = !this.isHorizontalScrollHidden;
66546660
this.calculateGridWidth();
66556661
this.resetCaches(recalcFeatureWidth);
66566662
this.cdr.detectChanges();
@@ -6670,6 +6676,14 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
66706676
this.calculateGridWidth();
66716677
this.cdr.detectChanges();
66726678
}
6679+
6680+
// in case horizontal scrollbar has appeared recalc to size correctly.
6681+
if (hasHScroll !== this.hasHorizontalScroll()) {
6682+
this.isHorizontalScrollHidden = !this.hasHorizontalScroll();
6683+
this.cdr.detectChanges();
6684+
this.calculateGridHeight();
6685+
this.cdr.detectChanges();
6686+
}
66736687
if (this.zone.isStable) {
66746688
this.zone.run(() => {
66756689
this._applyWidthHostBinding();

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

+2
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ describe('IgxGrid - Keyboard navigation #grid', () => {
514514
fix.detectChanges();
515515

516516
fix.componentInstance.columns = fix.componentInstance.generateCols(100);
517+
await wait(DEBOUNCETIME);
518+
fix.detectChanges();
517519
fix.componentInstance.data = fix.componentInstance.generateData(1000);
518520
fix.detectChanges();
519521

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

+1
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,7 @@ describe('IgxGrid Component Tests #grid', () => {
14511451
fix.componentInstance.initColumnsRows(5, 5);
14521452
fix.detectChanges();
14531453
await wait(16);
1454+
fix.detectChanges();
14541455
expect(fix.componentInstance.isHorizonatScrollbarVisible()).toBe(true);
14551456
const scrollbar = grid.headerContainer.getScroll();
14561457
scrollbar.scrollLeft = 10000;

projects/igniteui-angular/src/lib/grids/grid/row-drag.directive.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ describe('Row Drag Tests', () => {
260260
fixture.detectChanges();
261261

262262
// selectable rows disabled
263+
fixture.detectChanges();
263264
let horizontalScrollbarElement: DebugElement = fixture.debugElement.query(By.css(CSS_CLASS_VIRTUAL_HSCROLLBAR));
264265
let horizontalScrollbarRect = horizontalScrollbarElement.nativeElement.getBoundingClientRect();
265266
let pinnedColumnHeaderElement: DebugElement = fixture.debugElement.query(By.css('.' + CSS_CLASS_LAST_PINNED_HEADER));

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

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ describe('IgxHierarchicalGrid Integration #hGrid', () => {
302302
const childGrid = hierarchicalGrid.gridAPI.getChildGrids(false)[0];
303303
childGrid.columns[0].sortable = true;
304304
fixture.detectChanges();
305+
childGrid.cdr.detectChanges();
305306

306307
const childHeader = GridFunctions.getColumnHeader('ID', fixture, childGrid);
307308
GridFunctions.clickHeaderSortIcon(childHeader);

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-header-row.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent implem
112112
public headerContainers: QueryList<IgxGridForOfDirective<ColumnType, ColumnType[]>>;
113113

114114
public override get headerForOf() {
115-
return this.headerContainers.last;
115+
return this.headerContainers?.last;
116116
}
117117

118118
constructor(

0 commit comments

Comments
 (0)