diff --git a/.changeset/poor-lions-rush.md b/.changeset/poor-lions-rush.md new file mode 100644 index 000000000..6467b3508 --- /dev/null +++ b/.changeset/poor-lions-rush.md @@ -0,0 +1,5 @@ +--- +"@vue-flow/core": patch +--- + +Use calculated drag distance to trigger drag-click. diff --git a/packages/core/src/composables/useDrag.ts b/packages/core/src/composables/useDrag.ts index f66429705..b505d334e 100644 --- a/packages/core/src/composables/useDrag.ts +++ b/packages/core/src/composables/useDrag.ts @@ -229,8 +229,19 @@ export function useDrag(params: UseDragParams) { } const eventEnd = (event: UseDragEvent) => { - if (!dragging.value && !multiSelectionActive.value) { - onClick?.(event.sourceEvent) + if (!dragStarted && !dragging.value && !multiSelectionActive.value) { + const pointerPos = getPointerPosition(event) + + const x = pointerPos.xSnapped - (lastPos.x ?? 0) + const y = pointerPos.ySnapped - (lastPos.y ?? 0) + const distance = Math.sqrt(x * x + y * y) + + // dispatch a click event if the node was attempted to be dragged but the threshold was not exceeded + if (distance !== 0 && distance <= nodeDragThreshold.value) { + onClick?.(event.sourceEvent) + } + + return } dragging.value = false