Merge pull request #5489 from Sec-ant/feat/node-drag-distance

fix: node selection instability by using client coordinates for drag threshold
This commit is contained in:
Peter Kogo
2025-09-02 10:35:57 +02:00
committed by GitHub
2 changed files with 9 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
'@xyflow/system': patch
---
Fix nodeDragThreshold changing with zoom level

View File

@@ -334,8 +334,10 @@ export function XYDrag<OnNodeDrag extends (e: any, nodes: any, node: any) => voi
}
if (!dragStarted) {
const x = pointerPos.xSnapped - (lastPos.x ?? 0);
const y = pointerPos.ySnapped - (lastPos.y ?? 0);
// Calculate distance in client coordinates for consistent drag threshold behavior across zoom levels
const currentMousePosition = getEventPosition(event.sourceEvent, containerBounds!);
const x = currentMousePosition.x - mousePosition.x;
const y = currentMousePosition.y - mousePosition.y;
const distance = Math.sqrt(x * x + y * y);
if (distance > nodeDragThreshold) {