Skip to content

Commit

Permalink
fix(core): calculate distance to trigger drag-click (#1624)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
bcakmakoglu authored Sep 16, 2024
1 parent 1fa90ac commit 6692072
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-lions-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vue-flow/core": patch
---

Use calculated drag distance to trigger drag-click.
15 changes: 13 additions & 2 deletions packages/core/src/composables/useDrag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6692072

Please sign in to comment.