Skip to content

Commit

Permalink
fix(textarea): server-side rendering error when using mdTextareaAutos…
Browse files Browse the repository at this point in the history
…ize (#6050)

Fixes a server-side rendering error when using the `mdTextareaAutosize` directive.

Fixes #6047.
  • Loading branch information
crisbeto authored and andrewseguin committed Jul 28, 2017
1 parent e7da1e4 commit 05ca4a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/lib/input/autosize.ts
Expand Up @@ -8,6 +8,7 @@

import {Directive, ElementRef, Input, AfterViewInit, Optional, Self} from '@angular/core';
import {NgControl} from '@angular/forms';
import {Platform} from '@angular/cdk/platform';


/**
Expand Down Expand Up @@ -57,7 +58,11 @@ export class MdTextareaAutosize implements AfterViewInit {
/** Cached height of a textarea with a single row. */
private _cachedLineHeight: number;

constructor(private _elementRef: ElementRef, @Optional() @Self() formControl: NgControl) {
constructor(
private _elementRef: ElementRef,
private _platform: Platform,
@Optional() @Self() formControl: NgControl) {

if (formControl && formControl.valueChanges) {
formControl.valueChanges.subscribe(() => this.resizeToFitContent());
}
Expand All @@ -84,8 +89,10 @@ export class MdTextareaAutosize implements AfterViewInit {
}

ngAfterViewInit() {
this._cacheTextareaLineHeight();
this.resizeToFitContent();
if (this._platform.isBrowser) {
this._cacheTextareaLineHeight();
this.resizeToFitContent();
}
}

/** Sets a style property on the textarea element. */
Expand Down Expand Up @@ -131,6 +138,7 @@ export class MdTextareaAutosize implements AfterViewInit {
/** Resize the textarea to fit its content. */
resizeToFitContent() {
const textarea = this._elementRef.nativeElement as HTMLTextAreaElement;

if (textarea.value === this._previousValue) {
return;
}
Expand Down
3 changes: 3 additions & 0 deletions src/universal-app/kitchen-sink/kitchen-sink.html
Expand Up @@ -208,3 +208,6 @@ <h2>Toolbar</h2>
<h2>Tooltip</h2>

<button mdTooltip="Action!">Go</button>

<h2>Autosize textarea</h2>
<textarea mdTextareaAutosize mdAutosizeMaxRows="10"></textarea>

0 comments on commit 05ca4a7

Please sign in to comment.