From 75cd24433abb01c8606b724adb04c8b206116a32 Mon Sep 17 00:00:00 2001 From: melloware Date: Sat, 3 Dec 2022 08:35:26 -0500 Subject: [PATCH] Fix #3738: Slider replace 0/100 with min/max values --- 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 + '%' };