atlassian / pragmatic-drag-and-drop

Fast drag and drop for any experience on any tech stack
https://atlassian.design/components/pragmatic-drag-and-drop
Other
9.77k stars 223 forks source link

Opt out of the browser's native cancel animation #146

Open psychedelicious opened 3 weeks ago

psychedelicious commented 3 weeks ago

Thanks.

yangannyx commented 3 weeks ago

It doesn't seem like there's a way to opt out of the animation in the HTML Drag and Drop specification

The drag was canceled. If the platform conventions dictate that this be represented to the user (e.g. by animating the dragged selection going back to the source of the drag-and-drop operation), then do so.

psychedelicious commented 3 weeks ago

Thanks @yangannyx.

I did some experimentation and reading:

There's some inconsistency, where a no-op drop (e.g. a drop on something without a handler for the event) immediately hides the drag preview, but a canceled drag does the animation.

What I wanted to do was get the same behaviour as a no-op drop, when canceling a drop. In the application, I wanted to revert my "potential" drop targets' styling immediately, instead of waiting for the animation to finish. But because we cannot detect the drop cancelation, it's not possible. No biggie.

Maybe I've missed something here - I'll leave this open in case any others with more experience with the native dnd APIs know of a workaround.

psychedelicious commented 3 weeks ago

I noticed this in the docs for preventUnhandled:

Your are disabling a native drag preview and you want to prevent the default "cancel" animation on a cancelled drag

So maybe there is a way to opt out of the cancel animation, or detect cancellation as soon as the user cancels?

declan-warn commented 2 days ago

Hey @psychedelicious the preventUnhandled utility will ensure that every drop on the page is handled, even if you drop outside of a drop target. I think this is what you mean by a 'no-op drop'.

Unfortunately, as far as I know the animation cannot be avoided when a user presses esc.