tajo / react-range

🎚️Range input with a slider. Accessible. Bring your own styles and markup.
https://react-range.pages.dev
MIT License
847 stars 97 forks source link

Slider jumps back to the start position in iOS Safari #180

Closed shivamragnar closed 1 month ago

shivamragnar commented 2 years ago

Hey @tajo , Thanks for this amazing library. I think I am getting a issue which other users might also have. While using the slider in iOS Safari, the slider jumps back to the start position where we started the dragging from. It does not happen everytime to me but yeah it's pretty visible. What i found out was, the onChange event is fired with the wrong value, after we let off the thumb. This is extra onChange that is fired. I am pretty sure it must be iOS or safari causing it, but I hope if we can workaround this. There is a similar issue I found out https://github.com/mui/material-ui/issues/31869. Here is what I am using

<ImageSlider
    min={3}
    max={100}
    step={0.1}
    values={[value]}
    onChange={handleOnChange}
    onFinalChange={handleFinalChange}
    renderTrack={/* React Node */}
    renderThumb={/* React Node */}
 </>

ezgif com-gif-maker

luizcieslak commented 7 months ago

@shivamragnar have you found a solution for this?

EDIT: This workaround did the trick: https://github.com/mui/material-ui/issues/31869#issuecomment-1347358777

neeeded to place it in the renderTrack prop like:

                    renderTrack={({ props, children, isDragged }) => (
                        <div
                            onMouseDown={e => {
                                if (iOS() && e.type === 'mousedown') {
                                    return // I love IOS and safari
                                }
                                props.onMouseDown(e)
                            }}