Skip to content

Commit f2ba6b2

Browse files
committed
Use host binding
1 parent aa15cf0 commit f2ba6b2

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

src/lib/input/autosize.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import {Directive, ElementRef, Input, AfterViewInit} from '@angular/core';
1010
exportAs: 'mdTextareaAutosize',
1111
host: {
1212
'(input)': 'resizeToFitContent()',
13+
// Textarea elements that have the directive applied should have a single row by default.
14+
// Browsers normally show two rows by default and this makes the minRows and maxRows unusable.
15+
'rows': '1',
1316
},
1417
})
1518
export class MdTextareaAutosize implements AfterViewInit {
@@ -71,23 +74,9 @@ export class MdTextareaAutosize implements AfterViewInit {
7174

7275
ngAfterViewInit() {
7376
this._cacheTextareaLineHeight();
74-
this._setInitialRows();
7577
this.resizeToFitContent();
7678
}
7779

78-
/**
79-
* Sets the rows property of the textarea to one by default.
80-
* Browsers by default set the rows property to two. Therefore setting the minRows and maxRows
81-
* binding to something below two doesn't work.
82-
*/
83-
private _setInitialRows() {
84-
const textarea = this._elementRef.nativeElement as HTMLTextAreaElement;
85-
86-
// By default textarea elements that have the mdTextareaAutosize directive applied will
87-
// have a single row by default. Browsers normally show two rows by default.
88-
textarea.rows = 1;
89-
}
90-
9180
/** Sets a style property on the textarea element. */
9281
private _setTextareaStyle(property: string, value: string): void {
9382
const textarea = this._elementRef.nativeElement as HTMLTextAreaElement;

0 commit comments

Comments
 (0)