@@ -709,16 +709,19 @@ export class MatSlider extends _MatSliderMixinBase
709709 * as they're swiping across the screen.
710710 */
711711 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 ) {
714717 const isTouch = isTouchEvent ( triggerEvent ) ;
715718 const moveEventName = isTouch ? 'touchmove' : 'mousemove' ;
716719 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 ) ;
719722
720723 if ( isTouch ) {
721- body . addEventListener ( 'touchcancel' , this . _pointerUp , activeEventOptions ) ;
724+ document . addEventListener ( 'touchcancel' , this . _pointerUp , activeEventOptions ) ;
722725 }
723726 }
724727
@@ -731,13 +734,14 @@ export class MatSlider extends _MatSliderMixinBase
731734
732735 /** Removes any global event listeners that we may have added. */
733736 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 ) ;
741745 }
742746
743747 const window = this . _getWindow ( ) ;
0 commit comments