Skip to content

Commit 5e5eb88

Browse files
authored
fix(Grid): Add border to rendered height calc. (#16908)
1 parent c2fb8ac commit 5e5eb88

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7278,20 +7278,24 @@ export abstract class IgxGridBaseDirective implements GridType,
72787278
if (!this._height) {
72797279
return null;
72807280
}
7281+
const styles = this.document.defaultView.getComputedStyle(this.nativeElement);
72817282
const actualTheadRow = this.getTheadRowHeight();
72827283
const footerHeight = this.getFooterHeight();
72837284
const toolbarHeight = this.getToolbarHeight();
72847285
const pagingHeight = this.getPagingFooterHeight();
72857286
const groupAreaHeight = this.getGroupAreaHeight();
72867287
const scrHeight = this.getComputedHeight(this.scr.nativeElement);
7288+
const borderTop = parseFloat(styles.getPropertyValue('border-top-width')) || 0;
7289+
const borderBottom = parseFloat(styles.getPropertyValue('border-bottom-width')) || 0;
7290+
72877291
const renderedHeight = toolbarHeight + actualTheadRow +
72887292
footerHeight + pagingHeight + groupAreaHeight +
7289-
scrHeight;
7293+
scrHeight + borderTop + borderBottom;
72907294

72917295
let gridHeight = 0;
72927296

72937297
if (this.isPercentHeight) {
7294-
const computed = this.document.defaultView.getComputedStyle(this.nativeElement).getPropertyValue('height');
7298+
const computed = styles.getPropertyValue('height');
72957299
const autoSize = this._shouldAutoSize(renderedHeight);
72967300
if (autoSize || computed.indexOf('%') !== -1) {
72977301
const bodyHeight = this.getDataBasedBodyHeight();

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,30 @@ describe('IgxGrid Component Tests #grid', () => {
13011301
expect(parseInt(window.getComputedStyle(domGrid).height, 10)).toBe(300);
13021302
}));
13031303

1304+
it('should account for CSS border widths in body height calculation when height is percent #16640', fakeAsync(() => {
1305+
const fix = TestBed.createComponent(IgxGridWrappedInContComponent);
1306+
fix.componentInstance.outerHeight = 600;
1307+
fix.componentInstance.data = fix.componentInstance.fullData;
1308+
tick();
1309+
fix.detectChanges();
1310+
1311+
const grid = fix.componentInstance.grid;
1312+
const calcHeightNoBorder = grid.calcHeight;
1313+
expect(calcHeightNoBorder).not.toBeNull();
1314+
1315+
// Apply a 2px border (top and bottom) to the grid's native element
1316+
grid.nativeElement.style.borderTop = '2px solid black';
1317+
grid.nativeElement.style.borderBottom = '2px solid black';
1318+
1319+
// Trigger height recalculation
1320+
grid.reflow();
1321+
fix.detectChanges();
1322+
1323+
// The fix ensures border widths are included in the rendered height calculation,
1324+
// reducing the available body height accordingly and preventing continuous reflow growth
1325+
expect(grid.calcHeight).toBe(calcHeightNoBorder - 4);
1326+
}));
1327+
13041328
it('should keep auto-sizing if initial data is empty then set to a new array', fakeAsync(() => {
13051329
const fix = TestBed.createComponent(IgxGridWrappedInContComponent);
13061330
tick();

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@
1111
margin-bottom: 16px;
1212
max-width: 900px;
1313
}
14+
15+
igx-grid {
16+
border: 1px solid lightgray;
17+
}

0 commit comments

Comments
 (0)