Skip to content

Commit 265f928

Browse files
committed
fix(core): subtract container bounds when getting pointer position (#1829)
* fix(core): subtract container bounds when getting pointer position Signed-off-by: braks <[email protected]> * chore(changeset): add Signed-off-by: braks <[email protected]> * chore: cleanup Signed-off-by: braks <[email protected]> --------- Signed-off-by: braks <[email protected]>
1 parent 7d9ffe3 commit 265f928

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

.changeset/great-jokes-arrive.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+
Subtract container bounds when calculating pointer position.

packages/core/src/composables/useGetPointerPosition.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@ import type { UseDragEvent } from './useDrag'
99
* @internal
1010
*/
1111
export function useGetPointerPosition() {
12-
const { viewport, snapGrid, snapToGrid } = useVueFlow()
12+
const { viewport, snapGrid, snapToGrid, vueFlowRef } = useVueFlow()
1313

1414
// returns the pointer position projected to the VF coordinate system
1515
return (event: UseDragEvent | MouseTouchEvent) => {
16+
const containerBounds = vueFlowRef.value?.getBoundingClientRect() ?? { left: 0, top: 0 }
1617
const evt = isUseDragEvent(event) ? event.sourceEvent : event
1718

18-
const { x, y } = getEventPosition(evt)
19+
const { x, y } = getEventPosition(evt, containerBounds as DOMRect)
1920
const pointerPos = pointToRendererPoint({ x, y }, viewport.value)
2021
const { x: xSnapped, y: ySnapped } = snapToGrid.value ? snapPosition(pointerPos, snapGrid.value) : pointerPos
2122

22-
// we need the snapped position in order to be able to skip unnecessary drag events
23+
// we need the snapped position to be able to skip unnecessary drag events
2324
return {
2425
xSnapped,
2526
ySnapped,

0 commit comments

Comments
 (0)