Skip to content

Commit

Permalink
refactor: replace touchstart and mousedown event bindings with `p…
Browse files Browse the repository at this point in the history
…ointerdown`
  • Loading branch information
nerdyman committed Jan 5, 2023
1 parent 87ba39e commit caafd1a
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/ReactCompareSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,19 +295,19 @@ export const ReactCompareSlider: FC<ReactCompareSliderDetailedProps> = ({
useEffect(() => {
const containerRef = rootContainerRef.current as HTMLDivElement;

const handleMouseLeave = (): void => {
const handlePointerLeave = (): void => {
if (isDragging) return;
handlePointerUp();
};

if (changePositionOnHover) {
containerRef.addEventListener('pointermove', handlePointerMove, EVENT_PASSIVE_PARAMS);
containerRef.addEventListener('pointerleave', handleMouseLeave, EVENT_PASSIVE_PARAMS);
containerRef.addEventListener('pointerleave', handlePointerLeave, EVENT_PASSIVE_PARAMS);
}

return () => {
containerRef.removeEventListener('pointermove', handlePointerMove);
containerRef.removeEventListener('pointerleave', handleMouseLeave);
containerRef.removeEventListener('pointerleave', handlePointerLeave);
};
}, [changePositionOnHover, handlePointerMove, handlePointerUp, isDragging]);

Expand All @@ -326,14 +326,7 @@ export const ReactCompareSlider: FC<ReactCompareSliderDetailedProps> = ({
);

useEventListener(
'mousedown',
handlePointerDown,
interactiveTarget as HTMLDivElement,
EVENT_CAPTURE_PARAMS,
);

useEventListener(
'touchstart',
'pointerdown',
handlePointerDown,
interactiveTarget as HTMLDivElement,
EVENT_CAPTURE_PARAMS,
Expand Down

0 comments on commit caafd1a

Please sign in to comment.