From 876a6acd00d239f3ac7df21e27db74a16e4fd1b7 Mon Sep 17 00:00:00 2001 From: ethanalvizo <55671206+ethanalvizo@users.noreply.github.com> Date: Tue, 17 Oct 2023 22:04:14 -0400 Subject: [PATCH] fix: cap width of columns with long names (#1574) Closes #1276 - adds a max column width in GridMetricCalculator - value is obtained from GridTheme --- packages/grid/src/GridMetricCalculator.ts | 3 ++- packages/grid/src/GridTheme.ts | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/grid/src/GridMetricCalculator.ts b/packages/grid/src/GridMetricCalculator.ts index e9c2a9f950..4b36b92589 100644 --- a/packages/grid/src/GridMetricCalculator.ts +++ b/packages/grid/src/GridMetricCalculator.ts @@ -1656,7 +1656,7 @@ export class GridMetricCalculator { treePaddingX: number = this.calculateTreePaddingX(state) ): number { const { theme } = state; - const { autoSizeColumns, minColumnWidth } = theme; + const { autoSizeColumns, minColumnWidth, maxColumnWidth } = theme; if (!autoSizeColumns) { const { columnWidth } = theme; return columnWidth; @@ -1667,6 +1667,7 @@ export class GridMetricCalculator { const cachedValue = this.calculatedColumnWidths.get(modelColumn); let columnWidth = Math.ceil(Math.max(headerWidth, dataWidth)); columnWidth = Math.max(minColumnWidth, columnWidth); + columnWidth = Math.min(maxColumnWidth, columnWidth); if (cachedValue != null && cachedValue > columnWidth) { columnWidth = cachedValue; } else { diff --git a/packages/grid/src/GridTheme.ts b/packages/grid/src/GridTheme.ts index df3c55a2a3..13e4137c53 100644 --- a/packages/grid/src/GridTheme.ts +++ b/packages/grid/src/GridTheme.ts @@ -105,6 +105,7 @@ export type GridTheme = { columnWidth: number; minRowHeight: number; minColumnWidth: number; + maxColumnWidth: number; // Default row/column header/footers width/height columnHeaderHeight: number; @@ -206,6 +207,7 @@ const defaultTheme: GridTheme = Object.freeze({ columnWidth: 100, minRowHeight: 20, minColumnWidth: 55, + maxColumnWidth: 600, columnHeaderHeight: 20, rowHeaderWidth: 30, rowFooterWidth: 0,