@@ -52,6 +52,7 @@ import {MatFormFieldLineRipple} from './directives/line-ripple';
5252import { MatFormFieldNotchedOutline } from './directives/notched-outline' ;
5353import { MAT_PREFIX , MatPrefix } from './directives/prefix' ;
5454import { MAT_SUFFIX , MatSuffix } from './directives/suffix' ;
55+ import { DOCUMENT } from '@angular/common' ;
5556
5657/** Type for the available floatLabel values. */
5758export type FloatLabelType = 'always' | 'auto' ;
@@ -308,7 +309,8 @@ export class MatFormField implements AfterViewInit, OnDestroy, AfterContentCheck
308309 private _platform : Platform ,
309310 @Optional ( ) @Inject ( MAT_FORM_FIELD_DEFAULT_OPTIONS )
310311 private _defaults ?: MatFormFieldDefaultOptions ,
311- @Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) public _animationMode ?: string ) {
312+ @Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) public _animationMode ?: string ,
313+ @Inject ( DOCUMENT ) private _document ?: any ) {
312314 if ( _defaults && _defaults . appearance ) {
313315 this . appearance = _defaults . appearance ;
314316 } else if ( _defaults && _defaults . hideRequiredMarker ) {
@@ -340,7 +342,18 @@ export class MatFormField implements AfterViewInit, OnDestroy, AfterContentCheck
340342 this . _updateFocusState ( ) ;
341343 // Initial notch width update. This is needed in case the text-field label floats
342344 // on initialization, and renders inside of the notched outline.
343- this . _refreshOutlineNotchWidth ( ) ;
345+ // Make sure fonts are loaded before calculating the width.
346+ // debugger;
347+ if ( this . _document ?. fonts ?. ready ) {
348+ this . _document . fonts . ready . then ( ( ) => {
349+ this . _refreshOutlineNotchWidth ( ) ;
350+ this . _changeDetectorRef . markForCheck ( ) ;
351+ } ) ;
352+ } else {
353+ // FontFaceSet is not supported in IE
354+ setTimeout ( ( ) => this . _refreshOutlineNotchWidth ( ) ) ;
355+ }
356+ // this._refreshOutlineNotchWidth();
344357 // Enable animations now. This ensures we don't animate on initial render.
345358 this . _subscriptAnimationState = 'enter' ;
346359 // Because the above changes a value used in the template after it was checked, we need
0 commit comments