@@ -38,6 +38,7 @@ import {
38
38
} from '@angular/material/core' ;
39
39
import { Subject } from 'rxjs' ;
40
40
import { take } from 'rxjs/operators' ;
41
+ import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations' ;
41
42
42
43
43
44
/** Represents an event fired on an individual `mat-chip`. */
@@ -104,6 +105,7 @@ export class MatChipTrailingIcon {}
104
105
'[class.mat-chip-with-avatar]' : 'avatar' ,
105
106
'[class.mat-chip-with-trailing-icon]' : 'trailingIcon || removeIcon' ,
106
107
'[class.mat-chip-disabled]' : 'disabled' ,
108
+ '[class._mat-animation-noopable]' : '_animationsDisabled' ,
107
109
'[attr.disabled]' : 'disabled || null' ,
108
110
'[attr.aria-disabled]' : 'disabled.toString()' ,
109
111
'[attr.aria-selected]' : 'ariaSelected' ,
@@ -139,6 +141,9 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
139
141
/** Whether the chip has focus. */
140
142
_hasFocus : boolean = false ;
141
143
144
+ /** Whether animations for the chip are enabled. */
145
+ _animationsDisabled : boolean ;
146
+
142
147
/** Whether the chip list is selectable */
143
148
chipListSelectable : boolean = true ;
144
149
@@ -218,16 +223,19 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
218
223
return this . selectable ? this . selected . toString ( ) : null ;
219
224
}
220
225
221
- constructor ( public _elementRef : ElementRef ,
226
+ constructor ( public _elementRef : ElementRef < HTMLElement > ,
222
227
private _ngZone : NgZone ,
223
228
platform : Platform ,
224
- @Optional ( ) @Inject ( MAT_RIPPLE_GLOBAL_OPTIONS ) globalOptions : RippleGlobalOptions ) {
229
+ @Optional ( ) @Inject ( MAT_RIPPLE_GLOBAL_OPTIONS ) globalOptions : RippleGlobalOptions ,
230
+ // @breaking -change 7.0.0 `animationMode` parameter to become required.
231
+ @Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) animationMode ?: string ) {
225
232
super ( _elementRef ) ;
226
233
227
234
this . _addHostClassName ( ) ;
228
235
229
236
this . _chipRipple = new RippleRenderer ( this , _ngZone , _elementRef , platform ) ;
230
237
this . _chipRipple . setupTriggerEvents ( _elementRef . nativeElement ) ;
238
+ this . _animationsDisabled = animationMode === 'NoopAnimations' ;
231
239
232
240
if ( globalOptions ) {
233
241
this . _ripplesGloballyDisabled = ! ! globalOptions . disabled ;
@@ -238,18 +246,23 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
238
246
terminateOnPointerUp : globalOptions . terminateOnPointerUp ,
239
247
} ;
240
248
}
249
+
250
+ if ( this . _animationsDisabled ) {
251
+ this . rippleConfig . animation = { enterDuration : 0 , exitDuration : 0 } ;
252
+ }
241
253
}
242
254
243
255
_addHostClassName ( ) {
256
+ const element = this . _elementRef . nativeElement ;
257
+
244
258
// Add class for the different chips
245
259
for ( const attr of CHIP_ATTRIBUTE_NAMES ) {
246
- if ( this . _elementRef . nativeElement . hasAttribute ( attr ) ||
247
- this . _elementRef . nativeElement . tagName . toLowerCase ( ) === attr ) {
248
- ( this . _elementRef . nativeElement as HTMLElement ) . classList . add ( attr ) ;
260
+ if ( element . hasAttribute ( attr ) || element . tagName . toLowerCase ( ) === attr ) {
261
+ element . classList . add ( attr ) ;
249
262
return ;
250
263
}
251
264
}
252
- ( this . _elementRef . nativeElement as HTMLElement ) . classList . add ( 'mat-standard-chip' ) ;
265
+ element . classList . add ( 'mat-standard-chip' ) ;
253
266
}
254
267
255
268
ngOnDestroy ( ) {
0 commit comments