@@ -385,15 +385,12 @@ export class MdSlider extends _MdSliderMixinBase
385
385
386
386
private _controlValueAccessorChangeFn : ( value : any ) => void = ( ) => { } ;
387
387
388
- /** The last value for which a change event was emitted. */
389
- private _lastChangeValue : number | null ;
390
-
391
- /** The last value for which an input event was emitted. */
392
- private _lastInputValue : number | null ;
393
-
394
388
/** Decimal places to round to, based on the step amount. */
395
389
private _roundLabelTo : number ;
396
390
391
+ /** The value of the slider when the slide start event fires. */
392
+ private _valueOnSlideStart : number | null ;
393
+
397
394
/**
398
395
* Whether mouse events should be converted to a slider position by calculating their distance
399
396
* from the right or bottom edge of the slider as opposed to the top or left.
@@ -438,13 +435,16 @@ export class MdSlider extends _MdSliderMixinBase
438
435
return ;
439
436
}
440
437
438
+ let oldValue = this . value ;
441
439
this . _isSliding = false ;
442
440
this . _renderer . addFocus ( ) ;
443
441
this . _updateValueFromPosition ( { x : event . clientX , y : event . clientY } ) ;
444
442
445
- /* Emits a change and input event if the value changed. */
446
- this . _emitInputEvent ( ) ;
447
- this . _emitValueIfChanged ( ) ;
443
+ /* Emit a change and input event if the value changed. */
444
+ if ( oldValue != this . value ) {
445
+ this . _emitInputEvent ( ) ;
446
+ this . _emitChangeEvent ( ) ;
447
+ }
448
448
}
449
449
450
450
_onSlide ( event : HammerInput ) {
@@ -460,10 +460,14 @@ export class MdSlider extends _MdSliderMixinBase
460
460
461
461
// Prevent the slide from selecting anything else.
462
462
event . preventDefault ( ) ;
463
+
464
+ let oldValue = this . value ;
463
465
this . _updateValueFromPosition ( { x : event . center . x , y : event . center . y } ) ;
464
466
465
467
// Native range elements always emit `input` events when the value changed while sliding.
466
- this . _emitInputEvent ( ) ;
468
+ if ( oldValue != this . value ) {
469
+ this . _emitInputEvent ( ) ;
470
+ }
467
471
}
468
472
469
473
_onSlideStart ( event : HammerInput | null ) {
@@ -476,6 +480,7 @@ export class MdSlider extends _MdSliderMixinBase
476
480
477
481
this . _isSliding = true ;
478
482
this . _renderer . addFocus ( ) ;
483
+ this . _valueOnSlideStart = this . value ;
479
484
480
485
if ( event ) {
481
486
this . _updateValueFromPosition ( { x : event . center . x , y : event . center . y } ) ;
@@ -485,7 +490,11 @@ export class MdSlider extends _MdSliderMixinBase
485
490
486
491
_onSlideEnd ( ) {
487
492
this . _isSliding = false ;
488
- this . _emitValueIfChanged ( ) ;
493
+
494
+ if ( this . _valueOnSlideStart != this . value ) {
495
+ this . _emitChangeEvent ( ) ;
496
+ }
497
+ this . _valueOnSlideStart = null ;
489
498
}
490
499
491
500
_onFocus ( ) {
@@ -502,6 +511,8 @@ export class MdSlider extends _MdSliderMixinBase
502
511
_onKeydown ( event : KeyboardEvent ) {
503
512
if ( this . disabled ) { return ; }
504
513
514
+ let oldValue = this . value ;
515
+
505
516
switch ( event . keyCode ) {
506
517
case PAGE_UP :
507
518
this . _increment ( 10 ) ;
@@ -540,8 +551,11 @@ export class MdSlider extends _MdSliderMixinBase
540
551
// it.
541
552
return ;
542
553
}
543
- this . _emitInputEvent ( ) ;
544
- this . _emitValueIfChanged ( ) ;
554
+
555
+ if ( oldValue != this . value ) {
556
+ this . _emitInputEvent ( ) ;
557
+ this . _emitChangeEvent ( ) ;
558
+ }
545
559
546
560
this . _isSliding = true ;
547
561
event . preventDefault ( ) ;
@@ -581,22 +595,14 @@ export class MdSlider extends _MdSliderMixinBase
581
595
}
582
596
583
597
/** Emits a change event if the current value is different from the last emitted value. */
584
- private _emitValueIfChanged ( ) {
585
- if ( this . value != this . _lastChangeValue ) {
586
- let event = this . _createChangeEvent ( ) ;
587
- this . _lastChangeValue = this . value ;
588
- this . _controlValueAccessorChangeFn ( this . value ) ;
589
- this . change . emit ( event ) ;
590
- }
598
+ private _emitChangeEvent ( ) {
599
+ this . _controlValueAccessorChangeFn ( this . value ) ;
600
+ this . change . emit ( this . _createChangeEvent ( ) ) ;
591
601
}
592
602
593
603
/** Emits an input event when the current value is different from the last emitted value. */
594
604
private _emitInputEvent ( ) {
595
- if ( this . value != this . _lastInputValue ) {
596
- let event = this . _createChangeEvent ( ) ;
597
- this . _lastInputValue = this . value ;
598
- this . input . emit ( event ) ;
599
- }
605
+ this . input . emit ( this . _createChangeEvent ( ) ) ;
600
606
}
601
607
602
608
/** Updates the amount of space between ticks as a percentage of the width of the slider. */
0 commit comments