From 6cc30429b54715650ccd7851287cd0f142daba44 Mon Sep 17 00:00:00 2001 From: Braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Mon, 16 Sep 2024 12:58:04 +0200 Subject: [PATCH] fix(core): calculate distance to trigger drag-click (#1624) * fix(core): calculate distance to trigger drag-click Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> * chore(changeset): add Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> --------- Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> --- .changeset/poor-lions-rush.md | 5 +++++ packages/core/src/composables/useDrag.ts | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .changeset/poor-lions-rush.md diff --git a/.changeset/poor-lions-rush.md b/.changeset/poor-lions-rush.md new file mode 100644 index 00000000..6467b350 --- /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 f6642970..b505d334 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