Skip to content
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

dispatch slideEnd when pointerCapture is lost #3408

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/react/slider/src/slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ const SliderImpl = React.forwardRef<SliderImplElement, SliderImplProps>(
...sliderProps
} = props;
const context = useSliderContext(SLIDER_NAME, __scopeSlider);
const isDragging = React.useRef(false);

return (
<Primitive.span
Expand All @@ -430,6 +431,7 @@ const SliderImpl = React.forwardRef<SliderImplElement, SliderImplProps>(
onPointerDown={composeEventHandlers(props.onPointerDown, (event) => {
const target = event.target as HTMLElement;
target.setPointerCapture(event.pointerId);
isDragging.current = true;
// Prevent browser focus behaviour because we focus a thumb manually when values change.
event.preventDefault();
// Touch devices have a delay before focusing so won't focus if touch immediately moves
Expand All @@ -449,8 +451,15 @@ const SliderImpl = React.forwardRef<SliderImplElement, SliderImplProps>(
if (target.hasPointerCapture(event.pointerId)) {
target.releasePointerCapture(event.pointerId);
onSlideEnd(event);
isDragging.current = false;
}
})}
onLostPointerCapture={composeEventHandlers(props.onLostPointerCapture, (event) => {
if (isDragging.current) {
onSlideEnd(event);
}
isDragging.current = false;
})}
/>
);
}
Expand Down