Skip to content

Commit 39887da

Browse files
crisbetojelbourn
authored andcommitted
fix(form-field): server-side rendering error with outline appearance (#10719)
Fixes an error when rendering an outline form field on the server. Fixes #10719.
1 parent f9fa3f8 commit 39887da

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
@@ -48,6 +48,7 @@ import {MatLabel} from './label';
4848
import {MatPlaceholder} from './placeholder';
4949
import {MatPrefix} from './prefix';
5050
import {MatSuffix} from './suffix';
51+
import {Platform} from '@angular/cdk/platform';
5152

5253

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

223226
this._labelOptions = labelOptions ? labelOptions : {};
@@ -412,6 +415,11 @@ export class MatFormField extends _MatFormFieldMixinBase
412415
*/
413416
updateOutlineGap() {
414417
if (this.appearance === 'outline' && this._label && this._label.nativeElement.children.length) {
418+
if (this._platform && !this._platform.isBrowser) {
419+
// getBoundingClientRect isn't available on the server.
420+
return;
421+
}
422+
415423
const containerStart = this._getStartEnd(
416424
this._connectionContainerRef.nativeElement.getBoundingClientRect());
417425
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)