Skip to content

fix(form-field): server-side rendering error with outline appearance #10719

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

Merged
merged 1 commit into from
Apr 6, 2018
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
10 changes: 9 additions & 1 deletion src/lib/form-field/form-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {MatLabel} from './label';
import {MatPlaceholder} from './placeholder';
import {MatPrefix} from './prefix';
import {MatSuffix} from './suffix';
import {Platform} from '@angular/cdk/platform';


let nextUniqueId = 0;
Expand Down Expand Up @@ -218,7 +219,9 @@ export class MatFormField extends _MatFormFieldMixinBase
@Optional() @Inject(MAT_LABEL_GLOBAL_OPTIONS) labelOptions: LabelOptions,
@Optional() private _dir: Directionality,
@Optional() @Inject(MAT_FORM_FIELD_DEFAULT_OPTIONS) private _defaultOptions:
MatFormFieldDefaultOptions) {
MatFormFieldDefaultOptions,
// @deletion-target 7.0.0 _platform to be made required.
private _platform?: Platform) {
super(_elementRef);

this._labelOptions = labelOptions ? labelOptions : {};
Expand Down Expand Up @@ -415,6 +418,11 @@ export class MatFormField extends _MatFormFieldMixinBase
*/
updateOutlineGap() {
if (this.appearance === 'outline' && this._label && this._label.nativeElement.children.length) {
if (this._platform && !this._platform.isBrowser) {
// getBoundingClientRect isn't available on the server.
return;
}

const containerStart = this._getStartEnd(
this._connectionContainerRef.nativeElement.getBoundingClientRect());
const labelStart = this._getStartEnd(
Expand Down
5 changes: 5 additions & 0 deletions src/universal-app/kitchen-sink/kitchen-sink.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ <h2>Input</h2>
<input matInput placeholder="name" type="text">
</mat-form-field>

<mat-form-field appearance="outline">
<mat-label>Surname</mat-label>
<input matInput value="Baggins">
</mat-form-field>

<mat-form-field>
<textarea matInput placeholder="description"></textarea>
</mat-form-field>
Expand Down