@@ -57,6 +57,7 @@ import {
57
57
} from '@angular/material/core' ;
58
58
import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations' ;
59
59
import { normalizePassiveListenerOptions } from '@angular/cdk/platform' ;
60
+ import { DOCUMENT } from '@angular/common' ;
60
61
import { Subscription } from 'rxjs' ;
61
62
62
63
const activeEventOptions = normalizePassiveListenerOptions ( { passive : false } ) ;
@@ -488,6 +489,9 @@ export class MatSlider extends _MatSliderMixinBase
488
489
/** Keeps track of the last pointer event that was captured by the slider. */
489
490
private _lastPointerEvent : MouseEvent | TouchEvent | null ;
490
491
492
+ /** Used to subscribe to global move and end events */
493
+ protected _document ?: Document ;
494
+
491
495
constructor ( elementRef : ElementRef ,
492
496
private _focusMonitor : FocusMonitor ,
493
497
private _changeDetectorRef : ChangeDetectorRef ,
@@ -496,9 +500,13 @@ export class MatSlider extends _MatSliderMixinBase
496
500
// @breaking -change 8.0.0 `_animationMode` parameter to be made required.
497
501
@Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) public _animationMode ?: string ,
498
502
// @breaking -change 9.0.0 `_ngZone` parameter to be made required.
499
- private _ngZone ?: NgZone ) {
503
+ private _ngZone ?: NgZone ,
504
+ /** @breaking -change 11.0.0 make document required */
505
+ @Optional ( ) @Inject ( DOCUMENT ) document ?: any ) {
500
506
super ( elementRef ) ;
501
507
508
+ this . _document = document ;
509
+
502
510
this . tabIndex = parseInt ( tabIndex ) || 0 ;
503
511
504
512
this . _runOutsizeZone ( ( ) => {
@@ -696,8 +704,8 @@ export class MatSlider extends _MatSliderMixinBase
696
704
* as they're swiping across the screen.
697
705
*/
698
706
private _bindGlobalEvents ( triggerEvent : TouchEvent | MouseEvent ) {
699
- if ( typeof document !== 'undefined' && document ) {
700
- const body = document . body ;
707
+ if ( typeof this . _document !== 'undefined' && this . _document ) {
708
+ const body = this . _document . body ;
701
709
const isTouch = isTouchEvent ( triggerEvent ) ;
702
710
const moveEventName = isTouch ? 'touchmove' : 'mousemove' ;
703
711
const endEventName = isTouch ? 'touchend' : 'mouseup' ;
@@ -715,8 +723,8 @@ export class MatSlider extends _MatSliderMixinBase
715
723
716
724
/** Removes any global event listeners that we may have added. */
717
725
private _removeGlobalEvents ( ) {
718
- if ( typeof document !== 'undefined' && document ) {
719
- const body = document . body ;
726
+ if ( typeof this . _document !== 'undefined' && this . _document ) {
727
+ const body = this . _document . body ;
720
728
body . removeEventListener ( 'mousemove' , this . _pointerMove , activeEventOptions ) ;
721
729
body . removeEventListener ( 'mouseup' , this . _pointerUp , activeEventOptions ) ;
722
730
body . removeEventListener ( 'touchmove' , this . _pointerMove , activeEventOptions ) ;
0 commit comments