Skip to content

Commit 6be299a

Browse files
authored
chore(*): Recalc and apply new min widths based on paddings. (#15642)
1 parent 16c3f88 commit 6be299a

File tree

4 files changed

+22
-29
lines changed

4 files changed

+22
-29
lines changed

projects/igniteui-angular/src/lib/grids/columns/column.component.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const DEFAULT_DATE_FORMAT = 'mediumDate';
6363
const DEFAULT_TIME_FORMAT = 'mediumTime';
6464
const DEFAULT_DATE_TIME_FORMAT = 'medium';
6565
const DEFAULT_DIGITS_INFO = '1.0-3';
66+
const CELL_CONTENT_MIN = 32;
6667

6768
/* blazorElement */
6869
/* contentParent: ColumnGroup */
@@ -1234,14 +1235,8 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy, ColumnTy
12341235
if (!this.grid) {
12351236
return '80';
12361237
}
1237-
switch (this.grid.gridSize) {
1238-
case Size.Medium:
1239-
return '64';
1240-
case Size.Small:
1241-
return '56';
1242-
default:
1243-
return '80';
1244-
}
1238+
// the paddings + the min allowed cell content
1239+
return (this.grid.defaultHeaderGroupMinWidth + CELL_CONTENT_MIN).toString();
12451240
}
12461241
/**
12471242
* Returns a reference to the `summaryTemplate`.

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

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3228,7 +3228,7 @@ export abstract class IgxGridBaseDirective implements GridType,
32283228
private overlayIDs = [];
32293229
private _sortingStrategy: IGridSortingStrategy;
32303230
private _pinning: IPinningConfig = { columns: ColumnPinningPosition.Start };
3231-
private _shouldRecalcRowHeight = false;
3231+
private _shouldRecalcDefaultSizes = false;
32323232

32333233
private _hostWidth;
32343234
private _advancedFilteringOverlayId: string;
@@ -3302,6 +3302,7 @@ export abstract class IgxGridBaseDirective implements GridType,
33023302
private _sortDescendingHeaderIconTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
33033303
private _gridSize: Size = Size.Large;
33043304
private _defaultRowHeight = 50;
3305+
private _defaultCellPadding = 48;
33053306

33063307
/**
33073308
* @hidden @internal
@@ -3720,7 +3721,7 @@ export abstract class IgxGridBaseDirective implements GridType,
37203721
if (this.shouldResize) {
37213722
// resizing occurs due to the change of --ig-size css var
37223723
this._gridSize = this.gridSize;
3723-
this.updateDefaultRowHeight();
3724+
this.updateDefaultSizes();
37243725
this._autoSize = this.isPercentHeight && this.calcHeight !== this.getDataBasedBodyHeight();
37253726
this.crudService.endEdit(false);
37263727
if (this._summaryRowHeight === 0) {
@@ -3956,7 +3957,7 @@ export abstract class IgxGridBaseDirective implements GridType,
39563957
*/
39573958
public dataRebinding(event: IForOfDataChangeEventArgs) {
39583959
if (event.state.chunkSize == 0) {
3959-
this._shouldRecalcRowHeight = true;
3960+
this._shouldRecalcDefaultSizes = true;
39603961
}
39613962
this.dataChanging.emit(event);
39623963
}
@@ -3966,9 +3967,9 @@ export abstract class IgxGridBaseDirective implements GridType,
39663967
*/
39673968
public dataRebound(event: IForOfDataChangeEventArgs) {
39683969
this.selectionService.clearHeaderCBState();
3969-
if (this._shouldRecalcRowHeight) {
3970-
this._shouldRecalcRowHeight = false;
3971-
this.updateDefaultRowHeight();
3970+
if (this._shouldRecalcDefaultSizes) {
3971+
this._shouldRecalcDefaultSizes = false;
3972+
this.updateDefaultSizes();
39723973
}
39733974
this.dataChanged.emit(event);
39743975
}
@@ -4400,14 +4401,7 @@ export abstract class IgxGridBaseDirective implements GridType,
44004401
* The values below depend on the header cell default right/left padding values.
44014402
*/
44024403
public get defaultHeaderGroupMinWidth(): number {
4403-
switch (this.gridSize) {
4404-
case Size.Medium:
4405-
return 32;
4406-
case Size.Small:
4407-
return 24;
4408-
default:
4409-
return 48;
4410-
}
4404+
return this._defaultCellPadding;
44114405
}
44124406

44134407
/** @hidden @internal */
@@ -7838,13 +7832,15 @@ export abstract class IgxGridBaseDirective implements GridType,
78387832
this._lastSearchInfo.matchCount = this._lastSearchInfo.matchInfoCache.length;
78397833
}
78407834

7841-
protected updateDefaultRowHeight() {
7835+
protected updateDefaultSizes() {
78427836
if (this.dataRowList.length > 0 && this.dataRowList.first.cells && this.dataRowList.first.cells.length > 0) {
78437837
const height = parseFloat(this.document.defaultView.getComputedStyle(this.dataRowList.first.cells.first.nativeElement)?.getPropertyValue('height'));
7844-
if (height) {
7838+
const padding = parseFloat(this.document.defaultView.getComputedStyle(this.dataRowList.first.cells.first.nativeElement)?.getPropertyValue('padding-left'));
7839+
if (height && padding) {
78457840
this._defaultRowHeight = height;
7841+
this._defaultCellPadding = padding * 2;
78467842
} else {
7847-
this._shouldRecalcRowHeight = true;
7843+
this._shouldRecalcDefaultSizes = true;
78487844
}
78497845
}
78507846
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,10 @@ describe('IgxGrid - Deferred Column Resizing #grid', () => {
199199
fixture.detectChanges();
200200

201201
expect(column.width).toEqual('80px');
202-
setElementSize(grid.nativeElement, Size.Medium)
202+
setElementSize(grid.nativeElement, Size.Medium);
203203
tick(16); // needed because of the throttleTime of the resize obserer
204204
fixture.detectChanges();
205+
(grid as any).updateDefaultSizes();
205206

206207
expect(column.defaultMinWidth).toBe('64');
207208
UIInteractions.simulateMouseEvent('mousedown', headerResArea, 80, 0);
@@ -214,9 +215,10 @@ describe('IgxGrid - Deferred Column Resizing #grid', () => {
214215
fixture.detectChanges();
215216

216217
expect(column.width).toEqual('64px');
217-
setElementSize(grid.nativeElement, Size.Small)
218+
setElementSize(grid.nativeElement, Size.Small);
218219
tick(16); // needed because of the throttleTime of the resize obserer
219220
fixture.detectChanges();
221+
(grid as any).updateDefaultSizes();
220222

221223
expect(column.defaultMinWidth).toBe('56');
222224
UIInteractions.simulateMouseEvent('mousedown', headerResArea, 64, 0);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,8 +2514,8 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
25142514
this.theadRow.nativeElement.offsetHeight;
25152515
}
25162516

2517-
protected override updateDefaultRowHeight() {
2518-
super.updateDefaultRowHeight();
2517+
protected override updateDefaultSizes() {
2518+
super.updateDefaultSizes();
25192519
if (this.hasHorizontalLayout) {
25202520
// Trigger pipes to recalc heights for the horizontal layout mrl rows.
25212521
this.regroupTrigger++;

0 commit comments

Comments
 (0)