@@ -709,16 +709,19 @@ export class MatSlider extends _MatSliderMixinBase
709
709
* as they're swiping across the screen.
710
710
*/
711
711
private _bindGlobalEvents ( triggerEvent : TouchEvent | MouseEvent ) {
712
- if ( typeof this . _document !== 'undefined' && this . _document ) {
713
- const body = this . _document . body ;
712
+ // Note that we bind the events to the `document`, because it allows us to capture
713
+ // drag cancel events where the user's pointer is outside the browser window.
714
+ const document = this . _document ;
715
+
716
+ if ( typeof document !== 'undefined' && document ) {
714
717
const isTouch = isTouchEvent ( triggerEvent ) ;
715
718
const moveEventName = isTouch ? 'touchmove' : 'mousemove' ;
716
719
const endEventName = isTouch ? 'touchend' : 'mouseup' ;
717
- body . addEventListener ( moveEventName , this . _pointerMove , activeEventOptions ) ;
718
- body . addEventListener ( endEventName , this . _pointerUp , activeEventOptions ) ;
720
+ document . addEventListener ( moveEventName , this . _pointerMove , activeEventOptions ) ;
721
+ document . addEventListener ( endEventName , this . _pointerUp , activeEventOptions ) ;
719
722
720
723
if ( isTouch ) {
721
- body . addEventListener ( 'touchcancel' , this . _pointerUp , activeEventOptions ) ;
724
+ document . addEventListener ( 'touchcancel' , this . _pointerUp , activeEventOptions ) ;
722
725
}
723
726
}
724
727
@@ -731,13 +734,14 @@ export class MatSlider extends _MatSliderMixinBase
731
734
732
735
/** Removes any global event listeners that we may have added. */
733
736
private _removeGlobalEvents ( ) {
734
- if ( typeof this . _document !== 'undefined' && this . _document ) {
735
- const body = this . _document . body ;
736
- body . removeEventListener ( 'mousemove' , this . _pointerMove , activeEventOptions ) ;
737
- body . removeEventListener ( 'mouseup' , this . _pointerUp , activeEventOptions ) ;
738
- body . removeEventListener ( 'touchmove' , this . _pointerMove , activeEventOptions ) ;
739
- body . removeEventListener ( 'touchend' , this . _pointerUp , activeEventOptions ) ;
740
- body . removeEventListener ( 'touchcancel' , this . _pointerUp , activeEventOptions ) ;
737
+ const document = this . _document ;
738
+
739
+ if ( typeof document !== 'undefined' && document ) {
740
+ document . removeEventListener ( 'mousemove' , this . _pointerMove , activeEventOptions ) ;
741
+ document . removeEventListener ( 'mouseup' , this . _pointerUp , activeEventOptions ) ;
742
+ document . removeEventListener ( 'touchmove' , this . _pointerMove , activeEventOptions ) ;
743
+ document . removeEventListener ( 'touchend' , this . _pointerUp , activeEventOptions ) ;
744
+ document . removeEventListener ( 'touchcancel' , this . _pointerUp , activeEventOptions ) ;
741
745
}
742
746
743
747
const window = this . _getWindow ( ) ;
0 commit comments