Skip to content

Commit dd45146

Browse files
committed
fix(ripple): disable ripple animations when using NoopAnimationsModule
Disables the ripples animations when the consumer is using the `NoopAnimationsModule`.
1 parent 81b6a78 commit dd45146

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/lib/core/ripple/ripple.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {defaultRippleAnimationConfig, RippleAnimationConfig} from './ripple-rend
66
import {
77
MatRipple, MatRippleModule, MAT_RIPPLE_GLOBAL_OPTIONS, RippleState, RippleGlobalOptions
88
} from './index';
9+
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
910

1011
/** Shorthands for the enter and exit duration of ripples. */
1112
const {enterDuration, exitDuration} = defaultRippleAnimationConfig;
@@ -553,6 +554,29 @@ describe('MatRipple', () => {
553554
}));
554555
});
555556

557+
describe('with disabled animations', () => {
558+
let rippleDirective: MatRipple;
559+
560+
beforeEach(() => {
561+
TestBed.resetTestingModule();
562+
TestBed.configureTestingModule({
563+
imports: [NoopAnimationsModule, MatRippleModule],
564+
declarations: [BasicRippleContainer],
565+
});
566+
567+
fixture = TestBed.createComponent(BasicRippleContainer);
568+
fixture.detectChanges();
569+
570+
rippleTarget = fixture.nativeElement.querySelector('[mat-ripple]');
571+
rippleDirective = fixture.componentInstance.ripple;
572+
});
573+
574+
it('should set the animation durations to zero', () => {
575+
expect(rippleDirective.rippleConfig.animation!.enterDuration).toBe(0);
576+
expect(rippleDirective.rippleConfig.animation!.exitDuration).toBe(0);
577+
});
578+
});
579+
556580
describe('configuring behavior', () => {
557581
let controller: RippleContainerWithInputBindings;
558582

src/lib/core/ripple/ripple.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from '@angular/core';
2121
import {RippleRef} from './ripple-ref';
2222
import {RippleAnimationConfig, RippleConfig, RippleRenderer, RippleTarget} from './ripple-renderer';
23+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
2324

2425
/** Configurable options for `matRipple`. */
2526
export interface RippleGlobalOptions {
@@ -135,7 +136,8 @@ export class MatRipple implements OnInit, OnDestroy, RippleTarget {
135136
constructor(private _elementRef: ElementRef,
136137
ngZone: NgZone,
137138
platform: Platform,
138-
@Optional() @Inject(MAT_RIPPLE_GLOBAL_OPTIONS) globalOptions: RippleGlobalOptions) {
139+
@Optional() @Inject(MAT_RIPPLE_GLOBAL_OPTIONS) globalOptions: RippleGlobalOptions,
140+
@Optional() @Inject(ANIMATION_MODULE_TYPE) private _animationMode?: string) {
139141

140142
this._globalOptions = globalOptions || {};
141143
this._rippleRenderer = new RippleRenderer(this, ngZone, _elementRef, platform);
@@ -161,7 +163,9 @@ export class MatRipple implements OnInit, OnDestroy, RippleTarget {
161163
centered: this.centered,
162164
radius: this.radius,
163165
color: this.color,
164-
animation: {...this._globalOptions.animation, ...this.animation},
166+
animation: this._animationMode === 'NoopAnimations' ?
167+
{enterDuration: 0, exitDuration: 0} :
168+
{...this._globalOptions.animation, ...this.animation},
165169
terminateOnPointerUp: this._globalOptions.terminateOnPointerUp,
166170
speedFactor: this.speedFactor * (this._globalOptions.baseSpeedFactor || 1),
167171
};

0 commit comments

Comments
 (0)