Skip to content

Commit 62b2142

Browse files
cynthialong0-0annieyw
authored andcommitted
fix(material/core): mat-ripple-element is not fired on disable (#22537)
* fix(material/core): `mat-ripple-element` is not fired on disable When button becomes disabled after the ripple initiated and before the ripple animation is completed, it will somestimes not fire the `mat-ripple-element` correctly. Adding the `fadeOutAll()` method when set to disable will fix this issue. Fixes #22520 * fix(material/core): mat-ripple-element is not fired on disable When button becomes disabled after the ripple initiated and before the ripple animation is completed, it will sometimes not fire the `mat-ripple-element` correctly. Add a `fadeOutAllNonPersistent` method in `ripple-renderer.ts` to fade out all non persistent ripples and let it be triggered on disable. It should fix this issue. Fixes #22520 * fix(material/core): mat-ripple-element is not fired on disable When button becomes disabled after the ripple initiated and before the ripple animation is completed, it will sometimes not fire the `mat-ripple-element` correctly. Add a `fadeOutAllNonPersistent` method in `ripple-renderer.ts` to fade out all non persistent ripples and let it be triggered on disable. It should fix this issue. Fixes #22520 * fix(material/core): mat-ripple-element is not fired on disable When button becomes disabled after the ripple initiated and before the ripple animation is completed, it will sometimes not fire the `mat-ripple-element` correctly. Add a `fadeOutAllNonPersistent` method in `ripple-renderer.ts` to fade out all non persistent ripples and let it be triggered on disable. It should fix this issue. Fixes #22520 (cherry picked from commit 491d2ec)
1 parent 33104b6 commit 62b2142

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

src/material/core/ripple/ripple-renderer.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,15 @@ export class RippleRenderer implements EventListenerObject {
206206
this._activeRipples.forEach(ripple => ripple.fadeOut());
207207
}
208208

209+
/** Fades out all currently active non-persistent ripples. */
210+
fadeOutAllNonPersistent() {
211+
this._activeRipples.forEach(ripple => {
212+
if (!ripple.config.persistent) {
213+
ripple.fadeOut();
214+
}
215+
});
216+
}
217+
209218
/** Sets up the trigger event listeners */
210219
setupTriggerEvents(elementOrElementRef: HTMLElement | ElementRef<HTMLElement>) {
211220
const element = coerceElement(elementOrElementRef);

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,24 @@ describe('MatRipple', () => {
646646
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(1);
647647
});
648648

649+
it('fades out non-persistent ripples when disabled input is set',
650+
fakeAsync(() => {
651+
dispatchMouseEvent(rippleTarget, 'mousedown');
652+
controller.ripple.launch(0, 0, { persistent: true });
653+
654+
tick(enterDuration);
655+
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(2);
656+
657+
spyOn(controller.ripple, 'fadeOutAllNonPersistent').and.callThrough();
658+
controller.disabled = true;
659+
fixture.detectChanges();
660+
661+
expect(controller.ripple.fadeOutAllNonPersistent).toHaveBeenCalled();
662+
663+
tick(exitDuration);
664+
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(1);
665+
}));
666+
649667
it('allows specifying custom trigger element', () => {
650668
let alternateTrigger = fixture.debugElement.nativeElement
651669
.querySelector('.alternateTrigger') as HTMLElement;

src/material/core/ripple/ripple.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ export class MatRipple implements OnInit, OnDestroy, RippleTarget {
9191
@Input('matRippleDisabled')
9292
get disabled() { return this._disabled; }
9393
set disabled(value: boolean) {
94+
if (value) {
95+
this.fadeOutAllNonPersistent();
96+
}
9497
this._disabled = value;
9598
this._setupTriggerEventsIfEnabled();
9699
}
@@ -141,6 +144,11 @@ export class MatRipple implements OnInit, OnDestroy, RippleTarget {
141144
this._rippleRenderer.fadeOutAll();
142145
}
143146

147+
/** Fades out all currently showing non-persistent ripple elements. */
148+
fadeOutAllNonPersistent() {
149+
this._rippleRenderer.fadeOutAllNonPersistent();
150+
}
151+
144152
/**
145153
* Ripple configuration from the directive's input values.
146154
* @docs-private Implemented as part of RippleTarget

tools/public_api_guard/material/core.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ export declare class MatRipple implements OnInit, OnDestroy, RippleTarget {
266266
unbounded: boolean;
267267
constructor(_elementRef: ElementRef<HTMLElement>, ngZone: NgZone, platform: Platform, globalOptions?: RippleGlobalOptions, _animationMode?: string | undefined);
268268
fadeOutAll(): void;
269+
fadeOutAllNonPersistent(): void;
269270
launch(config: RippleConfig): RippleRef;
270271
launch(x: number, y: number, config?: RippleConfig): RippleRef;
271272
ngOnDestroy(): void;
@@ -365,6 +366,7 @@ export declare class RippleRenderer implements EventListenerObject {
365366
_removeTriggerEvents(): void;
366367
fadeInRipple(x: number, y: number, config?: RippleConfig): RippleRef;
367368
fadeOutAll(): void;
369+
fadeOutAllNonPersistent(): void;
368370
fadeOutRipple(rippleRef: RippleRef): void;
369371
handleEvent(event: Event): void;
370372
setupTriggerEvents(elementOrElementRef: HTMLElement | ElementRef<HTMLElement>): void;

0 commit comments

Comments
 (0)