react-beautiful-dnd icon indicating copy to clipboard operation
react-beautiful-dnd copied to clipboard

New hook for cancelling a drag (animates back to original position, similar to escape key behaviour)

Open jamesalexmorgan opened this issue 8 years ago • 3 comments

Btw, Thanks so much for this library awesome Atlassian team!!! It's an absolute joy to work with!

The animation behaviour that the escape key triggers is perfect for me! I need to trigger that awesome animation, reverting their drag depending where they've tried to drop. If they dropped the item in an incorrect place in my list, it would be an awesome user experience for it to animate back to it's original position. Instead of right now where it clicks back to its original place instantly.

What could be awesome is a new hook, maybe called onCheckCancel or onCheckValidDrag or onBeforeDragEnd which could...

  • run just before drag end, (maybe immediately on mouse up, so you can check before you start animating)
  • expect a return value of true or false
  • If the function returns false, that would tell the DragDropContext to cancel and fire the cool escape key reverting behaviour

This would let users write their own custom cancel logic! Yay! 🎉

<DragDropContext
  ....
  onCheckCancel={({ source, destination }) => {
    const isValidDrag = checkIfValidDrag({ source, destination });
    return isValidDrag; // returns true or false
  }}
>
...

Any thoughts?

Related issues... https://github.com/atlassian/react-beautiful-dnd/issues/9 https://github.com/atlassian/react-beautiful-dnd/issues/167

Thanks awesome DND team!!

jamesalexmorgan avatar Nov 07 '18 23:11 jamesalexmorgan

Hey, Any updates on this new idea, even I need this functionality in my code. If the user switches on the toggle button then drag should be enabled and if the user switches it off then drag should be disabled.

vishalshettydev avatar Mar 06 '19 07:03 vishalshettydev

Hi,

I also need this. This https://github.com/atlassian/react-beautiful-dnd/issues/9 does not seem to work when triggered in onDragEnd. However I need to be able to decide if the move should be allowed based on what droppable the draggable is dropped on

markusv avatar Mar 11 '19 13:03 markusv

Let's track this here: #1239

alexreardon avatar Jul 22 '19 05:07 alexreardon