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