From e70082f6ccb949ada7304ec385d5ac3d3859e79d Mon Sep 17 00:00:00 2001 From: Lucas Date: Thu, 29 Oct 2026 10:14:49 +0100 Subject: [PATCH] fix: dont move sliders when horizontal scroll --- .../VerticalSlider/VerticalSlider.tsx | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/src/components/VerticalSlider/VerticalSlider.tsx b/src/components/VerticalSlider/VerticalSlider.tsx index 751c9ba..392db11 100644 --- a/src/components/VerticalSlider/VerticalSlider.tsx +++ b/src/components/VerticalSlider/VerticalSlider.tsx @@ -49,6 +49,7 @@ function formatValueDefault(v: number, decimals: number) { return v.toFixed(decimals); } +const TOUCH_INTENT_PX = 20; const MIN_TICKS = 3; const MAX_TICK_SPACING_PX = 16; const WHEEL_COMMIT_DELAY_MS = 250; @@ -214,6 +215,7 @@ export default function VerticalSlider({ // --- per-input-method "is the user still doing something" flags -------- const dragging = useRef(false); const activePointerId = useRef(null); + const pendingTouch = useRef<{ id: number; x: number; y: number } | null>(null); const keysHeld = useRef>(new Set()); const wheelTimeout = useRef | null>(null); @@ -353,6 +355,7 @@ export default function VerticalSlider({ dragging.current = false; activePointerId.current = null; + pendingTouch.current = null; keysHeld.current.clear(); pendingCommit.current = null; if (wheelTimeout.current) { @@ -482,6 +485,30 @@ export default function VerticalSlider({ // --- pointer / mouse --------------------------------------------------- + function handlePointerMove(e: React.PointerEvent) { + const pending = pendingTouch.current; + if (pending && e.pointerId === pending.id) { + const dx = e.clientX - pending.x; + const dy = e.clientY - pending.y; + if (Math.abs(dx) < TOUCH_INTENT_PX && Math.abs(dy) < TOUCH_INTENT_PX) return; + + pendingTouch.current = null; + + if (Math.abs(dy) > Math.abs(dx)) { + // Vertical intent: start the drag now + dragging.current = true; + activePointerId.current = e.pointerId; + e.currentTarget.setPointerCapture(e.pointerId); + valueFromPointer(e.clientY); + } + // Horizontal intent: do nothing, the browser scrolls the strip + return; + } + + if (!dragging.current || e.pointerId !== activePointerId.current) return; + valueFromPointer(e.clientY); + } + function valueFromPointer(clientY: number) { if (!sliderRef.current) return; const rect = sliderRef.current.getBoundingClientRect(); @@ -492,6 +519,14 @@ export default function VerticalSlider({ function startDrag(e: React.PointerEvent) { if (disabled) return; + + // Touch: don't move anything yet. Wait to see if the gesture is vertical + // (fader) or horizontal (the strip scrolling). + if (e.pointerType === 'touch') { + if (dragging.current || pendingTouch.current) return; + pendingTouch.current = { id: e.pointerId, x: e.clientX, y: e.clientY }; + return; + } if (e.pointerType === 'mouse' && e.button !== 0) return; // Ignore a second pointer (multi-touch) while one is already dragging. if (dragging.current) return; @@ -503,12 +538,11 @@ export default function VerticalSlider({ valueFromPointer(e.clientY); } - function handlePointerMove(e: React.PointerEvent) { - if (!dragging.current || e.pointerId !== activePointerId.current) return; - valueFromPointer(e.clientY); - } - function endDrag(e: React.PointerEvent) { + if (pendingTouch.current?.id === e.pointerId) { + pendingTouch.current = null; + return; + } if (!dragging.current || e.pointerId !== activePointerId.current) return; // Release the gesture synchronously. The old code awaited onChange first,