@@ -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 } ) ;
@@ -483,6 +484,9 @@ export class MatSlider extends _MatSliderMixinBase
483
484
/** Keeps track of the last pointer event that was captured by the slider. */
484
485
private _lastPointerEvent : MouseEvent | TouchEvent | null ;
485
486
487
+ /** Used to subscribe to global move and end events */
488
+ protected _document ?: Document ;
489
+
486
490
constructor ( elementRef : ElementRef ,
487
491
private _focusMonitor : FocusMonitor ,
488
492
private _changeDetectorRef : ChangeDetectorRef ,
@@ -491,9 +495,13 @@ export class MatSlider extends _MatSliderMixinBase
491
495
// @breaking -change 8.0.0 `_animationMode` parameter to be made required.
492
496
@Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) public _animationMode ?: string ,
493
497
// @breaking -change 9.0.0 `_ngZone` parameter to be made required.
494
- private _ngZone ?: NgZone ) {
498
+ private _ngZone ?: NgZone ,
499
+ /** @breaking -change 11.0.0 make document required */
500
+ @Optional ( ) @Inject ( DOCUMENT ) document ?: any ) {
495
501
super ( elementRef ) ;
496
502
503
+ this . _document = document ;
504
+
497
505
this . tabIndex = parseInt ( tabIndex ) || 0 ;
498
506
499
507
this . _runOutsizeZone ( ( ) => {
@@ -691,8 +699,8 @@ export class MatSlider extends _MatSliderMixinBase
691
699
* as they're swiping across the screen.
692
700
*/
693
701
private _bindGlobalEvents ( triggerEvent : TouchEvent | MouseEvent ) {
694
- if ( typeof document !== 'undefined' && document ) {
695
- const body = document . body ;
702
+ if ( typeof this . _document !== 'undefined' && this . _document ) {
703
+ const body = this . _document . body ;
696
704
const isTouch = isTouchEvent ( triggerEvent ) ;
697
705
const moveEventName = isTouch ? 'touchmove' : 'mousemove' ;
698
706
const endEventName = isTouch ? 'touchend' : 'mouseup' ;
@@ -710,8 +718,8 @@ export class MatSlider extends _MatSliderMixinBase
710
718
711
719
/** Removes any global event listeners that we may have added. */
712
720
private _removeGlobalEvents ( ) {
713
- if ( typeof document !== 'undefined' && document ) {
714
- const body = document . body ;
721
+ if ( typeof this . _document !== 'undefined' && this . _document ) {
722
+ const body = this . _document . body ;
715
723
body . removeEventListener ( 'mousemove' , this . _pointerMove , activeEventOptions ) ;
716
724
body . removeEventListener ( 'mouseup' , this . _pointerUp , activeEventOptions ) ;
717
725
body . removeEventListener ( 'touchmove' , this . _pointerMove , activeEventOptions ) ;
0 commit comments