Skip to content

Commit

Permalink
Fix drop issue (facebookarchive#1725)
Browse files Browse the repository at this point in the history
Summary:
**Summary**

I have created a demo to illustrate this issue, feel free to look at [here](https://github.com/laysent/draft-js-drag-and-drop-issue)

If you look at `src/component/base/DraftEditor.react.js`, there is a problem with `_dragCount`:

When you drag a file into editor and drop it, `onDragEnter` will be triggered to increase `this._dragCount`. However, `onDragLeave` will not be triggered when dropping, thus `this._dragCount` will not be decreased back to 0.

Thus, after dragging and dropping, when user drags another file and NOT drop it, both `onDragEnter` and `onDragLeave` will be triggered. This time, `this._dragCount` will be increased then decreased. However, since it's initial value after dropping is not 0, it will not be decreased back to 0 after `dragLeave`, thus it will not trigger `this.exitCurrentMode()` in `onDragLeave`. Editor remains in "drag" mode.

To resolve this issue, simply set `_dragCount` back to 0 when dropping the file.

**Test Plan**

I don't think one is necessary for this issue. But would be happy to provide one if required.
Pull Request resolved: facebookarchive#1725

Differential Revision: D10234644

fbshipit-source-id: 6b8ffeef21899d80f623db3554dd688038ed92ac
  • Loading branch information
laysent authored and jdecked committed Oct 8, 2019
1 parent a15ae5b commit 307a5f7
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/component/handlers/drag/DraftEditorDragHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const DraftEditorDragHandler = {
);

e.preventDefault();
editor._dragCount = 0;
editor.exitCurrentMode();

if (dropSelection == null) {
Expand Down

0 comments on commit 307a5f7

Please sign in to comment.