@@ -19,6 +19,7 @@ import {
19
19
ViewEncapsulation ,
20
20
ChangeDetectionStrategy ,
21
21
ChangeDetectorRef ,
22
+ ViewChild ,
22
23
} from '@angular/core' ;
23
24
import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ;
24
25
import { coerceBooleanProperty , coerceNumberProperty , HammerInput } from '../core' ;
@@ -377,9 +378,6 @@ export class MdSlider extends _MdSliderMixinBase
377
378
/** The size of a tick interval as a percentage of the size of the track. */
378
379
private _tickIntervalPercent : number = 0 ;
379
380
380
- /** A renderer to handle updating the slider's thumb and fill track. */
381
- private _renderer : SliderRenderer ;
382
-
383
381
/** The dimensions of the slider. */
384
382
private _sliderDimensions : ClientRect | null = null ;
385
383
@@ -391,6 +389,9 @@ export class MdSlider extends _MdSliderMixinBase
391
389
/** The value of the slider when the slide start event fires. */
392
390
private _valueOnSlideStart : number | null ;
393
391
392
+ /** Reference to the inner slider wrapper element. */
393
+ @ViewChild ( 'sliderWrapper' ) private _sliderWrapper : ElementRef ;
394
+
394
395
/**
395
396
* Whether mouse events should be converted to a slider position by calculating their distance
396
397
* from the right or bottom edge of the slider as opposed to the top or left.
@@ -412,7 +413,6 @@ export class MdSlider extends _MdSliderMixinBase
412
413
this . _focusOriginMonitor
413
414
. monitor ( this . _elementRef . nativeElement , renderer , true )
414
415
. subscribe ( ( origin : FocusOrigin ) => this . _isActive = ! ! origin && origin !== 'keyboard' ) ;
415
- this . _renderer = new SliderRenderer ( this . _elementRef ) ;
416
416
}
417
417
418
418
ngOnDestroy ( ) {
@@ -426,7 +426,7 @@ export class MdSlider extends _MdSliderMixinBase
426
426
427
427
// We save the dimensions of the slider here so we can use them to update the spacing of the
428
428
// ticks and determine where on the slider click and slide events happen.
429
- this . _sliderDimensions = this . _renderer . getSliderDimensions ( ) ;
429
+ this . _sliderDimensions = this . _getSliderDimensions ( ) ;
430
430
this . _updateTickIntervalPercent ( ) ;
431
431
}
432
432
@@ -437,7 +437,7 @@ export class MdSlider extends _MdSliderMixinBase
437
437
438
438
let oldValue = this . value ;
439
439
this . _isSliding = false ;
440
- this . _renderer . addFocus ( ) ;
440
+ this . _focusHostElement ( ) ;
441
441
this . _updateValueFromPosition ( { x : event . clientX , y : event . clientY } ) ;
442
442
443
443
/* Emit a change and input event if the value changed. */
@@ -479,7 +479,7 @@ export class MdSlider extends _MdSliderMixinBase
479
479
this . _onMouseenter ( ) ;
480
480
481
481
this . _isSliding = true ;
482
- this . _renderer . addFocus ( ) ;
482
+ this . _focusHostElement ( ) ;
483
483
this . _valueOnSlideStart = this . value ;
484
484
485
485
if ( event ) {
@@ -500,7 +500,7 @@ export class MdSlider extends _MdSliderMixinBase
500
500
_onFocus ( ) {
501
501
// We save the dimensions of the slider here so we can use them to update the spacing of the
502
502
// ticks and determine where on the slider click and slide events happen.
503
- this . _sliderDimensions = this . _renderer . getSliderDimensions ( ) ;
503
+ this . _sliderDimensions = this . _getSliderDimensions ( ) ;
504
504
this . _updateTickIntervalPercent ( ) ;
505
505
}
506
506
@@ -647,6 +647,23 @@ export class MdSlider extends _MdSliderMixinBase
647
647
return Math . max ( min , Math . min ( value , max ) ) ;
648
648
}
649
649
650
+ /**
651
+ * Get the bounding client rect of the slider track element.
652
+ * The track is used rather than the native element to ignore the extra space that the thumb can
653
+ * take up.
654
+ */
655
+ private _getSliderDimensions ( ) {
656
+ return this . _sliderWrapper ? this . _sliderWrapper . nativeElement . getBoundingClientRect ( ) : null ;
657
+ }
658
+
659
+ /**
660
+ * Focuses the native element.
661
+ * Currently only used to allow a blur event to fire but will be used with keyboard input later.
662
+ */
663
+ private _focusHostElement ( ) {
664
+ this . _elementRef . nativeElement . focus ( ) ;
665
+ }
666
+
650
667
/**
651
668
* Sets the model value. Implemented as part of ControlValueAccessor.
652
669
* @param value
@@ -682,33 +699,3 @@ export class MdSlider extends _MdSliderMixinBase
682
699
this . disabled = isDisabled ;
683
700
}
684
701
}
685
-
686
- /**
687
- * Renderer class in order to keep all dom manipulation in one place and outside of the main class.
688
- * @docs -private
689
- */
690
- export class SliderRenderer {
691
- private _sliderElement : HTMLElement ;
692
-
693
- constructor ( elementRef : ElementRef ) {
694
- this . _sliderElement = elementRef . nativeElement ;
695
- }
696
-
697
- /**
698
- * Get the bounding client rect of the slider track element.
699
- * The track is used rather than the native element to ignore the extra space that the thumb can
700
- * take up.
701
- */
702
- getSliderDimensions ( ) {
703
- let wrapperElement = this . _sliderElement . querySelector ( '.mat-slider-wrapper' ) ;
704
- return wrapperElement ? wrapperElement . getBoundingClientRect ( ) : null ;
705
- }
706
-
707
- /**
708
- * Focuses the native element.
709
- * Currently only used to allow a blur event to fire but will be used with keyboard input later.
710
- */
711
- addFocus ( ) {
712
- this . _sliderElement . focus ( ) ;
713
- }
714
- }
0 commit comments