@@ -195,6 +195,8 @@ export class MatFormField extends _MatFormFieldMixinBase
195195
196196 _outlineGapStart = 0 ;
197197
198+ _initialGapCalculated = false ;
199+
198200 /**
199201 * @deprecated
200202 * @deletion -target 7.0.0
@@ -265,15 +267,13 @@ export class MatFormField extends _MatFormFieldMixinBase
265267 this . _syncDescribedByIds ( ) ;
266268 this . _changeDetectorRef . markForCheck ( ) ;
267269 } ) ;
268-
269- Promise . resolve ( ) . then ( ( ) => {
270- this . updateOutlineGap ( ) ;
271- this . _changeDetectorRef . markForCheck ( ) ;
272- } ) ;
273270 }
274271
275272 ngAfterContentChecked ( ) {
276273 this . _validateControlChild ( ) ;
274+ if ( ! this . _initialGapCalculated ) {
275+ Promise . resolve ( ) . then ( ( ) => this . updateOutlineGap ( ) ) ;
276+ }
277277 }
278278
279279 ngAfterViewInit ( ) {
@@ -417,6 +417,10 @@ export class MatFormField extends _MatFormFieldMixinBase
417417 if ( this . appearance === 'outline' && this . _label && this . _label . nativeElement . children . length ) {
418418 if ( this . _platform && ! this . _platform . isBrowser ) {
419419 // getBoundingClientRect isn't available on the server.
420+ this . _initialGapCalculated = true ;
421+ return ;
422+ }
423+ if ( ! document . contains ( this . _elementRef . nativeElement ) ) {
420424 return ;
421425 }
422426
@@ -434,6 +438,7 @@ export class MatFormField extends _MatFormFieldMixinBase
434438 this . _outlineGapStart = 0 ;
435439 this . _outlineGapWidth = 0 ;
436440 }
441+ this . _initialGapCalculated = true ;
437442 this . _changeDetectorRef . markForCheck ( ) ;
438443 }
439444
0 commit comments