Skip to content

Commit

Permalink
fix(util/dragger): handle dragover events during capture phase
Browse files Browse the repository at this point in the history
We need to do this to make sure we track cursor movements before we reach other drag event handlers, e.g. in child containers.

Related to #289
Related to https://github.com/camunda/web-modeler/issues/5892#issuecomment-1733155870
  • Loading branch information
Niklas Kiefer committed Sep 26, 2023
1 parent ead4dcc commit 0694e2f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/components/util/dragger.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ export function createDragger(fn, dragPreview) {
// (2) setup drag listeners

// attach drag + cleanup event
document.addEventListener('dragover', onDrag);
// we need to do this to make sure we track cursor
// movements before we reach other drag event handlers,
// e.g. in child containers.
document.addEventListener('dragover', onDrag, true);
document.addEventListener('dragenter', preventDefault, true);

document.addEventListener('dragend', onEnd);
document.addEventListener('drop', preventDefault);
}
Expand All @@ -55,7 +60,9 @@ export function createDragger(fn, dragPreview) {
}

function onEnd() {
document.removeEventListener('dragover', onDrag);
document.removeEventListener('dragover', onDrag, true);
document.removeEventListener('dragenter', preventDefault, true);

document.removeEventListener('dragend', onEnd);
document.removeEventListener('drop', preventDefault);
}
Expand Down

0 comments on commit 0694e2f

Please sign in to comment.