From 3010d8d1c5c55de66e28c61a110245a910dc143b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Fanton?= Date: Wed, 18 Sep 2024 12:30:08 +0000 Subject: [PATCH] Added preventOverlap flag to DragControls --- src/web/DragControls.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/web/DragControls.tsx b/src/web/DragControls.tsx index 0a9527121..cf7e24105 100644 --- a/src/web/DragControls.tsx +++ b/src/web/DragControls.tsx @@ -38,6 +38,7 @@ export type DragControlsProps = { onDragEnd?: () => void children: React.ReactNode dragConfig?: DragConfig + preventOverlap?: boolean /** If preventOverlap is true, other overlapping DragControls will not be draggable */ } export const DragControls: ForwardRefComponent = React.forwardRef< @@ -78,8 +79,13 @@ export const DragControls: ForwardRefComponent = onDragStart && onDragStart(initialModelPosition) invalidate() }, - onDrag: ({ xy: [dragX, dragY], intentional }) => { + onDrag: ({ xy: [dragX, dragY], intentional, event }) => { if (!intentional) return + + if(props.preventOverlap === true){ + event.stopPropagation(); + } + const normalizedMouseX = ((dragX - size.left) / size.width) * 2 - 1 const normalizedMouseY = -((dragY - size.top) / size.height) * 2 + 1