@@ -50,6 +50,7 @@ import {MatPlaceholder} from './placeholder';
50
50
import { MatPrefix } from './prefix' ;
51
51
import { MatSuffix } from './suffix' ;
52
52
import { Platform } from '@angular/cdk/platform' ;
53
+ import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations' ;
53
54
54
55
55
56
let nextUniqueId = 0 ;
@@ -130,6 +131,7 @@ export const MAT_FORM_FIELD_DEFAULT_OPTIONS =
130
131
'[class.ng-valid]' : '_shouldForward("valid")' ,
131
132
'[class.ng-invalid]' : '_shouldForward("invalid")' ,
132
133
'[class.ng-pending]' : '_shouldForward("pending")' ,
134
+ '[class._mat-animation-noopable]' : '!_animationsEnabled' ,
133
135
} ,
134
136
inputs : [ 'color' ] ,
135
137
encapsulation : ViewEncapsulation . None ,
@@ -204,10 +206,11 @@ export class MatFormField extends _MatFormFieldMixinBase
204
206
}
205
207
private _floatLabel : FloatLabelType ;
206
208
207
- _outlineGapWidth = 0 ;
209
+ /** Whether the Angular animations are enabled. */
210
+ _animationsEnabled : boolean ;
208
211
212
+ _outlineGapWidth = 0 ;
209
213
_outlineGapStart = 0 ;
210
-
211
214
_initialGapCalculated = false ;
212
215
213
216
/**
@@ -234,13 +237,15 @@ export class MatFormField extends _MatFormFieldMixinBase
234
237
@Optional ( ) private _dir : Directionality ,
235
238
@Optional ( ) @Inject ( MAT_FORM_FIELD_DEFAULT_OPTIONS ) private _defaultOptions :
236
239
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.
238
241
private _platform ?: Platform ,
239
- private _ngZone ?: NgZone ) {
242
+ private _ngZone ?: NgZone ,
243
+ @Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) _animationMode ?: string ) {
240
244
super ( _elementRef ) ;
241
245
242
246
this . _labelOptions = labelOptions ? labelOptions : { } ;
243
247
this . floatLabel = this . _labelOptions . float || 'auto' ;
248
+ this . _animationsEnabled = _animationMode !== 'NoopAnimations' ;
244
249
}
245
250
246
251
/**
@@ -345,13 +350,17 @@ export class MatFormField extends _MatFormFieldMixinBase
345
350
/** Animates the placeholder up and locks it in position. */
346
351
_animateAndLockLabel ( ) : void {
347
352
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 ;
350
357
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
+ }
354
362
363
+ this . floatLabel = 'always' ;
355
364
this . _changeDetectorRef . markForCheck ( ) ;
356
365
}
357
366
}
0 commit comments