How to Prevent Canvas Dragging While Dragging a Node in React Flow #4899
-
Hi, I want to prevent the React Flow canvas from moving or being draggable when the user starts dragging a specific icon (image shown in the discussion). However, when I tried using <Button
type="text"
size="small"
title="Drag Node"
draggable
onDragStart={(event) => {
event.stopPropagation()
setNodeDragging(true);
event.dataTransfer.setData("nodeType", JSON.stringify({ id }));
event.dataTransfer.effectAllowed = "move";
}}
onDragEnd={(event) => {
setNodeDragging(false);
}}
icon={<FontAwesomeIcon icon={faExpand} color="#ffffff70" />}
/> <ReactFlow
defaultEdgeOptions={{
animated: true
}}
className="dark:text-white cursor-grab"
nodes={nodes}
edges={edges}
nodesDraggable={false}
nodesConnectable={false}
nodeTypes={nodeTypes}
edgeTypes={edgeTypes}
zoomOnScroll={true}
zoomOnPinch={true}
panOnDrag={nodeDragging}
nodeDragThreshold={0}
onNodeDrag={onNodeDrag}
onEdgeClick={onEdgeClick}
onConnect={onConnect}
onInit={(instance) => {
instance.zoomTo(1);
}}
onDragOver={onDragOver}
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
deleteKeyCode={null}
fitView={true}
>
<Background
className="bg-neutral-100 dark:bg-neutral-800"
variant="dots"
/>
</ReactFlow> The issue is that the state ( Is there any way to achieve the expected behavior where the canvas does not move when dragging the icon? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
add the |
Beta Was this translation helpful? Give feedback.
Oh my bad, in your case you want to use
nopan
instead ofnodrag
^^