Skip to content

Commit e78659d

Browse files
committed
wip resize on value change
1 parent d2836bc commit e78659d

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"@types/minimist": "^1.1.28",
4949
"@types/node": "^6.0.34",
5050
"@types/run-sequence": "0.0.27",
51+
"@types/rx": "^2.5.33",
5152
"browserstacktunnel-wrapper": "^2.0.0",
5253
"conventional-changelog": "^1.1.0",
5354
"express": "^4.14.0",

src/lib/input/autosize.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Directive, ElementRef, Input, OnInit} from '@angular/core';
1+
import {Directive, ElementRef, Input, OnInit, NgZone} from '@angular/core';
22

33

44
/**
@@ -19,10 +19,24 @@ export class MdTextareaAutosize implements OnInit {
1919
/** Maximum number of rows for this textarea. */
2020
@Input() maxRows: number;
2121

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+
2236
/** Cached height of a textarea with a single row. */
2337
private _cachedLineHeight: number;
2438

25-
constructor(private _elementRef: ElementRef) { }
39+
constructor(private _elementRef: ElementRef, private _ngZone: NgZone) { }
2640

2741
/** The minimum height of the textarea as determined by minRows. */
2842
get _minHeight() {
@@ -58,9 +72,11 @@ export class MdTextareaAutosize implements OnInit {
5872
// would affect the height.
5973
textareaClone.style.position = 'absolute';
6074
textareaClone.style.visibility = 'hidden';
75+
textareaClone.style.border = 'none';
6176
textareaClone.style.padding = '';
62-
textareaClone.style.minHeight = '';
6377
textareaClone.style.height = '';
78+
textareaClone.style.minHeight = '';
79+
textareaClone.style.maxHeight = '';
6480

6581
textarea.parentNode.appendChild(textareaClone);
6682
this._cachedLineHeight = textareaClone.offsetHeight;

src/lib/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"../../node_modules/@types"
2323
],
2424
"types": [
25-
"jasmine"
25+
"jasmine",
26+
"rx/rx.all"
2627
]
2728
},
2829
"angularCompilerOptions": {

0 commit comments

Comments
 (0)