mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(text-field): autosize textarea not scrolling to end of input on firefox (#10403)
Fixes the textarea not being scrolled to the text cursor when the textarea is resized on Firefox. Fixes #10400.
This commit is contained in:
committed by
mmalerba
parent
e409ec4f4d
commit
d0a4e9fd6a
@@ -191,11 +191,22 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
|
||||
textarea.style.overflow = 'hidden';
|
||||
textarea.placeholder = '';
|
||||
|
||||
const height = textarea.scrollHeight;
|
||||
|
||||
// Use the scrollHeight to know how large the textarea *would* be if fit its entire value.
|
||||
textarea.style.height = `${textarea.scrollHeight}px`;
|
||||
textarea.style.height = `${height}px`;
|
||||
textarea.style.overflow = '';
|
||||
textarea.placeholder = placeholderText;
|
||||
|
||||
// On Firefox resizing the textarea will prevent it from scrolling to the caret position.
|
||||
// We need to re-set the selection in order for it to scroll to the proper position.
|
||||
if (typeof requestAnimationFrame !== 'undefined') {
|
||||
this._ngZone.runOutsideAngular(() => requestAnimationFrame(() => {
|
||||
const {selectionStart, selectionEnd} = textarea;
|
||||
textarea.setSelectionRange(selectionStart, selectionEnd);
|
||||
}));
|
||||
}
|
||||
|
||||
this._previousValue = value;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user