New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a "onGrab" event to the Slider #3575
Comments
Sorry, I don't see how this is different from |
Hi @adidahiya!
Hmm, well you could definitely just use Here's an example of how the const PlaybackTimeSlider = React.memo((props: IProps) => {
// A context object which contains the shared state about the current playback time.
const { videoTimeMillis, setVideoTimeMillis } = useContext(PlaybackContext);
// Has the user grabbed the time slider?
const [isGrabbed, setIsGrabbed] = useState(false);
const handleGrab = useCallback(() => setIsGrabbed(true), []);
// This is the current value of the slider
const [sliderTimeMillis, setSliderTimeMillis] = useState(videoTimeMillis);
// If the user releases the handle, immediately push the updated time to the context.
const handleRelease = useCallback(releasedValue => {
setIsGrabbed(false);
setVideoTimeMillis(releasedValue);
}, [setVideoTimeMillis]);
// If the time is updated externally, immediately reflect those changes on the slider
useEffect(() => { setSliderTimeMillis(videoTimeMillis) }, []);
useEffect(() => {
if (isGrabbed) {
// If the user has grabbed the handle, debounce updates to the video time while
// they're dragging it to prevent loading of frames that are just going to get dropped
debounce(() => { setVideoTimeMillis(sliderTimeMillis) }, 400);
} else {
// Otherwise we can immediately push the new video time
setVideoTimeMillis(sliderTimeMillis);
}
}, [isGrabbed, sliderTimeMillis]);
return (
<>
<Slider
value={sliderTimeMillis}
onChange={setSliderTimeMillis}
onGrab={handleGrab}
onRelease={handleRelease}
/>
{isPlaying && <PlayHead />}
</>
);
}); I hope that makes sense! |
@gerrod This would be very useful!
Very useful when controlling for example a video player. You need to detect change start to be able to pause playback otherwise the slider would tremble/wobble during scrubbing / seeking. |
If it is of any use, I am currently doing this React ref hack to be able to have a start phase: const element = ReactDOM.findDOMNode(
this.sliderRef.current
) as HTMLElement;
element.addEventListener("mousedown", this.onSliderChangeStart);
element.addEventListener("touchdown", this.onSliderChangeStart); The handle bubbles so no need to intercept that. But there are of course inconveniences, posted here because it may be helpful for someone. |
@iongion thanks for the bump and the link to that detailed slider API, that's very useful. I'm not sure when I'll get around to working on this, but I'm open to PRs |
Environment
Package version: @blueprintjs/core 3.15.1
Browser: Chrome 74+
Feature request
Currently the slider supports an
onChange
andonRelease
event - it would be useful to also have anonGrab
(or similar) event which is invoked when the user grabs the slider handle without releasing it.Examples
A scenario when this would be useful is when using the slider as a scrubber control for a video. If the value of the slider is updated due to the user grabbing the handle and sliding, we would want to:
The text was updated successfully, but these errors were encountered: