Skip to content

fix(cdk/text-field): clear cached line height on resize #30355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading