Skip to content

fix(grid): start column resize from the rendered width (#18038) - #18040

Open
Huyvux12 wants to merge 2 commits into
IgniteUI:masterfrom
Huyvux12:fix/18038-column-resize-minwidth-first-drag
Open

Huyvux12 wants to merge 2 commits into
IgniteUI:masterfrom
Huyvux12:fix/18038-column-resize-minwidth-first-drag

Conversation

@Huyvux12

Copy link
Copy Markdown

Description

Fixes #18038

A resizable column with minWidth but no width ignored the first drag: column.width reports the clamped default width (136px) while the column is drawn at its minWidth (e.g. 200px). _handlePixelResize() started from column.width, so a first drag shorter than minWidth - 136px was clamped back to minWidth (no visible change), and a longer drag undershot by the same difference (+100px gave 236px instead of 300px).

The fix starts pixel resizes from the width the column is actually drawn at: the new getResizeStartWidth() returns calcWidth when finite, falling back to column.width otherwise. It is used by _handlePixelResize() and by resizeColumn() for the columnResized event's prevWidth (percentage resizes are untouched). This matches the precedent in resizeColumnLayoutFor(), which already starts from calcWidth, and in restrictResizeMin/Max / getColMinWidth, which already use the rendered width.

Reproduction (before the fix)

Base SHA: aba881361dcaa92a70a880b1fd848a9cab049ecc (master)

New tests in projects/igniteui-angular/grids/grid/src/column-resizing.spec.ts (run with CI=true npx ng test igniteui-angular --no-watch --browsers=chromiumHeadless --include 'projects/igniteui-angular/grids/grid/src/column-resizing.spec.ts' --filter '#18038'):

Test Before After
First drag +40px (minWidth 200px, no width) 200px 240px
First drag +100px 236px 300px
First drag +40px, user-set width 100px + minWidth 200px 200px 240px
First drag +40px, minWidth 50px (below the 136px default) 50px 90px

All four fail before the fix (verified by stashing only the service change) and pass after it.

Control case

A second +40px drag in the first test still works as before: 240px → 280px, and the columnResized event now reports the correct args ({ prevWidth: '200px', newWidth: '240px' } for the first drag, { prevWidth: '240px', newWidth: '280px' } for the second).

Regression scope

  • Full column-resizing.spec.ts: 54 passed, 2 failed — the same 2 Multi Column Headers autosize tests fail on clean master too (verified by a git stash baseline run; they depend on webfonts loaded from Google Fonts, which are unavailable in this environment). No other test in the file changed outcome.
  • npm run lint:lib exits 0 (warnings only, matching the file's existing ChangeDetectionStrategy.Eager test-component convention).

Diff scope

  • projects/igniteui-angular/grids/core/src/resizing/resizing.service.ts (+14/−2): new getResizeStartWidth() helper, used by _handlePixelResize() and resizeColumn() (non-percentage path only).
  • projects/igniteui-angular/grids/grid/src/column-resizing.spec.ts (+199): 4 new tests + 3 new test components. No other files changed.

Risks checked and ruled out

  • calcWidth equals the drawn width: templates bind to resolvedWidth = calcPixelWidth + 'px', i.e. calcWidth; for user-set widths cacheCalcWidth constrains width through getConstrainedSizePx, so it is the drawn width there too. Multi-row-layout resize already used calcWidth as its start width.
  • Percentage resizes are untouched (isPercentageWidth guard in resizeColumn()); the pivot-grid resizing service has no minWidth on its dimensions, so the same mismatch cannot occur there.
  • Calling calcWidth during a drag does not mutate layout state: getCalcWidth() returns the cached value whenever it is set and finite, which is the normal case during a drag.
  • Side effect: a no-op drag on an affected column no longer emits a spurious columnResized event (prevWidth: '136px' → newWidth: '200px' for a column that did not visibly change).

Known limitation (out of scope)

If every visible column is set/constrained and their constrained widths sum to exactly the grid width, getPossibleColumnWidth() computes 0/0 = NaN, which can leave column.width as "NaNpx" in that knife-edge case. That is a pre-existing issue in the width-calculation path, not something this fix introduces; the -Infinity sibling of the same expression is handled (getConstrainedSizePx(-Infinity) returns the minWidth, covered by the minWidth 50px test).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change uses rendered widths for constrained pixel resizing and adds regression tests for the affected first-drag scenarios, with no active review issues identified.

No open issues 🎉

What changed in this PR

Fixes grid column resizing so pixel drags start from the column’s rendered width when minWidth constrains its configured width.

Changes:

  • Uses rendered widths for pixel resize calculations and event metadata.
  • Adds regression tests for constrained and first-drag scenarios.
File Description
projects/​igniteui-angular/​grids/​grid/​src/​column-resizing.spec.ts Adds regression tests covering first-drag resizing with minimum and user-defined widths.
projects/​igniteui-angular/​grids/​core/​src/​resizing/​resizing.service.ts Uses the rendered column width as the baseline for pixel resizing and resize event metadata.

Review effort: Lite

@onlyexeption onlyexeption left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix and the detailed write-up! I checked the branch out and dragged the columns in the demo app. The pixel cases from #18038 now end exactly where the resize indicator is released. Your change also fixes a few related cases: a column without width drawn at its maxWidth, the tree grid, the hierarchical grid and multi-row layouts. The new tests fail on master and pass with the change.

There's one thing to address before merging, plus a few smaller suggestions.

Percentage-width columns still ignore the first drag

_handlePercentageResize() has the same root cause: it still starts from parseFloat(column.width). A column with a percentage width is drawn at its minWidth whenever its share of the grid is smaller than the minWidth and at its maxWidth whenever the share is larger. Since #15449 (for #15383) this also applies when the grid first renders.

This is the main reason to set a minWidth on a percentage column. It's also the configuration the column resizing docs use for restricting resizing:

<igx-column [field]="'ID'" width="10%" [resizable]="true"
            [minWidth]="'60px'" [maxWidth]="'230px'"></igx-column>

The docs say the width "may be defined in pixels, percentages or a mix of both" and "Mixing the minimum and maximum column width value types (pixels or percentages) is allowed." For percentage columns they add: "The columns remain responsive and any future grid resizing will still reflect on the columns as well." A percentage width keeps the column responsive, and the pixel minWidth keeps it readable on narrow screens. On a narrow screen the column is therefore drawn at its minWidth most of the time, which is exactly the state this bug hits.

Here is the docs example in a 500px grid, where 10% is 50px, so the column is drawn at its 60px minWidth:

First drag Expected With this PR
+8px 68px 60px (no change)
+20px 80px ~70px
+40px 100px ~90px

The same happens with maxWidth. For example, with width="50%" and maxWidth="300px" in a 1000px grid, a −40px drag leaves the column at 300px. A percentage minWidth behaves the same way.

One way to fix it is to start from the drawn width converted to a percentage of grid.calcWidth, but only when the column is drawn at a different width than its percentage. Converting unconditionally isn't safe: the round trip is not exact (20% of a 641px grid comes back as 20.000000000000004%). An unconstrained column would then get a slightly different stored value on every resize, and the noise would show up in prevWidth. A sketch:

protected getResizeStartPercent(column: ColumnType): number {
    const percentWidth = parseFloat(column.width);
    const gridWidth = column.grid.calcWidth;
    const drawnWidth = parseFloat(String(column.calcWidth));
    // In a grid without a width, percentage columns are drawn at their minimum whatever the percentage.
    if (!gridWidth || column.grid.isColumnWidthSum || !Number.isFinite(drawnWidth)) {
        return percentWidth;
    }
    // Compare in pixels: converting the drawn width back to a percentage is not exact.
    const isDrawnAtWidth = Math.abs(drawnWidth - percentWidth / 100 * gridWidth) < 0.01;
    return isDrawnAtWidth ? percentWidth : drawnWidth / gridWidth * 100;
}

Use it in _handlePercentageResize() and for the percentage prevWidth in resizeColumn(). The column keeps its % unit, so it stays responsive.

For tests, I'd cover a percentage width with a pixel minWidth, one with a pixel maxWidth, and one with a percentage minWidth. Also add an unconstrained percentage column on a 641px grid that asserts the exact % string. The existing percentage tests use round numbers like '50%' and '12.5%', so they wouldn't catch the float noise.

Smaller suggestions

  1. Releasing the resize handle without moving it still changes width. Hold the handle longer than the 200ms debounce and release it without moving. A column drawn at its minWidth gets that width as its width: '136px' becomes '200px' and widthSetByUser becomes true. In the demo app, a 10% column with a 120px minWidth became 12.51% after such a click. Once the window got wider, it was drawn at 144px instead of 120px. Master does this too, but with this PR the pixel case no longer emits columnResized, so the change goes unreported. An early return in resizeColumn() when diff === 0 fixes it. Keep this.zone.run(() => { }) and this.isColumnResizing = false in that branch so the resize line still hides.

  2. getResizeStartWidth() can be simplified. The || column.width in the first line is redundant, because the second line already falls back to column.width. The result is the same for numbers, 0, null, undefined, NaN and strings:

    const calcWidth = parseFloat(String(column.calcWidth));
    return Number.isFinite(calcWidth) ? calcWidth : parseFloat(column.width);
  3. Tests for the other cases this PR fixes:

    • A column without width that is drawn at its maxWidth. Example: a 900px grid with three columns without width, one of them with maxWidth="100px". That column reports column.width as '400px' but is drawn at 100px. On master a −15px drag leaves it at 100px, and nothing covers this case yet.
    • Multi-row layouts. They go through resizeColumnLayoutFor() and then _handlePixelResize(), which now starts from calcWidth too. Add a test in grid.multi-row-layout.integration.spec.ts with a child that has a minWidth and no width. On master its template column stays at 200px after a +40px drag.
    • In "should resize a column with minWidth below the default minimum…", consider asserting the precondition, for example expect(parseFloat(column.width)).not.toEqual(drawnWidth), like the other three tests do with '136px' and '100px'. Otherwise the test keeps passing even if its setup stops reproducing the bug.
  4. CHANGELOG. Please add an entry under a new ## 22.3.3 > ### Bug Fixes section (22.3.2 is already released). Merging master first brings in the current sections. It's worth mentioning the columnResized change too: prevWidth is now the drawn width ('200px' rather than '136px'), and a drag that leaves the drawn width unchanged no longer emits the event.

Happy to re-test once you push an update.

@Huyvux12
Huyvux12 force-pushed the fix/18038-column-resize-minwidth-first-drag branch 2 times, most recently from 315d513 to 9ca9376 Compare December 4, 2026 13:18
A resizable column with minWidth but no width reported its clamped default width (136px) through column.width while it was drawn at its minWidth. _handlePixelResize started from column.width, so the first drag was clamped back to minWidth and a longer drag undershot by the same difference. Start pixel resizes (and the columnResized prevWidth) from calcWidth, which holds the drawn width, falling back to column.width when it is not finite.

Fixes IgniteUI#18038
Percentage columns drawn at minWidth/maxWidth now start the first
drag from the drawn width via getResizeStartPercent, and a no-move
release no longer assigns the drawn width or emits columnResized.
@Huyvux12
Huyvux12 force-pushed the fix/18038-column-resize-minwidth-first-drag branch from 9ca9376 to 0e0a48c Compare December 4, 2026 13:25

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Column resize ignores the first drag when a column has minWidth but no width

5 participants