File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
src/components/ReactSlider Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -575,13 +575,21 @@ class ReactSlider extends React.Component {
575575 return prepareOutValue ( this . state . value ) ;
576576 }
577577
578- getClosestIndex ( pixelOffset ) {
578+ getClosestIndex ( pixelOffset , nextValue ) {
579579 let minDist = Number . MAX_VALUE ;
580580 let closestIndex = - 1 ;
581581
582582 const { value } = this . state ;
583583 const l = value . length ;
584584
585+ if ( new Set ( value ) . size === 1 ) {
586+ if ( value [ 0 ] > nextValue ) {
587+ return 0 ;
588+ }
589+
590+ return value . length - 1 ;
591+ }
592+
585593 for ( let i = 0 ; i < l ; i += 1 ) {
586594 const offset = this . calcOffset ( value [ i ] ) ;
587595 const dist = Math . abs ( pixelOffset - offset ) ;
@@ -771,8 +779,8 @@ class ReactSlider extends React.Component {
771779 // and calls `callback` with that thumb's index.
772780 forceValueFromPosition ( position , callback ) {
773781 const pixelOffset = this . calcOffsetFromPosition ( position ) ;
774- const closestIndex = this . getClosestIndex ( pixelOffset ) ;
775782 const nextValue = trimAlignValue ( this . calcValue ( pixelOffset ) , this . props ) ;
783+ const closestIndex = this . getClosestIndex ( pixelOffset , nextValue ) ;
776784
777785 // Clone this.state.value since we'll modify it temporarily
778786 // eslint-disable-next-line zillow/react/no-access-state-in-setstate
You can’t perform that action at this time.
0 commit comments