Skip to content

Commit 09f2872

Browse files
crisbetommalerba
authored andcommitted
fix(core): ripple mutating global options when animations are… (#18983)
When animations are disabled, the ripple elements sets the animation duration of its global options to zero. The problem is that it's mutating the object that's used by all other ripples. The issue can be observed by going to the MDC checkbox demo and then trying to interact with something that should have a ripple.
1 parent 7957423 commit 09f2872

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

src/material/core/ripple/ripple.spec.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,14 +479,15 @@ describe('MatRipple', () => {
479479
let rippleDirective: MatRipple;
480480

481481
function createTestComponent(rippleConfig: RippleGlobalOptions,
482-
testComponent: any = BasicRippleContainer) {
482+
testComponent: any = BasicRippleContainer,
483+
extraImports: any[] = []) {
483484
// Reset the previously configured testing module to be able set new providers.
484485
// The testing module has been initialized in the root describe group for the ripples.
485486
TestBed.resetTestingModule();
486487
TestBed.configureTestingModule({
487-
imports: [MatRippleModule],
488+
imports: [MatRippleModule, ...extraImports],
488489
declarations: [testComponent],
489-
providers: [{ provide: MAT_RIPPLE_GLOBAL_OPTIONS, useValue: rippleConfig }]
490+
providers: [{provide: MAT_RIPPLE_GLOBAL_OPTIONS, useValue: rippleConfig}]
490491
});
491492

492493
fixture = TestBed.createComponent(testComponent);
@@ -569,6 +570,14 @@ describe('MatRipple', () => {
569570
// will still exist. To properly finish all timers, we just wait the remaining time.
570571
tick(enterDuration - exitDuration);
571572
}));
573+
574+
it('should not mutate the global options when NoopAnimationsModule is present', () => {
575+
const options: RippleGlobalOptions = {};
576+
577+
createTestComponent(options, RippleContainerWithoutBindings, [NoopAnimationsModule]);
578+
579+
expect(options.animation).toBeFalsy();
580+
});
572581
});
573582

574583
describe('with disabled animations', () => {

src/material/core/ripple/ripple.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,10 @@ export class MatRipple implements OnInit, OnDestroy, RippleTarget {
121121
ngZone: NgZone,
122122
platform: Platform,
123123
@Optional() @Inject(MAT_RIPPLE_GLOBAL_OPTIONS) globalOptions?: RippleGlobalOptions,
124-
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) {
124+
@Optional() @Inject(ANIMATION_MODULE_TYPE) private _animationMode?: string) {
125125

126126
this._globalOptions = globalOptions || {};
127127
this._rippleRenderer = new RippleRenderer(this, ngZone, _elementRef, platform);
128-
129-
if (animationMode === 'NoopAnimations') {
130-
this._globalOptions.animation = {enterDuration: 0, exitDuration: 0};
131-
}
132128
}
133129

134130
ngOnInit() {
@@ -154,7 +150,11 @@ export class MatRipple implements OnInit, OnDestroy, RippleTarget {
154150
centered: this.centered,
155151
radius: this.radius,
156152
color: this.color,
157-
animation: {...this._globalOptions.animation, ...this.animation},
153+
animation: {
154+
...this._globalOptions.animation,
155+
...(this._animationMode === 'NoopAnimations' ? {enterDuration: 0, exitDuration: 0} : {}),
156+
...this.animation
157+
},
158158
terminateOnPointerUp: this._globalOptions.terminateOnPointerUp,
159159
};
160160
}

tools/public_api_guard/material/core.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ export declare class MatRipple implements OnInit, OnDestroy, RippleTarget {
327327
get trigger(): HTMLElement;
328328
set trigger(trigger: HTMLElement);
329329
unbounded: boolean;
330-
constructor(_elementRef: ElementRef<HTMLElement>, ngZone: NgZone, platform: Platform, globalOptions?: RippleGlobalOptions, animationMode?: string);
330+
constructor(_elementRef: ElementRef<HTMLElement>, ngZone: NgZone, platform: Platform, globalOptions?: RippleGlobalOptions, _animationMode?: string | undefined);
331331
fadeOutAll(): void;
332332
launch(config: RippleConfig): RippleRef;
333333
launch(x: number, y: number, config?: RippleConfig): RippleRef;

0 commit comments

Comments
 (0)