@@ -141,6 +141,7 @@ export const MAT_FORM_FIELD_DEFAULT_OPTIONS =
141141export class MatFormField extends _MatFormFieldMixinBase
142142 implements AfterContentInit , AfterContentChecked , AfterViewInit , CanColor {
143143 private _labelOptions : LabelOptions ;
144+ private _outlineGapCalculationNeeded = false ;
144145
145146 /** The form-field appearance style. */
146147 @Input ( )
@@ -300,6 +301,9 @@ export class MatFormField extends _MatFormFieldMixinBase
300301
301302 ngAfterContentChecked ( ) {
302303 this . _validateControlChild ( ) ;
304+ if ( this . _outlineGapCalculationNeeded ) {
305+ this . updateOutlineGap ( ) ;
306+ }
303307 }
304308
305309 ngAfterViewInit ( ) {
@@ -448,6 +452,11 @@ export class MatFormField extends _MatFormFieldMixinBase
448452 return ;
449453 }
450454
455+ if ( ! document . documentElement . contains ( this . _elementRef . nativeElement ) ) {
456+ this . _outlineGapCalculationNeeded = true ;
457+ return ;
458+ }
459+
451460 let startWidth = 0 ;
452461 let gapWidth = 0 ;
453462 const startEls = this . _connectionContainerRef . nativeElement . querySelectorAll < HTMLElement > (
@@ -459,9 +468,6 @@ export class MatFormField extends _MatFormFieldMixinBase
459468 // getBoundingClientRect isn't available on the server.
460469 return ;
461470 }
462- if ( ! document . documentElement . contains ( this . _elementRef . nativeElement ) ) {
463- return ;
464- }
465471
466472 const containerStart = this . _getStartEnd (
467473 this . _connectionContainerRef . nativeElement . getBoundingClientRect ( ) ) ;
@@ -481,6 +487,8 @@ export class MatFormField extends _MatFormFieldMixinBase
481487 for ( let i = 0 ; i < gapEls . length ; i ++ ) {
482488 gapEls . item ( i ) . style . width = `${ gapWidth } px` ;
483489 }
490+
491+ this . _outlineGapCalculationNeeded = false ;
484492 }
485493
486494 /** Gets the start end of the rect considering the current directionality. */
0 commit comments