From bb2171896e54c1533d1aef288351d497a25b986b Mon Sep 17 00:00:00 2001 From: Melloware Date: Sat, 3 Dec 2022 08:41:10 -0500 Subject: [PATCH] Fix #3738: Slider replace 0/100 with min/max values (#3739) --- components/lib/slider/Slider.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/components/lib/slider/Slider.js b/components/lib/slider/Slider.js index 0b43f02a44..64b7ad0c6b 100644 --- a/components/lib/slider/Slider.js +++ b/components/lib/slider/Slider.js @@ -12,7 +12,7 @@ export const Slider = React.memo( const initY = React.useRef(0); const barWidth = React.useRef(0); const barHeight = React.useRef(0); - const value = props.range ? props.value || [0, 100] : props.value || 0; + const value = props.range ? props.value || [props.min, props.max] : props.value || 0; const horizontal = props.orientation === 'horizontal'; const vertical = props.orientation === 'vertical'; @@ -205,8 +205,9 @@ export const Slider = React.memo( }; const createRangeSlider = () => { - const handleValueStart = ((value[0] < props.min ? 0 : value[0] - props.min) * 100) / (props.max - props.min); - const handleValueEnd = ((value[1] > props.max ? 100 : value[1] - props.min) * 100) / (props.max - props.min); + const handleValueStart = ((value[0] < props.min ? props.min : value[0] - props.min) * 100) / (props.max - props.min); + const handleValueEnd = ((value[1] > props.max ? props.max : value[1] - props.min) * 100) / (props.max - props.min); + const rangeStartHandle = horizontal ? createHandle(handleValueStart, null, 0) : createHandle(null, handleValueStart, 0); const rangeEndHandle = horizontal ? createHandle(handleValueEnd, null, 1) : createHandle(null, handleValueEnd, 1); const rangeStyle = horizontal ? { left: handleValueStart + '%', width: handleValueEnd - handleValueStart + '%' } : { bottom: handleValueStart + '%', height: handleValueEnd - handleValueStart + '%' }; @@ -223,8 +224,8 @@ export const Slider = React.memo( const createSingleSlider = () => { let handleValue; - if (value < props.min) handleValue = 0; - else if (value > props.max) handleValue = 100; + if (value < props.min) handleValue = props.min; + else if (value > props.max) handleValue = props.max; else handleValue = ((value - props.min) * 100) / (props.max - props.min); const rangeStyle = horizontal ? { width: handleValue + '%' } : { height: handleValue + '%' };