Open oodavid opened 7 years ago
Excellent report: I'll look into it.
Happy to contribute.
I started going through the sources and found that preventDefault
is triggered as part of a general event utility method here:
I didn't fancy messing with that before seeing how it would affect the rest of the library.
preventDefault
anyway. Would you be willing to help with testing?Absolutely 👍
Great! The dev
branch has the changes, in this commit. Fixing #785 solves this issue from Chrome (desktop + mobile), Firefox and Edge, but not for iOS Safari, as that doesn't support touch-action: none
.
Other browsers have the heuristics do separate a touchstart
from a scroll intent for elements with touch-action: none
, but as noUiSlider needs to act (by means of preventDefault
) on the touchstart
event, I don't really see a way to fix this for iOS.
I'm unsure but is this still under development?
I've been out of the loop for a little while, so I'll have to do some reading up on the recent changes browsers have been making. I know the Chrome team recently made some changes in this area. I'll add some details here.
noUiSlider currently uses touch-action: none
to guarantee the page doesn't scroll when using a slider. You could change that to touch-action: pan-up pan-down
(etc.) for horizontal sliders, with left/right for vertical. That's not a change I think is smart: any touches near the slider shouldn't be at risk of glitchy behaviour, such a page scroll. Safari doesn't support these properties anyway, so the benefit is small.
Completely appreciate the amount of effort that has gone into this, its the first thing I've come across when testing this on mobile with a scrollable page. Its SUCH a shame because everything about this slider is perfect and I desperately want to use it..!
Has anybody managed to even hack their way around this to make the sliders not react on vertical scrolling? The only thing I can think of doing is blocking the slider until a user interacts with it, but I don't really want to do.
Is one way of looking at this to detect the scroll direction on the start event and if its vertical (not horizontal) adding a disabled property and disabling the slider until scrolled (and the end event is fired) and then remove it again?
Noticed here:
https://refreshless.com/nouislider/more/
If I disable the slider, then I can scroll past it happily. Just wondered if you guys think this could work.
Solution that works for me:
touch-action: pan-y
CSS style on the sliderbehavior: none
in the slider initialization - users can't tap the slider to set its value, but it prevents them from accidently changing the slider value while scrolling
Issue
Touch scrolling is prevented when the initial touchpoint is on a noUiSlider:
Proposal
touchstart
coordinatestouchmove
is a set distance away fromtouchstart
- maybe3vh
, or some configurable valuetouchend
Alternatively, on step
3
, you could start blocking the scroll event if parallel to the component