Skip to content

Commit

Permalink
Fix nested drag sources
Browse files Browse the repository at this point in the history
1. Only preventDefault() if *no* drag sources in the nesting chain handled drag start
2. When a nested drag sources begins drag, don't let its parents handle it too
  • Loading branch information
gaearon committed Mar 1, 2015
1 parent 8dc0d73 commit 43a9802
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 9 additions & 0 deletions modules/backends/HTML5.js
Expand Up @@ -59,6 +59,13 @@ function preventDefaultNativeDropAction(e) {
}
}

function handleTopDragStart(e) {
// If by this time no drag source reacted, tell browser not to drag.
if (!DragOperationStore.isDragging()) {
e.preventDefault();
}
}

function handleTopDragEnter(e) {
// IE requires this to not show a nodrag icon over the container
e.preventDefault();
Expand Down Expand Up @@ -118,6 +125,7 @@ var HTML5 = {
return;
}

window.addEventListener('dragstart', handleTopDragStart);
window.addEventListener('dragenter', handleTopDragEnter);
window.addEventListener('dragover', handleTopDragOver);
window.addEventListener('dragleave', handleTopDragLeave);
Expand All @@ -129,6 +137,7 @@ var HTML5 = {
return;
}

window.removeEventListener('dragstart', handleTopDragStart);
window.removeEventListener('dragenter', handleTopDragEnter);
window.removeEventListener('dragover', handleTopDragOver);
window.removeEventListener('dragleave', handleTopDragLeave);
Expand Down
8 changes: 5 additions & 3 deletions modules/utils/createDragDropMixin.js
Expand Up @@ -199,9 +199,7 @@ function createDragDropMixin(backend) {

handleDragStart(type, e) {
var { canDrag, beginDrag } = this._dragSources[type];

if (!canDrag(this)) {
e.preventDefault();
if (DragOperationStore.isDragging() || !canDrag(this)) {
return;
}

Expand All @@ -216,6 +214,10 @@ function createDragDropMixin(backend) {
y: offsetFromClient.y - containerRect.top
};

if (!dragPreview) {
dragPreview = containerNode;
}

if (!effectsAllowed) {
// Move is a sensible default drag effect.
// Browser shows a drag preview anyway so we usually don't want "+" icon.
Expand Down

0 comments on commit 43a9802

Please sign in to comment.