Skip to content

Commit

Permalink
fix(cdk/text-field): clear cached line height on resize
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.
  • Loading branch information
crisbeto committed Jan 20, 2025
1 parent 12b7671 commit 9703cd1
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 9703cd1

Please sign in to comment.