Skip to content

Commit

Permalink
Fix #3738: Slider replace 0/100 with min/max values (#3739)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Dec 3, 2022
1 parent d5331d1 commit bb21718
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions components/lib/slider/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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 + '%' };
Expand All @@ -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 + '%' };
Expand Down

0 comments on commit bb21718

Please sign in to comment.