@@ -50,6 +50,7 @@ import {MatPlaceholder} from './placeholder';
5050import { MatPrefix } from './prefix' ;
5151import { MatSuffix } from './suffix' ;
5252import { Platform } from '@angular/cdk/platform' ;
53+ import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations' ;
5354
5455
5556let nextUniqueId = 0 ;
@@ -130,6 +131,7 @@ export const MAT_FORM_FIELD_DEFAULT_OPTIONS =
130131 '[class.ng-valid]' : '_shouldForward("valid")' ,
131132 '[class.ng-invalid]' : '_shouldForward("invalid")' ,
132133 '[class.ng-pending]' : '_shouldForward("pending")' ,
134+ '[class._mat-animation-noopable]' : '!_animationsEnabled' ,
133135 } ,
134136 inputs : [ 'color' ] ,
135137 encapsulation : ViewEncapsulation . None ,
@@ -204,10 +206,11 @@ export class MatFormField extends _MatFormFieldMixinBase
204206 }
205207 private _floatLabel : FloatLabelType ;
206208
207- _outlineGapWidth = 0 ;
209+ /** Whether the Angular animations are enabled. */
210+ _animationsEnabled : boolean ;
208211
212+ _outlineGapWidth = 0 ;
209213 _outlineGapStart = 0 ;
210-
211214 _initialGapCalculated = false ;
212215
213216 /**
@@ -234,13 +237,15 @@ export class MatFormField extends _MatFormFieldMixinBase
234237 @Optional ( ) private _dir : Directionality ,
235238 @Optional ( ) @Inject ( MAT_FORM_FIELD_DEFAULT_OPTIONS ) private _defaultOptions :
236239 MatFormFieldDefaultOptions ,
237- // @deletion -target 7.0.0 _platform and _ngZone to be made required.
240+ // @deletion -target 7.0.0 _platform, _ngZone and _animationMode to be made required.
238241 private _platform ?: Platform ,
239- private _ngZone ?: NgZone ) {
242+ private _ngZone ?: NgZone ,
243+ @Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) _animationMode ?: string ) {
240244 super ( _elementRef ) ;
241245
242246 this . _labelOptions = labelOptions ? labelOptions : { } ;
243247 this . floatLabel = this . _labelOptions . float || 'auto' ;
248+ this . _animationsEnabled = _animationMode !== 'NoopAnimations' ;
244249 }
245250
246251 /**
@@ -345,13 +350,17 @@ export class MatFormField extends _MatFormFieldMixinBase
345350 /** Animates the placeholder up and locks it in position. */
346351 _animateAndLockLabel ( ) : void {
347352 if ( this . _hasFloatingLabel ( ) && this . _canLabelFloat ) {
348- this . _showAlwaysAnimate = true ;
349- this . floatLabel = 'always' ;
353+ // If animations are disabled, we shouldn't go in here,
354+ // because the `transitionend` will never fire.
355+ if ( this . _animationsEnabled ) {
356+ this . _showAlwaysAnimate = true ;
350357
351- fromEvent ( this . _label . nativeElement , 'transitionend' ) . pipe ( take ( 1 ) ) . subscribe ( ( ) => {
352- this . _showAlwaysAnimate = false ;
353- } ) ;
358+ fromEvent ( this . _label . nativeElement , 'transitionend' ) . pipe ( take ( 1 ) ) . subscribe ( ( ) => {
359+ this . _showAlwaysAnimate = false ;
360+ } ) ;
361+ }
354362
363+ this . floatLabel = 'always' ;
355364 this . _changeDetectorRef . markForCheck ( ) ;
356365 }
357366 }
0 commit comments