Open psychedelicious opened 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.
Thanks @yangannyx.
I did some experimentation and reading:
keydown
.keydown
.
Other inputs are ignored. Unfortunately, this means you cannot even listen for the esc
keydown.dragend
event only fires after the animation finishes (tested on FF and Chrome) - not on the esc
keydown.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.
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?
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
.
onDropTargetChange
andonDrop
events fire after the cancel animation finishes. Is it possible to detect cancelation before the animation finishes?Thanks.