Skip to content

Commit 8539731

Browse files
committed
fix(core): dispatch click if drag move was attempted (#1534)
* fix(core): dispatch click if drag move was attempted * chore(core): cleanup
1 parent d4ccb11 commit 8539731

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

.changeset/moody-apricots-rhyme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vue-flow/core": patch
3+
---
4+
5+
Dispatch click if drag move was attempted and threshold was not crossed, ignoring any movement that's too small to be considered a drag at all

packages/core/src/components/Nodes/NodeWrapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ const NodeWrapper = defineComponent({
130130
emit.dragStop(event)
131131
},
132132
onClick(event) {
133-
emit.click({ node, event })
133+
onSelectNode(event)
134134
},
135135
})
136136

packages/core/src/composables/useDrag.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ export function useDrag(params: UseDragParams) {
7373
let mousePosition: XYPosition = { x: 0, y: 0 }
7474
let dragEvent: MouseEvent | null = null
7575
let dragStarted = false
76-
let dragAborted = false
7776

7877
let autoPanId = 0
7978
let autoPanStarted = false
@@ -218,9 +217,6 @@ export function useDrag(params: UseDragParams) {
218217
if (distance > nodeDragThreshold.value) {
219218
startDrag(event, nodeEl)
220219
}
221-
222-
// we have to ignore very small movements as they would be picked up as regular clicks even though a potential drag might have been registered as well
223-
dragAborted = distance >= 0.5 && distance < nodeDragThreshold.value
224220
}
225221

226222
// skip events without movement
@@ -234,10 +230,15 @@ export function useDrag(params: UseDragParams) {
234230

235231
const eventEnd = (event: UseDragEvent) => {
236232
if (!dragStarted) {
237-
// if the node was dragged without any movement, and we're not dragging a selection, we want to emit the node-click event
238-
if (dragAborted && onClick) {
233+
const pointerPos = getPointerPosition(event)
234+
235+
const x = pointerPos.xSnapped - (lastPos.x ?? 0)
236+
const y = pointerPos.ySnapped - (lastPos.y ?? 0)
237+
const distance = Math.sqrt(x * x + y * y)
238+
239+
// dispatch a click event if the node was attempted to be dragged but the threshold was not exceeded
240+
if (distance !== 0 && distance <= nodeDragThreshold.value) {
239241
onClick?.(event.sourceEvent)
240-
dragAborted = false
241242
}
242243

243244
return
@@ -246,7 +247,6 @@ export function useDrag(params: UseDragParams) {
246247
dragging.value = false
247248
autoPanStarted = false
248249
dragStarted = false
249-
dragAborted = false
250250

251251
cancelAnimationFrame(autoPanId)
252252

0 commit comments

Comments
 (0)