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.
This commit is contained in:
Kristiyan Kostadinov
2018-09-11 19:58:50 +02:00
committed by Jeremy Elbourn
parent cfb83a0ebc
commit 948e563ed9
2 changed files with 18 additions and 5 deletions
+7 -5
View File
@@ -110,12 +110,14 @@ export class RippleRenderer {
this._containerElement = elementRef.nativeElement;
// Specify events which need to be registered on the trigger.
this._triggerEvents.set('mousedown', this.onMousedown);
this._triggerEvents.set('mouseup', this.onPointerUp);
this._triggerEvents.set('mouseleave', this.onPointerUp);
this._triggerEvents
.set('mousedown', this.onMousedown)
.set('mouseup', this.onPointerUp)
.set('mouseleave', this.onPointerUp)
this._triggerEvents.set('touchstart', this.onTouchStart);
this._triggerEvents.set('touchend', this.onPointerUp);
.set('touchstart', this.onTouchStart)
.set('touchend', this.onPointerUp)
.set('touchcancel', this.onPointerUp);
}
}
+11
View File
@@ -127,6 +127,17 @@ describe('MatRipple', () => {
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0);
}));
it('should clear ripples if the touch sequence is cancelled', fakeAsync(() => {
dispatchTouchEvent(rippleTarget, 'touchstart');
tick(enterDuration);
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(1);
dispatchTouchEvent(rippleTarget, 'touchcancel');
tick(exitDuration);
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0);
}));
it('should launch multiple ripples for multi-touch', fakeAsync(() => {
const touchEvent = createTouchEvent('touchstart');