@@ -113,8 +113,9 @@ export class MdSlider implements ControlValueAccessor {
113
113
114
114
private _controlValueAccessorChangeFn : ( value : any ) => void = ( ) => { } ;
115
115
116
- /** The last value for which a change event was emitted. */
117
- private _lastEmittedValue : number = null ;
116
+ /** The last values for which a change or input event was emitted. */
117
+ private _lastChangeValue : number = null ;
118
+ private _lastInputValue : number = null ;
118
119
119
120
/** onTouch function registered via registerOnTouch (ControlValueAccessor). */
120
121
onTouched : ( ) => any = ( ) => { } ;
@@ -295,6 +296,7 @@ export class MdSlider implements ControlValueAccessor {
295
296
}
296
297
297
298
@Output ( ) change = new EventEmitter < MdSliderChange > ( ) ;
299
+ @Output ( ) input = new EventEmitter < MdSliderChange > ( ) ;
298
300
299
301
constructor ( @Optional ( ) private _dir : Dir , elementRef : ElementRef ) {
300
302
this . _renderer = new SliderRenderer ( elementRef ) ;
@@ -320,6 +322,9 @@ export class MdSlider implements ControlValueAccessor {
320
322
this . _isSliding = false ;
321
323
this . _renderer . addFocus ( ) ;
322
324
this . _updateValueFromPosition ( { x : event . clientX , y : event . clientY } ) ;
325
+
326
+ /* Emits a change and input event if the value changed. */
327
+ this . _emitInputEvent ( ) ;
323
328
this . _emitValueIfChanged ( ) ;
324
329
}
325
330
@@ -331,6 +336,9 @@ export class MdSlider implements ControlValueAccessor {
331
336
// Prevent the slide from selecting anything else.
332
337
event . preventDefault ( ) ;
333
338
this . _updateValueFromPosition ( { x : event . center . x , y : event . center . y } ) ;
339
+
340
+ // Native range elements always emit `input` events when the value changed while sliding.
341
+ this . _emitInputEvent ( ) ;
334
342
}
335
343
336
344
_onSlideStart ( event : HammerInput ) {
@@ -434,16 +442,23 @@ export class MdSlider implements ControlValueAccessor {
434
442
435
443
/** Emits a change event if the current value is different from the last emitted value. */
436
444
private _emitValueIfChanged ( ) {
437
- if ( this . value != this . _lastEmittedValue ) {
438
- let event = new MdSliderChange ( ) ;
439
- event . source = this ;
440
- event . value = this . value ;
441
- this . _lastEmittedValue = this . value ;
445
+ if ( this . value != this . _lastChangeValue ) {
446
+ let event = this . _createChangeEvent ( ) ;
447
+ this . _lastChangeValue = this . value ;
442
448
this . _controlValueAccessorChangeFn ( this . value ) ;
443
449
this . change . emit ( event ) ;
444
450
}
445
451
}
446
452
453
+ /** Emits an input event when the current value is different from the last emitted value. */
454
+ private _emitInputEvent ( ) {
455
+ if ( this . value != this . _lastInputValue ) {
456
+ let event = this . _createChangeEvent ( ) ;
457
+ this . _lastInputValue = this . value ;
458
+ this . input . emit ( event ) ;
459
+ }
460
+ }
461
+
447
462
/** Updates the amount of space between ticks as a percentage of the width of the slider. */
448
463
private _updateTickIntervalPercent ( ) {
449
464
if ( ! this . tickInterval ) {
@@ -461,6 +476,16 @@ export class MdSlider implements ControlValueAccessor {
461
476
}
462
477
}
463
478
479
+ /** Creates a slider change object from the specified value. */
480
+ private _createChangeEvent ( value = this . value ) : MdSliderChange {
481
+ let event = new MdSliderChange ( ) ;
482
+
483
+ event . source = this ;
484
+ event . value = value ;
485
+
486
+ return event ;
487
+ }
488
+
464
489
/** Calculates the percentage of the slider that a value is. */
465
490
private _calculatePercentage ( value : number ) {
466
491
return ( value - this . min ) / ( this . max - this . min ) ;
0 commit comments