Skip to content

Commit 8bb5d0f

Browse files
committed
fix(ui): fix miss right arg in range slider
1 parent c7c155d commit 8bb5d0f

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

packages/ui/src/components/slider/Slider.tsx

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -246,27 +246,6 @@ export function DSlider(props: DSliderProps): JSX.Element | null {
246246
}
247247
};
248248

249-
const handleChange = (e: React.ChangeEvent<HTMLInputElement>, isLeft = true) => {
250-
const val = toNumber(e.currentTarget.value);
251-
if (dRange) {
252-
const index = isLeft ? 0 : 1;
253-
changeValue((draft) => {
254-
const offset = val - draft[index];
255-
const isAdd = offset > 0;
256-
draft[index] = val;
257-
if (isNumber(dRangeMinDistance) && draft[1] - draft[0] < dRangeMinDistance) {
258-
const _index = isLeft ? 1 : 0;
259-
draft[_index] = getValue(draft[_index] + offset, isAdd ? 'ceil' : 'floor');
260-
if (draft[1] - draft[0] < dRangeMinDistance) {
261-
draft[index] = getValue(draft[_index] + (isAdd ? -dRangeMinDistance : dRangeMinDistance), isAdd ? 'floor' : 'ceil');
262-
}
263-
}
264-
});
265-
} else {
266-
changeValue(val);
267-
}
268-
};
269-
270249
useEffect(() => {
271250
if (thumbPoint) {
272251
tooltipLeftRef.current?.updatePosition();
@@ -414,7 +393,29 @@ export function DSlider(props: DSliderProps): JSX.Element | null {
414393
min={dMin}
415394
step={dStep ?? undefined}
416395
aria-orientation={dVertical ? 'vertical' : 'horizontal'}
417-
onChange={handleChange}
396+
onChange={(e) => {
397+
const val = toNumber(e.currentTarget.value);
398+
if (dRange) {
399+
const index = isLeft ? 0 : 1;
400+
changeValue((draft) => {
401+
const offset = val - draft[index];
402+
const isAdd = offset > 0;
403+
draft[index] = val;
404+
if (isNumber(dRangeMinDistance) && draft[1] - draft[0] < dRangeMinDistance) {
405+
const _index = isLeft ? 1 : 0;
406+
draft[_index] = getValue(draft[_index] + offset, isAdd ? 'ceil' : 'floor');
407+
if (draft[1] - draft[0] < dRangeMinDistance) {
408+
draft[index] = getValue(
409+
draft[_index] + (isAdd ? -dRangeMinDistance : dRangeMinDistance),
410+
isAdd ? 'floor' : 'ceil'
411+
);
412+
}
413+
}
414+
});
415+
} else {
416+
changeValue(val);
417+
}
418+
}}
418419
onFocus={() => {
419420
setFocusDot(isLeft ? 'left' : 'right');
420421
}}

0 commit comments

Comments
 (0)