[Slider] Fix slider focus in scrollable context #3118
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Previously if a Slider was used in a context where one has to scroll to view the entire range of the Slider, and the Slider was used in conjunction with a backed value (i.e.
Value
andonValueChange
props are provided) then unexpected scrolling would occur with the following steps.Then the
.focus()
in theonChange
handler would scroll back to the last location of the Slider thumb, and then the value would be updated. Thus the Slider thumb would be at the location you scrolled to, while the user would be at the location where the slider thumb was before.See video for short demo.
slider-demo.mp4
This fix prevents scrolling when focusing the Slider Thumb so the location in the scroll context remains stable.
Current behavior can be observed in the following Codesandbox https://codesandbox.io/p/devbox/damp-microservice-n4hz7x
I also included a story in Storybook where the Slider is placed in a scroll container where the fixed behavior can be observed.
Motivation
One might wonder why you would have a Slider so wide that you need to scroll. I am currently building a diagram where the x axis represents time and in that context it is quite likely that the whole diagram represents 24 hours, but the user only sees 2~3 hours on their screen at a time in order to observe the necessary details.