pragmatic-drag-and-drop icon indicating copy to clipboard operation
pragmatic-drag-and-drop copied to clipboard

Is there any way to know that the drag was cancel by pressing esc key?

Open niranjan821 opened this issue 11 months ago • 2 comments

We have a virtualized list where a dragged item can be removed from the list when moved due to virtualization. If the user drags the item, brings it back to its original position, and presses the Esc key to cancel the drag, the onDrop event doesn’t trigger until the mouse is released. Instead, the onDragLeave event fires, but this also happens when the item is dragged out of the drop target.

To work around this, I tried using keyboard events to detect the Esc key press. However, the issue is that onDragLeave gets triggered even before the onKeyUp event, and the onKeyDown event doesn’t trigger at all.

niranjan821 avatar Dec 17 '24 12:12 niranjan821

Hi, I also couldn't figure out a way to do this in #146. It looks like it is a limitation of the browser drag and drop API.

psychedelicious avatar Jan 15 '25 03:01 psychedelicious

@psychedelicious I found a workaround for my case. I stored the dragged item in a variable and attached a keyup listener to the wrapper element. When the Escape key is pressed and there is a dragged item in the variable, I assume that the drag is canceled.

niranjan821 avatar Jan 16 '25 05:01 niranjan821