Marks in mui range Sliders gets duplicated because of two children with the same key

Viewed 38

I am experiencing a bug from the range slider of mui wherein the marks get duplicated when both of the thumb slider reached the farthest right.

Initially my slider is like this:

enter image description here

Once I slide both of the thumbs to the farthest right an error will occur on the console:

enter image description here

enter image description here

Then the mark would get duplicated like this:
enter image description here

The cause was that the SliderUnstyled uses the value from marks as its key. Because of this, when both of the thumbs reach the farthest right, both of them would have a value of 100 which triggers the error of duplicate keys.

Here is also a link of a codesandbox from another developer facing the same issue: https://codesandbox.io/s/material-demo-forked-tlu40e?file=/demo.js

I saw a similar issue from Github from this link: https://github.com/mui/material-ui/issues/31960

One solution there was to modify the SliderUnstyled.js file from "material-ui/packages/mui-base/src/SliderUnstyled/SliderUnstyled.js" wherein you need to change the key to the mark's index instead of the mark's value.

I've tried the solution from this https://github.com/mui/material-ui/pull/33526/commits/4ff58040654a4b75aa86691194df80bd2abd87b8 but I just want to ask if there is another solution to this issue wherein modifying the SliderUnstyled.js is not necessary.

1 Answers

Looking at the sandbox you linked and the mui documentation I believe you are using "marks" incorrectly. Marks appear to be used as static markers on the slider. You are instead assigning them to be the value, which does not appear to be necessary.

See: https://mui.com/material-ui/react-slider/

Related