Skip to content
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
4 changes: 4 additions & 0 deletions src/cdk/text-field/autosize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
private _cachedLineHeight?: number;
/** Cached height of a textarea with only the placeholder. */
private _cachedPlaceholderHeight?: number;
/** Cached scroll top of a textarea */
private _cachedScrollTop: number;

/** Used to reference correct document/window */
protected _document? = inject(DOCUMENT, {optional: true});
Expand Down Expand Up @@ -303,6 +305,7 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {

this._cacheTextareaLineHeight();
this._cacheTextareaPlaceholderHeight();
this._cachedScrollTop = this._textareaElement.scrollTop;

// If we haven't determined the line-height yet, we know we're still hidden and there's no point
// in checking the height of the textarea.
Expand Down Expand Up @@ -367,6 +370,7 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
// it to receive focus on IE and Edge.
if (!this._destroyed.isStopped && this._hasFocus) {
textarea.setSelectionRange(selectionStart, selectionEnd);
textarea.scrollTop = this._cachedScrollTop;
}
}
}
Loading