Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/components/ReactSlider/ReactSlider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -575,13 +575,21 @@ class ReactSlider extends React.Component {
return prepareOutValue(this.state.value);
}

getClosestIndex(pixelOffset) {
getClosestIndex(pixelOffset, nextValue) {
let minDist = Number.MAX_VALUE;
let closestIndex = -1;

const { value } = this.state;
const l = value.length;

if (new Set(value).size === 1) {
if (value[0] > nextValue) {
return 0;
}

return value.length - 1;
}

for (let i = 0; i < l; i += 1) {
const offset = this.calcOffset(value[i]);
const dist = Math.abs(pixelOffset - offset);
Expand Down Expand Up @@ -771,8 +779,8 @@ class ReactSlider extends React.Component {
// and calls `callback` with that thumb's index.
forceValueFromPosition(position, callback) {
const pixelOffset = this.calcOffsetFromPosition(position);
const closestIndex = this.getClosestIndex(pixelOffset);
const nextValue = trimAlignValue(this.calcValue(pixelOffset), this.props);
const closestIndex = this.getClosestIndex(pixelOffset, nextValue);

// Clone this.state.value since we'll modify it temporarily
// eslint-disable-next-line zillow/react/no-access-state-in-setstate
Expand Down