1
- import { Directive , ElementRef , Input , OnInit } from '@angular/core' ;
1
+ import { Directive , ElementRef , Input , OnInit , NgZone } from '@angular/core' ;
2
2
3
3
4
4
/**
@@ -19,10 +19,24 @@ export class MdTextareaAutosize implements OnInit {
19
19
/** Maximum number of rows for this textarea. */
20
20
@Input ( ) maxRows : number ;
21
21
22
+ /** The value of the textarea. */
23
+ private _value : string ;
24
+
25
+ @Input ( )
26
+ get value ( ) { return this . _value }
27
+ set value ( newValue : string ) {
28
+ this . _value = newValue ;
29
+
30
+ // Wait for the DOM to be updated with the new value before resizing.
31
+ this . _ngZone . runOutsideAngular ( ( ) => {
32
+ this . _ngZone . onStable . first ( ) . subscribe ( ( ) => this . resizeToFitContent ( ) ) ;
33
+ } ) ;
34
+ }
35
+
22
36
/** Cached height of a textarea with a single row. */
23
37
private _cachedLineHeight : number ;
24
38
25
- constructor ( private _elementRef : ElementRef ) { }
39
+ constructor ( private _elementRef : ElementRef , private _ngZone : NgZone ) { }
26
40
27
41
/** The minimum height of the textarea as determined by minRows. */
28
42
get _minHeight ( ) {
@@ -58,9 +72,11 @@ export class MdTextareaAutosize implements OnInit {
58
72
// would affect the height.
59
73
textareaClone . style . position = 'absolute' ;
60
74
textareaClone . style . visibility = 'hidden' ;
75
+ textareaClone . style . border = 'none' ;
61
76
textareaClone . style . padding = '' ;
62
- textareaClone . style . minHeight = '' ;
63
77
textareaClone . style . height = '' ;
78
+ textareaClone . style . minHeight = '' ;
79
+ textareaClone . style . maxHeight = '' ;
64
80
65
81
textarea . parentNode . appendChild ( textareaClone ) ;
66
82
this . _cachedLineHeight = textareaClone . offsetHeight ;
0 commit comments