Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(textarea): server-side rendering error when using mdTextareaAutosize #6050

Merged
merged 1 commit into from
Jul 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/lib/input/autosize.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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>