Skip to content

Commit 7fc7da1

Browse files
crisbetoandrewseguin
authored andcommitted
fix(chips): disable all animations when using NoopAnimationsModule (#11546)
Disables all of the chip animations and transitions when the consumer is using the `NoopAnimationsModule`. Also cleans up some repetitive code. Relates to #10590.
1 parent 3697aa9 commit 7fc7da1

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/material/chips/chip.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
} from '@angular/material/core';
4242
import {Subject} from 'rxjs';
4343
import {take} from 'rxjs/operators';
44+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
4445

4546

4647
/** Represents an event fired on an individual `mat-chip`. */
@@ -105,6 +106,7 @@ export class MatChipTrailingIcon {}
105106
'[class.mat-chip-with-avatar]': 'avatar',
106107
'[class.mat-chip-with-trailing-icon]': 'trailingIcon || removeIcon',
107108
'[class.mat-chip-disabled]': 'disabled',
109+
'[class._mat-animation-noopable]': '_animationsDisabled',
108110
'[attr.disabled]': 'disabled || null',
109111
'[attr.aria-disabled]': 'disabled.toString()',
110112
'[attr.aria-selected]': 'ariaSelected',
@@ -139,6 +141,9 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
139141
/** Whether the chip has focus. */
140142
_hasFocus: boolean = false;
141143

144+
/** Whether animations for the chip are enabled. */
145+
_animationsDisabled: boolean;
146+
142147
/** Whether the chip list is selectable */
143148
chipListSelectable: boolean = true;
144149

@@ -224,18 +229,21 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
224229
this.selected.toString() : null;
225230
}
226231

227-
constructor(public _elementRef: ElementRef,
232+
constructor(public _elementRef: ElementRef<HTMLElement>,
228233
private _ngZone: NgZone,
229234
platform: Platform,
230235
@Optional() @Inject(MAT_RIPPLE_GLOBAL_OPTIONS)
231-
globalRippleOptions: RippleGlobalOptions | null) {
236+
globalRippleOptions: RippleGlobalOptions | null,
237+
// @breaking-change 8.0.0 `animationMode` parameter to become required.
238+
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) {
232239
super(_elementRef);
233240

234241
this._addHostClassName();
235242

236243
this._chipRipple = new RippleRenderer(this, _ngZone, _elementRef, platform);
237244
this._chipRipple.setupTriggerEvents(_elementRef.nativeElement);
238245
this.rippleConfig = globalRippleOptions || {};
246+
this._animationsDisabled = animationMode === 'NoopAnimations';
239247
}
240248

241249
_addHostClassName() {

src/material/chips/chips.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@import '../core/style/variables';
22
@import '../core/style/elevation';
33
@import '../core/style/layout-common';
4+
@import '../core/style/noop-animation';
45
@import '../../cdk/a11y/a11y';
56

67
$mat-chip-min-height: 32px;
@@ -36,6 +37,7 @@ $mat-chip-remove-size: 18px;
3637

3738
.mat-standard-chip {
3839
@include mat-elevation-transition;
40+
@include _noop-animation;
3941
display: inline-flex;
4042
padding: $mat-chip-vertical-padding $mat-chip-horizontal-padding;
4143
border-radius: 16px;

tools/public_api_guard/material/chips.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
export declare const MAT_CHIPS_DEFAULT_OPTIONS: InjectionToken<MatChipsDefaultOptions>;
22

33
export declare class MatChip extends _MatChipMixinBase implements FocusableOption, OnDestroy, CanColor, CanDisable, CanDisableRipple, RippleTarget {
4+
_animationsDisabled: boolean;
45
_chipListMultiple: boolean;
5-
_elementRef: ElementRef;
6+
_elementRef: ElementRef<HTMLElement>;
67
_hasFocus: boolean;
78
readonly _onBlur: Subject<MatChipEvent>;
89
readonly _onFocus: Subject<MatChipEvent>;
@@ -24,7 +25,7 @@ export declare class MatChip extends _MatChipMixinBase implements FocusableOptio
2425
readonly selectionChange: EventEmitter<MatChipSelectionChange>;
2526
trailingIcon: MatChipTrailingIcon;
2627
value: any;
27-
constructor(_elementRef: ElementRef, _ngZone: NgZone, platform: Platform, globalRippleOptions: RippleGlobalOptions | null);
28+
constructor(_elementRef: ElementRef<HTMLElement>, _ngZone: NgZone, platform: Platform, globalRippleOptions: RippleGlobalOptions | null, animationMode?: string);
2829
_addHostClassName(): void;
2930
_blur(): void;
3031
_handleClick(event: Event): void;

0 commit comments

Comments
 (0)