Skip to content

Commit

Permalink
refactor: sepated handlemove into handlemouse and handletouch move
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelLimaC committed Mar 1, 2024
1 parent 3070763 commit c8b4437
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/components/RangeSlider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ export default function RangeSlider({
this.emit('interactionEnd', currentValue);
};

const handleMove = (event) => {
const handleMouseMove = (event) => {
event.preventDefault();
const clientX = event.type === 'touchmove' ? event.touches[0].clientX : event.clientX;
const { clientX } = event;
moveBackground(clientX);
};

const handleTouchMove = (event) => {
event.preventDefault();
const { clientX } = event.touches[0];
moveBackground(clientX);
};

Expand All @@ -89,16 +95,16 @@ export default function RangeSlider({
});

this.listen('mount', () => {
document.addEventListener('mousemove', handleMove);
document.addEventListener('mousemove', handleMouseMove);
document.addEventListener('mouseup', handleEnd);
document.addEventListener('touchmove', handleMove);
document.addEventListener('touchmove', handleTouchMove);
document.addEventListener('touchend', handleEnd);
});

this.listen('unmount', () => {
document.removeEventListener('mousemove', handleMove);
document.removeEventListener('mousemove', handleMouseMove);
document.removeEventListener('mouseup', handleEnd);
document.removeEventListener('touchmove', handleMove);
document.removeEventListener('touchmove', handleTouchMove);
document.removeEventListener('touchend', handleEnd);
});
}
Expand Down

0 comments on commit c8b4437

Please sign in to comment.