@@ -44,6 +44,8 @@ var _util = require('./util');
4444
4545var _propTypes = require ( './propTypes' ) ;
4646
47+ var internals = new WeakMap ( ) ;
48+
4749var KeyCode = {
4850 LEFT_ARROW : 37 ,
4951 RIGHT_ARROW : 39
@@ -71,6 +73,12 @@ function shouldUpdate(inputRange, values) {
7173 return isWithinRange ( inputRange , values ) && hasStepDifference ( inputRange , values ) ;
7274}
7375
76+ function getDocument ( inputRange ) {
77+ var ownerDocument = inputRange . refs . inputRange . ownerDocument ;
78+
79+ return ownerDocument ;
80+ }
81+
7482function getComponentClassName ( inputRange ) {
7583 var props = inputRange . props ;
7684
@@ -217,7 +225,9 @@ var InputRange = (function (_React$Component) {
217225
218226 _get ( Object . getPrototypeOf ( InputRange . prototype ) , 'constructor' , this ) . call ( this , props ) ;
219227
220- ( 0 , _util . autobind ) ( [ 'handleSliderMouseMove' , 'handleSliderKeyDown' , 'handleTrackMouseDown' ] , this ) ;
228+ internals . set ( this , { } ) ;
229+
230+ ( 0 , _util . autobind ) ( [ 'handleInteractionEnd' , 'handleInteractionStart' , 'handleKeyDown' , 'handleKeyUp' , 'handleMouseDown' , 'handleMouseUp' , 'handleSliderKeyDown' , 'handleSliderMouseMove' , 'handleTouchStart' , 'handleTouchEnd' , 'handleTrackMouseDown' ] , this ) ;
221231 }
222232
223233 _createClass ( InputRange , [ {
@@ -285,7 +295,7 @@ var InputRange = (function (_React$Component) {
285295 }
286296 } , {
287297 key : 'handleSliderMouseMove' ,
288- value : function handleSliderMouseMove ( slider , event ) {
298+ value : function handleSliderMouseMove ( event , slider ) {
289299 if ( this . props . disabled ) {
290300 return ;
291301 }
@@ -297,7 +307,7 @@ var InputRange = (function (_React$Component) {
297307 }
298308 } , {
299309 key : 'handleSliderKeyDown' ,
300- value : function handleSliderKeyDown ( slider , event ) {
310+ value : function handleSliderKeyDown ( event , slider ) {
301311 if ( this . props . disabled ) {
302312 return ;
303313 }
@@ -319,7 +329,7 @@ var InputRange = (function (_React$Component) {
319329 }
320330 } , {
321331 key : 'handleTrackMouseDown' ,
322- value : function handleTrackMouseDown ( track , position ) {
332+ value : function handleTrackMouseDown ( event , track , position ) {
323333 if ( this . props . disabled ) {
324334 return ;
325335 }
@@ -328,6 +338,78 @@ var InputRange = (function (_React$Component) {
328338
329339 this . updatePosition ( key , position ) ;
330340 }
341+ } , {
342+ key : 'handleInteractionStart' ,
343+ value : function handleInteractionStart ( ) {
344+ var _this = internals . get ( this ) ;
345+
346+ if ( ! this . props . onChangeComplete || ( 0 , _util . isDefined ) ( _this . startValue ) ) {
347+ return ;
348+ }
349+
350+ _this . startValue = this . props . value ;
351+ }
352+ } , {
353+ key : 'handleInteractionEnd' ,
354+ value : function handleInteractionEnd ( ) {
355+ var _this = internals . get ( this ) ;
356+
357+ if ( ! this . props . onChangeComplete || ! ( 0 , _util . isDefined ) ( _this . startValue ) ) {
358+ return ;
359+ }
360+
361+ if ( _this . startValue !== this . props . value ) {
362+ this . props . onChangeComplete ( this , this . props . value ) ;
363+ }
364+
365+ _this . startValue = null ;
366+ }
367+ } , {
368+ key : 'handleKeyDown' ,
369+ value : function handleKeyDown ( event ) {
370+ this . handleInteractionStart ( event ) ;
371+ }
372+ } , {
373+ key : 'handleKeyUp' ,
374+ value : function handleKeyUp ( event ) {
375+ this . handleInteractionEnd ( event ) ;
376+ }
377+ } , {
378+ key : 'handleMouseDown' ,
379+ value : function handleMouseDown ( event ) {
380+ var document = getDocument ( this ) ;
381+
382+ this . handleInteractionStart ( event ) ;
383+
384+ document . addEventListener ( 'mouseup' , this . handleMouseUp ) ;
385+ }
386+ } , {
387+ key : 'handleMouseUp' ,
388+ value : function handleMouseUp ( event ) {
389+ var document = getDocument ( this ) ;
390+
391+ this . handleInteractionEnd ( event ) ;
392+
393+ document . removeEventListener ( 'mouseup' , this . handleMouseUp ) ;
394+ }
395+ } , {
396+ key : 'handleTouchStart' ,
397+ value : function handleTouchStart ( event ) {
398+ var document = getDocument ( this ) ;
399+
400+ this . handleInteractionStart ( event ) ;
401+
402+ document . addEventListener ( 'touchend' , this . handleTouchEnd ) ;
403+ }
404+ } , {
405+ key : 'handleTouchEnd' ,
406+ value : function handleTouchEnd ( event ) {
407+ var document = getDocument ( this ) ;
408+
409+ this . handleInteractionEnd ( event ) ;
410+
411+ document . removeEventListener ( 'touchend' , this . handleTouchEnd ) ;
412+ }
331413 } , {
332414 key : 'render' ,
333415 value : function render ( ) {
@@ -342,7 +424,11 @@ var InputRange = (function (_React$Component) {
342424 {
343425 'aria-disabled' : this . props . disabled ,
344426 ref : 'inputRange' ,
345- className : componentClassName } ,
427+ className : componentClassName ,
428+ onKeyDown : this . handleKeyDown ,
429+ onKeyUp : this . handleKeyUp ,
430+ onMouseDown : this . handleMouseDown ,
431+ onTouchStart : this . handleTouchStart } ,
346432 _react2 [ 'default' ] . createElement (
347433 _Label2 [ 'default' ] ,
348434 {
@@ -404,6 +490,7 @@ InputRange.propTypes = {
404490 minValue : _propTypes . maxMinValuePropType ,
405491 name : _react2 [ 'default' ] . PropTypes . string ,
406492 onChange : _react2 [ 'default' ] . PropTypes . func . isRequired ,
493+ onChangeComplete : _react2 [ 'default' ] . PropTypes . func ,
407494 step : _react2 [ 'default' ] . PropTypes . number ,
408495 value : _propTypes . maxMinValuePropType
409496} ;
@@ -564,7 +651,7 @@ var Slider = (function (_React$Component) {
564651 } , {
565652 key : 'handleMouseMove' ,
566653 value : function handleMouseMove ( event ) {
567- this . props . onSliderMouseMove ( this , event ) ;
654+ this . props . onSliderMouseMove ( event , this ) ;
568655 }
569656 } , {
570657 key : 'handleTouchStart' ,
@@ -579,7 +666,7 @@ var Slider = (function (_React$Component) {
579666 } , {
580667 key : 'handleTouchMove' ,
581668 value : function handleTouchMove ( event ) {
582- this . props . onSliderMouseMove ( this , event ) ;
669+ this . props . onSliderMouseMove ( event , this ) ;
583670 }
584671 } , {
585672 key : 'handleTouchEnd' ,
@@ -594,7 +681,7 @@ var Slider = (function (_React$Component) {
594681 } , {
595682 key : 'handleKeyDown' ,
596683 value : function handleKeyDown ( event ) {
597- this . props . onSliderKeyDown ( this , event ) ;
684+ this . props . onSliderKeyDown ( event , this ) ;
598685 }
599686 } , {
600687 key : 'render' ,
@@ -714,7 +801,7 @@ var Track = (function (_React$Component) {
714801 y : 0
715802 } ;
716803
717- this . props . onTrackMouseDown ( this , position ) ;
804+ this . props . onTrackMouseDown ( event , this , position ) ;
718805 }
719806 } , {
720807 key : 'handleTouchStart' ,
@@ -883,6 +970,10 @@ function isObject(object) {
883970 return object !== null && typeof object === 'object' ;
884971}
885972
973+ function isDefined ( value ) {
974+ return value !== undefined && value !== null ;
975+ }
976+
886977function isEmpty ( obj ) {
887978 if ( ! obj ) {
888979 return true ;
@@ -940,6 +1031,7 @@ var util = {
9401031 clamp : clamp ,
9411032 distanceTo : distanceTo ,
9421033 extend : extend ,
1034+ isDefined : isDefined ,
9431035 isEmpty : isEmpty ,
9441036 isNumber : isNumber ,
9451037 isObject : isObject ,
0 commit comments