Skip to content

Commit 27979e4

Browse files
Merge pull request #50 from SimformSolutionsPvtLtd/fix/UNT-T22232_fix_inconsistent_behaviour_with_step_0.1
fix: UNT-T22232 inconsistent behaviour with step 0.1
2 parents 34ff552 + d23263f commit 27979e4

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/components/RadialSlider/RadialSlider.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,18 @@ const RadialSlider = (props: RadialSliderProps & typeof defaultProps) => {
103103
const onPressButtons = (type: string) => {
104104
if (type === 'up' && max > value) {
105105
setValue((prevState: number) => {
106-
prevValue.current = prevState + step;
106+
const calculatedValue = prevState + step;
107+
const roundedValue = parseFloat(calculatedValue.toFixed(1));
107108

108-
return prevState + step;
109+
return roundedValue;
109110
});
110111
} else if (type === 'down' && min < value) {
111112
setValue((prevState: number) => {
112-
prevValue.current = prevState - step;
113+
const calculatedValue = prevState - step;
114+
const roundedValue = parseFloat(calculatedValue.toFixed(1));
115+
prevValue.current = roundedValue;
113116

114-
return prevState - step;
117+
return roundedValue;
115118
});
116119
}
117120
};

src/components/RadialSlider/hooks/useSliderAnimation.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,14 @@ const useSliderAnimation = (props: RadialSliderAnimationHookProps) => {
123123
nValue = Math.max(min, Math.min(max, nValue));
124124

125125
setValue((prevState: number) => {
126-
prevValue.current = Math.round(
127-
Math.abs(nValue - prevState) > diff / 4 ? prevState : nValue
128-
);
129-
return Math.round(
130-
Math.abs(nValue - prevState) > diff / 4 ? prevState : nValue
131-
);
126+
const roundedValue = parseFloat(nValue.toFixed(1));
127+
prevValue.current =
128+
Math.abs(roundedValue - prevState) > diff / 4
129+
? prevState
130+
: roundedValue;
131+
return Math.abs(roundedValue - prevState) > diff / 4
132+
? prevState
133+
: roundedValue;
132134
});
133135

134136
onChange(prevValue.current);

0 commit comments

Comments
 (0)