From 9dccdb6c90fd515f72b539c206896962fa8c16b3 Mon Sep 17 00:00:00 2001 From: Benjy Cui Date: Fri, 30 Oct 2015 17:53:24 +0800 Subject: [PATCH] fix: `lowerBound` should be smaller than `upperBound` --- src/Slider.jsx | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Slider.jsx b/src/Slider.jsx index 999f967..078d053 100644 --- a/src/Slider.jsx +++ b/src/Slider.jsx @@ -156,10 +156,23 @@ class Slider extends React.Component { this.startPosition = position; const {upperBound, lowerBound} = this.state; - const isUpperBoundCloser = Math.abs(upperBound - value) < Math.abs(lowerBound - value); - let valueNeedChanging = (!this.props.range || isUpperBoundCloser) ? 'upperBound' : 'lowerBound'; - const isAtTheSamePoint = (upperBound === lowerBound); - valueNeedChanging = isAtTheSamePoint ? this.state.recent : valueNeedChanging; + + let valueNeedChanging = 'upperBound'; + if (this.props.range) { + const isLowerBoundCloser = Math.abs(upperBound - value) > Math.abs(lowerBound - value); + if (isLowerBoundCloser) { + valueNeedChanging = 'lowerBound'; + } + + const isAtTheSamePoint = (upperBound === lowerBound); + if (isAtTheSamePoint) { + valueNeedChanging = this.state.recent; + } + + if (isAtTheSamePoint && (value !== upperBound)) { + valueNeedChanging = value < upperBound ? 'lowerBound' : 'upperBound'; + } + } this.setState({ handle: valueNeedChanging,