leongersen / noUiSlider

noUiSlider is a lightweight, ARIA-accessible JavaScript range slider with multi-touch and keyboard support. It is fully GPU animated: no reflows, so it is fast; even on older devices. It also fits wonderfully in responsive designs and has no dependencies.
https://refreshless.com/nouislider/
MIT License
5.64k stars 658 forks source link

Issue format #1189

Closed SylvainBailly closed 2 years ago

SylvainBailly commented 2 years ago

Hi, I got some issue with the number i pass to the slider. I use it with 2 associated inputs : image

Some numbers (like 78) are unreacheable end always rounded to former value (77 for 78). So if i write 78 in my left input the slider go to 77 as min.

Any idea why ? image

SylvainBailly commented 2 years ago

Forgot to say that if i console.log(value) just before set every seems ok but when i console.log elem.noUiSlider?.get(); right after .set() i got the shift.

I really hope you can help me :)

leongersen commented 2 years ago

Why are you passing true, true as additional arguments to set here?

leongersen commented 2 years ago

Anyway, your issue is likely in parseInt, which does not round.

SylvainBailly commented 2 years ago

But my number are strictly egal to 78 ? why the return value is 77.99999999 even if i remove parseInt it's totaly the same. If i remove 'true, true' so there are more number with this problem

leongersen commented 2 years ago

The slider isn't storing its positions as integers. You are taking the output, and instead of rounding, you truncate (so 77.99999999 to 77 instead of 87). You need to set your to formatter to a function that does the rounding you want, so say to: (value) => Math.round(value).

SylvainBailly commented 2 years ago

I feel myself dumb.. it work perfectly thanks :)

github-actions[bot] commented 2 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.