Skip to content

Commit

Permalink
fix(autosize): textarea receiving focus on init (#11460)
Browse files Browse the repository at this point in the history
Fixes autosizeable textareas receiving focus when they're initialized.

Fixes #11451.
Fixes #11308.
  • Loading branch information
crisbeto authored and mmalerba committed May 23, 2018
1 parent 9313f18 commit 7d447c2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/cdk/text-field/autosize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,10 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
// IE will throw an "Unspecified error" if we try to set the selection range after the
// element has been removed from the DOM. Assert that the directive hasn't been destroyed
// between the time we requested the animation frame and when it was executed.
if (!this._destroyed.isStopped) {
// Also note that we have to assert that the textarea is focused before we set the
// selection range. Setting the selection range on a non-focused textarea will cause
// it to receive focus on IE and Edge.
if (!this._destroyed.isStopped && document.activeElement === textarea) {
textarea.setSelectionRange(selectionStart, selectionEnd);
}
}));
Expand Down

0 comments on commit 7d447c2

Please sign in to comment.