Skip to content

Commit 948e563

Browse files
crisbetojelbourn
authored andcommitted
fix(ripple): ripples not being cleared if touch sequence is canceled (#12936)
If the browser's touch sequence gets canceled by something, the `touchend` event won't fire which means that the ripples won't be cleared from the ripple container. These changes add an extra handler to make sure that they are.
1 parent cfb83a0 commit 948e563

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,14 @@ export class RippleRenderer {
110110
this._containerElement = elementRef.nativeElement;
111111

112112
// Specify events which need to be registered on the trigger.
113-
this._triggerEvents.set('mousedown', this.onMousedown);
114-
this._triggerEvents.set('mouseup', this.onPointerUp);
115-
this._triggerEvents.set('mouseleave', this.onPointerUp);
116-
117-
this._triggerEvents.set('touchstart', this.onTouchStart);
118-
this._triggerEvents.set('touchend', this.onPointerUp);
113+
this._triggerEvents
114+
.set('mousedown', this.onMousedown)
115+
.set('mouseup', this.onPointerUp)
116+
.set('mouseleave', this.onPointerUp)
117+
118+
.set('touchstart', this.onTouchStart)
119+
.set('touchend', this.onPointerUp)
120+
.set('touchcancel', this.onPointerUp);
119121
}
120122
}
121123

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@ describe('MatRipple', () => {
127127
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0);
128128
}));
129129

130+
it('should clear ripples if the touch sequence is cancelled', fakeAsync(() => {
131+
dispatchTouchEvent(rippleTarget, 'touchstart');
132+
tick(enterDuration);
133+
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(1);
134+
135+
dispatchTouchEvent(rippleTarget, 'touchcancel');
136+
tick(exitDuration);
137+
138+
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0);
139+
}));
140+
130141
it('should launch multiple ripples for multi-touch', fakeAsync(() => {
131142
const touchEvent = createTouchEvent('touchstart');
132143

0 commit comments

Comments
 (0)