Skip to content

Commit ecfb922

Browse files
CodySchaafoliviertassinari
authored andcommitted
[Slider] Fix small step example
1 parent db48077 commit ecfb922

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

packages/material-ui-unstyled/src/SliderUnstyled/SliderUnstyled.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -304,21 +304,24 @@ const SliderUnstyled = React.forwardRef(function SliderUnstyled(props, ref) {
304304

305305
const handleHiddenInputChange = useEventCallback((event) => {
306306
const index = Number(event.currentTarget.getAttribute('data-index'));
307+
const value = values[index];
308+
const marksValues = marks.map((mark) => mark.value);
309+
const marksIndex = marksValues.indexOf(value);
307310

308-
let newValue = parseInt(event.target.value, 10); // TODO this might need to use roundValueToStep instead or something
309-
310-
newValue = clamp(newValue, min, max); // todo might not be needed since input won't allow it to go outside
311+
// TODO this might need to use roundValueToStep instead or something
312+
// but since the native input respects the step it doesn't look like we need it
313+
let newValue = event.target.valueAsNumber;
314+
// TODO add test to make sure when value/step is -4e-8 it still works
311315

312316
if (marks && step == null) {
313-
const markValues = marks.map((mark) => mark.value);
314-
const currentMarkIndex = markValues.indexOf(values[index]);
315-
316317
newValue =
317-
newValue < values[index]
318-
? markValues[currentMarkIndex - 1]
319-
: markValues[currentMarkIndex + 1];
318+
newValue < value
319+
? marksValues[marksIndex - 1]
320+
: marksValues[marksIndex + 1];
320321
}
321322

323+
newValue = clamp(newValue, min, max); // todo might not be needed since input won't allow it to go outside
324+
322325
if (range) {
323326
const previousValue = newValue;
324327
newValue = setValueIndex({

0 commit comments

Comments
 (0)