onNodeDragStart without onNodeDragStop
See original GitHub issueHi,
I have encountered a situation where onNodeDragStop is not getting called after onNodeDragStart is called when the user did not move the node out of position before releasing the mouse left button.  I believe it’s due to the following logic:
Is it possible to update the logic as follows to ensure onNodeDragStop is not omitted:
 const onDragStop = useCallback( 
   (event: DraggableEvent) => { 
     // onDragStop also gets called when user just clicks on a node. 
     // Because of that we set dragging to true inside the onDrag handler and handle the click here 
     if (!isDragging) { 
       if (isSelectable && !selectNodesOnDrag && !selected) { 
         addSelectedElements(node); 
       } 
  
       onClick?.(event as MouseEvent, node); 
     } else {
       updateNodePosDiff({ 
         id: node.id, 
         isDragging: false, 
       });
    } 
     onNodeDragStop?.(event as MouseEvent, node); 
   }, 
   [node, isSelectable, selectNodesOnDrag, onClick, onNodeDragStop, isDragging, selected] 
 ); 
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
 Top Results From Across the Web
Top Results From Across the Web
Interaction Props Example - React Flow
This example shows the different props like nodesDraggable, zoomOnScroll or panOnDrag that control the interactivity of a diagram.
Read more >copy the node while drag and drop using react-flow-renderer
You can solve this by changing your onNodeDragStop handler to something like this: onNodeDragStop = (evt: MouseEvent, node: Node) => { if ...
Read more >Class TreeViewEvents<TValue>
OnNodeDragStop. Triggers when the TreeView node dragging (move) stops. Declaration. public EventCallback<DragAndDropEventArgs> ...
Read more >This version has been deprecated - react-flow-renderer - npm
... onNodeDragStart(event: MouseEvent, node: Node) : node drag start; onNodeDragStop(event: MouseEvent, node: Node) : node drag stop ...
Read more >Ogma - Linkurious documentation
If no renderer is available (e.g in Node.js), Ogma will fallback on ... onNodeDragStart(function (evt) { console.log('User dragged nodes ' + evt.nodes.
Read more > Top Related Medium Post
Top Related Medium Post
No results found
 Top Related StackOverflow Question
Top Related StackOverflow Question
No results found
 Troubleshoot Live Code
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free Top Related Reddit Thread
Top Related Reddit Thread
No results found
 Top Related Hackernoon Post
Top Related Hackernoon Post
No results found
 Top Related Tweet
Top Related Tweet
No results found
 Top Related Dev.to Post
Top Related Dev.to Post
No results found
 Top Related Hashnode Post
Top Related Hashnode Post
No results found

Hi @moklick,
I understand the reasoning. Unfortunately, drag and click both start with
mousedownevent and if I recall correctly, since the Node is wrapped within areact-draggablecomponent, themousedownwill triggeronNodeDragStartevent and onmouseupevent if no “dragging” occurred, then the existing code will trigger theonClickwhich will in-term triggeronElementClickevent and skiponNodeDragStopevent. In other words, with the following simple example:When the user clicks (
mousedownand without moving the mousemouseup) on an element, the console will log:Which will result in
onNodeDragStartevent firing without correspondingonNodeDragStopevent. In most cases when there is a handler foronNodeDragStartevent it is likely to find a handler foronNodeDragStopevent; while it is feasible to implement a handler foronElementClickto negate/close out the effect ofonNodeDragStart, it makes the code less intuitive and harder to maintain as it will force the developer to “handle” parts ofonNodeDragStoplogic inonElementClickhandler. Ideally, theonDragStartevent should fire when the node’s position changed for the 1st time in order to clearly differentiate drag from click; however, I am not sure that’s howreact-draggableis implemented.Wow, dealing with same exact issue and love @datoslabs answer