Skip to content

Commit 1091768

Browse files
committed
fix(form-field): server-side rendering error with outline appearance
Fixes an error when rendering an outline form field on the server.
1 parent 717dd45 commit 1091768

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/lib/form-field/form-field.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {MatLabel} from './label';
4949
import {MatPlaceholder} from './placeholder';
5050
import {MatPrefix} from './prefix';
5151
import {MatSuffix} from './suffix';
52+
import {Platform} from '@angular/cdk/platform';
5253

5354

5455
let nextUniqueId = 0;
@@ -218,7 +219,9 @@ export class MatFormField extends _MatFormFieldMixinBase
218219
@Optional() @Inject(MAT_LABEL_GLOBAL_OPTIONS) labelOptions: LabelOptions,
219220
@Optional() private _dir: Directionality,
220221
@Optional() @Inject(MAT_FORM_FIELD_DEFAULT_OPTIONS) private _defaultOptions:
221-
MatFormFieldDefaultOptions) {
222+
MatFormFieldDefaultOptions,
223+
// @deletion-target 7.0.0 _platform to be made required.
224+
private _platform?: Platform) {
222225
super(_elementRef);
223226

224227
this._labelOptions = labelOptions ? labelOptions : {};
@@ -415,6 +418,11 @@ export class MatFormField extends _MatFormFieldMixinBase
415418
*/
416419
updateOutlineGap() {
417420
if (this.appearance === 'outline' && this._label && this._label.nativeElement.children.length) {
421+
if (this._platform && !this._platform.isBrowser) {
422+
// getBoundingClientRect isn't available on the server.
423+
return;
424+
}
425+
418426
const containerStart = this._getStartEnd(
419427
this._connectionContainerRef.nativeElement.getBoundingClientRect());
420428
const labelStart = this._getStartEnd(

src/universal-app/kitchen-sink/kitchen-sink.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ <h2>Input</h2>
115115
<input matInput placeholder="name" type="text">
116116
</mat-form-field>
117117

118+
<mat-form-field appearance="outline">
119+
<mat-label>Surname</mat-label>
120+
<input matInput value="Baggins">
121+
</mat-form-field>
122+
118123
<mat-form-field>
119124
<textarea matInput placeholder="description"></textarea>
120125
</mat-form-field>

0 commit comments

Comments
 (0)