Skip to content

fix(slider): handle touchcancel event #17520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/material/slider/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,21 +667,28 @@ export class MatSlider extends _MatSliderMixinBase
*/
private _bindGlobalEvents(triggerEvent: TouchEvent | MouseEvent) {
if (typeof document !== 'undefined' && document) {
const body = document.body;
const isTouch = isTouchEvent(triggerEvent);
const moveEventName = isTouch ? 'touchmove' : 'mousemove';
const endEventName = isTouch ? 'touchend' : 'mouseup';
document.body.addEventListener(moveEventName, this._pointerMove, activeEventOptions);
document.body.addEventListener(endEventName, this._pointerUp, activeEventOptions);
body.addEventListener(moveEventName, this._pointerMove, activeEventOptions);
body.addEventListener(endEventName, this._pointerUp, activeEventOptions);

if (isTouch) {
body.addEventListener('touchcancel', this._pointerUp, activeEventOptions);
}
}
}

/** Removes any global event listeners that we may have added. */
private _removeGlobalEvents() {
if (typeof document !== 'undefined' && document) {
document.body.removeEventListener('mousemove', this._pointerMove, activeEventOptions);
document.body.removeEventListener('mouseup', this._pointerUp, activeEventOptions);
document.body.removeEventListener('touchmove', this._pointerMove, activeEventOptions);
document.body.removeEventListener('touchend', this._pointerUp, activeEventOptions);
const body = document.body;
body.removeEventListener('mousemove', this._pointerMove, activeEventOptions);
body.removeEventListener('mouseup', this._pointerUp, activeEventOptions);
body.removeEventListener('touchmove', this._pointerMove, activeEventOptions);
body.removeEventListener('touchend', this._pointerUp, activeEventOptions);
body.removeEventListener('touchcancel', this._pointerUp, activeEventOptions);
}
}

Expand Down