Skip to content

Commit 380fd1d

Browse files
committedJan 21, 2025·
fix(cdk/text-field): clear cached line height on resize (#30355)
Clears the cached heights in the autosize directive when the window is resized since they may change. (cherry picked from commit 48117e7)
1 parent 09d7476 commit 380fd1d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed
 

‎src/cdk/text-field/autosize.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
114114
}
115115

116116
/** Cached height of a textarea with a single row. */
117-
private _cachedLineHeight: number;
117+
private _cachedLineHeight?: number;
118118
/** Cached height of a textarea with only the placeholder. */
119119
private _cachedPlaceholderHeight?: number;
120120

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

171176
this._isViewInited = true;

0 commit comments

Comments
 (0)
Please sign in to comment.