Skip to content

Commit

Permalink
fix: don't miss canDrag check on nested dnd source
Browse files Browse the repository at this point in the history
  • Loading branch information
3cp committed Mar 20, 2020
1 parent bea1577 commit a58357f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
22 changes: 14 additions & 8 deletions src/dnd-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,6 @@ class DndService {
const dndSource = this._startingSource(element);
if (!dndSource) return;

if (typeof dndSource.delegate.dndCanDrag === 'function') {
if (!dndSource.delegate.dndCanDrag()) return;
}

this._grabbed = dndSource;
this._startListeningEventualMovements();

Expand Down Expand Up @@ -468,11 +464,21 @@ class DndService {
return;
}

let dndSource = this._sourceOf(element);
while (!dndSource && element) {
element = getParent(element); // drag target should be a top element
let dndSource;
while (element) {
if (!element) break;
dndSource = this._sourceOf(element);
const s = this._sourceOf(element);

if (s && (
typeof s.delegate.dndCanDrag !== 'function' ||
s.delegate.dndCanDrag()
)) {
dndSource = s;
break;
}

// Try next parent
element = getParent(element);
}

return dndSource;
Expand Down
1 change: 0 additions & 1 deletion test/dnd.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ test('add source', t => {
// source with border-box box-sizing
dndService.addSource({dndModel: model1, dndElement: box_border_box});


// source with customised dndCanDrag
dndService.addSource({
dndModel: model1,
Expand Down

0 comments on commit a58357f

Please sign in to comment.