zyzo / react-dnd-mouse-backend

Mouse Backend for react-dnd library
http://zyzo.github.io/react-dnd-mouse-backend/
MIT License
85 stars 30 forks source link

Escape key to cancel drag? #28

Open srgreen00 opened 5 years ago

srgreen00 commented 5 years ago

Is it possible to cause the drag the cancel by hitting the escape key? While the HTML 5 backend will cancel the drag on escape, the mouse back end drag is not effected.

Though I donʻt see how that where that might have been implemented explicitly on HTML5, I was looking at the TouchBackend. It has a enableKeyboardEvents property.

When set, it adds a keyboard listener that calls the following on escape.

handleCancelOnEscape (e) {
    if (e.key === 'Escape' && this.monitor.isDragging()){
        this._mouseClientOffset = {};

        this.uninstallSourceNodeRemovalObserver();
        this.actions.endDrag();
    }
}

Would something like this be needed to handle escape in the mouse back end?

Thanks.