Skip to content

Commit 40fab43

Browse files
committed
fix(cdk-experimental/column-resize): Fix lazy resize mode (broken by ##30378)
1 parent c1ff40f commit 40fab43

File tree

3 files changed

+12
-20
lines changed

3 files changed

+12
-20
lines changed

src/cdk-experimental/column-resize/column-resize.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ export abstract class ColumnResize implements AfterViewInit, OnDestroy {
6565
/** The id attribute of the table, if specified. */
6666
id?: string;
6767

68+
/** @docs-private Whether a call to updateStickyColumnStyles is pending after a resize. */
69+
_flushPending = false;
70+
6871
/**
6972
* Whether to update the column's width continuously as the mouse position
7073
* changes, or to wait until mouseup to apply the new size.

src/cdk-experimental/column-resize/resize-strategy.ts

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,15 @@ export abstract class ResizeStrategy implements OnDestroy {
5454

5555
/** Adjusts the width of the table element by the specified delta. */
5656
protected updateTableWidthAndStickyColumns(delta: number): void {
57-
if (this._pendingResizeDelta === null) {
58-
const tableElement = this.columnResize.elementRef.nativeElement;
59-
const tableWidth = this.getElementWidth(tableElement);
57+
this.columnResize._flushPending = true;
6058

61-
this.styleScheduler.schedule(() => {
62-
tableElement.style.width = coerceCssPixelValue(tableWidth + this._pendingResizeDelta!);
63-
64-
this._pendingResizeDelta = null;
65-
});
66-
67-
this.styleScheduler.scheduleEnd(() => {
68-
// Once the column sizes have updated, we unset the table width so that
69-
// it does not have unwanted side effects on future changes in the table
70-
// such as columns being added or removed.
71-
tableElement.style.width = '';
72-
73-
this.table.updateStickyColumnStyles();
74-
});
75-
}
76-
77-
this._pendingResizeDelta = (this._pendingResizeDelta ?? 0) + delta;
59+
this.styleScheduler.scheduleEnd(() => {
60+
if (!this.columnResize._flushPending) {
61+
return;
62+
}
63+
this.columnResize._flushPending = false;
64+
this.table.updateStickyColumnStyles();
65+
});
7866
}
7967

8068
/** Gets the style.width pixels on the specified element if present, otherwise its offsetWidth. */

src/material-experimental/column-resize/_column-resize-theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// Required for resizing to work properly.
1111
.mat-column-resize-table.cdk-column-resize-with-resized-column {
1212
table-layout: fixed;
13+
width: fit-content;
1314
}
1415

1516
.mat-column-resize-flex {

0 commit comments

Comments
 (0)