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
21 changes: 15 additions & 6 deletions src/Range.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ class Range extends React.Component {
const nextBounds = [...state.bounds];
nextBounds[state.handle] = value;
let nextHandle = state.handle;
if (props.pushable !== false) {

if ((typeof props.pushable === 'boolean' && props.pushable !== false) ||
(typeof props.pushable === 'number' && props.pushable >= 0)) {
const originalValue = state.bounds[nextHandle];
this.pushSurroundingHandles(nextBounds, nextHandle, originalValue);
} else if (props.allowCross) {
Expand Down Expand Up @@ -207,12 +209,16 @@ class Range extends React.Component {
const value = bounds[handle];

let direction = 0;
if (bounds[handle + 1] - value < threshold) {
if (bounds[handle + 1] - value < threshold && threshold > 0) {
direction = +1; // push to right
}
if (value - bounds[handle - 1] < threshold) {
if (value - bounds[handle - 1] < threshold && threshold > 0) {
direction = -1; // push to left
}
if (threshold === 0 && (originalValue === bounds[handle - 1] ||
originalValue === bounds[handle + 1])) {
bounds.forEach((v, i, a) => a[i] === originalValue ? a[i] = value : a[i] = v);
}

if (direction === 0) { return; }

Expand All @@ -227,7 +233,7 @@ class Range extends React.Component {
pushHandle(bounds, handle, direction, amount) {
const originalValue = bounds[handle];
let currentValue = bounds[handle];
while (direction * (currentValue - originalValue) < amount) {
while (direction * (currentValue - originalValue) <= amount) {
if (!this.pushHandleOnePoint(bounds, handle, direction)) {
// can't push handle enough to create the needed `amount` gap, so we
// revert its position to the original value
Expand Down Expand Up @@ -271,12 +277,15 @@ class Range extends React.Component {
ensureValueNotConflict(val, { allowCross }) {
const state = this.state || {};
const { handle, bounds } = state;
const { pushable: threshold } = this.props;


/* eslint-disable eqeqeq */
if (!allowCross && handle != null) {
if (handle > 0 && val <= bounds[handle - 1]) {
if (threshold > 0 && handle > 0 && val <= bounds[handle - 1]) {
return bounds[handle - 1];
}
if (handle < bounds.length - 1 && val >= bounds[handle + 1]) {
if (threshold > 0 && handle < bounds.length - 1 && val >= bounds[handle + 1]) {
return bounds[handle + 1];
}
}
Expand Down