Skip to content

Commit b1ded1d

Browse files
authored
fix(Grid): Add border to rendered height calc. (#16906)
1 parent a72848f commit b1ded1d

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-6
lines changed

package-lock.json

Lines changed: 25 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7257,20 +7257,24 @@ export abstract class IgxGridBaseDirective implements GridType,
72577257
if (!this._height) {
72587258
return null;
72597259
}
7260+
const styles = this.document.defaultView.getComputedStyle(this.nativeElement);
72607261
const actualTheadRow = this.getTheadRowHeight();
72617262
const footerHeight = this.getFooterHeight();
72627263
const toolbarHeight = this.getToolbarHeight();
72637264
const pagingHeight = this.getPagingFooterHeight();
72647265
const groupAreaHeight = this.getGroupAreaHeight();
72657266
const scrHeight = this.getComputedHeight(this.scr.nativeElement);
7267+
const borderTop = parseFloat(styles.getPropertyValue('border-top-width')) || 0;
7268+
const borderBottom = parseFloat(styles.getPropertyValue('border-bottom-width')) || 0;
7269+
72667270
const renderedHeight = toolbarHeight + actualTheadRow +
72677271
footerHeight + pagingHeight + groupAreaHeight +
7268-
scrHeight;
7272+
scrHeight + borderTop + borderBottom;
72697273

72707274
let gridHeight = 0;
72717275

72727276
if (this.isPercentHeight) {
7273-
const computed = this.document.defaultView.getComputedStyle(this.nativeElement).getPropertyValue('height');
7277+
const computed = styles.getPropertyValue('height');
72747278
const autoSize = this._shouldAutoSize(renderedHeight);
72757279
if (autoSize || computed.indexOf('%') !== -1) {
72767280
const bodyHeight = this.getDataBasedBodyHeight();

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

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

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