fix: dont move sliders when horizontal scroll
This commit is contained in:
@@ -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<number | null>(null);
|
||||
const pendingTouch = useRef<{ id: number; x: number; y: number } | null>(null);
|
||||
const keysHeld = useRef<Set<string>>(new Set());
|
||||
const wheelTimeout = useRef<ReturnType<typeof setTimeout> | 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<HTMLDivElement>) {
|
||||
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<HTMLDivElement>) {
|
||||
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<HTMLDivElement>) {
|
||||
if (!dragging.current || e.pointerId !== activePointerId.current) return;
|
||||
valueFromPointer(e.clientY);
|
||||
}
|
||||
|
||||
function endDrag(e: React.PointerEvent<HTMLDivElement>) {
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user