Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jamesalexmorgan opened this issue Nov 7, 2018 · 3 comments

Comments

@jamesalexmorgan
Copy link

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...
#9
#167

Thanks awesome DND team!!

@webmastervishal
Copy link

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.

@markusv
Copy link

markusv commented Mar 11, 2019

Hi,

I also need this. This #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

@alexreardon
Copy link
Collaborator

Let's track this here: #1239

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants