File tree 1 file changed +10
-2
lines changed
src/components/ReactSlider
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 {
575
575
return prepareOutValue ( this . state . value ) ;
576
576
}
577
577
578
- getClosestIndex ( pixelOffset ) {
578
+ getClosestIndex ( pixelOffset , nextValue ) {
579
579
let minDist = Number . MAX_VALUE ;
580
580
let closestIndex = - 1 ;
581
581
582
582
const { value } = this . state ;
583
583
const l = value . length ;
584
584
585
+ if ( new Set ( value ) . size === 1 ) {
586
+ if ( value [ 0 ] > nextValue ) {
587
+ return 0 ;
588
+ }
589
+
590
+ return value . length - 1 ;
591
+ }
592
+
585
593
for ( let i = 0 ; i < l ; i += 1 ) {
586
594
const offset = this . calcOffset ( value [ i ] ) ;
587
595
const dist = Math . abs ( pixelOffset - offset ) ;
@@ -771,8 +779,8 @@ class ReactSlider extends React.Component {
771
779
// and calls `callback` with that thumb's index.
772
780
forceValueFromPosition ( position , callback ) {
773
781
const pixelOffset = this . calcOffsetFromPosition ( position ) ;
774
- const closestIndex = this . getClosestIndex ( pixelOffset ) ;
775
782
const nextValue = trimAlignValue ( this . calcValue ( pixelOffset ) , this . props ) ;
783
+ const closestIndex = this . getClosestIndex ( pixelOffset , nextValue ) ;
776
784
777
785
// Clone this.state.value since we'll modify it temporarily
778
786
// eslint-disable-next-line zillow/react/no-access-state-in-setstate
You can’t perform that action at this time.
0 commit comments