Skip to content

Commit

Permalink
fix(cdk/text-field): clear cached line height on resize (#30355)
Browse files Browse the repository at this point in the history
Clears the cached heights in the autosize directive when the window is resized since they may change.

(cherry picked from commit 48117e7)
  • Loading branch information
crisbeto committed Jan 21, 2025
1 parent 09d7476 commit 380fd1d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/cdk/text-field/autosize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
}

/** Cached height of a textarea with a single row. */
private _cachedLineHeight: number;
private _cachedLineHeight?: number;
/** Cached height of a textarea with only the placeholder. */
private _cachedPlaceholderHeight?: number;

Expand Down Expand Up @@ -165,7 +165,12 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
this._renderer.listen(this._textareaElement, 'focus', this._handleFocusEvent),
this._renderer.listen(this._textareaElement, 'blur', this._handleFocusEvent),
];
this._resizeEvents.pipe(auditTime(16)).subscribe(() => this.resizeToFitContent(true));
this._resizeEvents.pipe(auditTime(16)).subscribe(() => {
// Clear the cached heights since the styles can change
// when the window is resized (e.g. by media queries).
this._cachedLineHeight = this._cachedPlaceholderHeight = undefined;
this.resizeToFitContent(true);
});
});

this._isViewInited = true;
Expand Down

0 comments on commit 380fd1d

Please sign in to comment.