React-dnd: Fix nested drag sources and how they work with canDrag

Created on 27 Feb 2015  ·  4Comments  ·  Source: react-dnd/react-dnd

This is related to #87 but more technical. Currently nested drag sources will activate together. This is a very, very wrong behavior. Child drag source should _always_ prevent parent from activating.

But it's not as simple as it seems with HTML5 backend.

I tried adding e.stopPropagation() into dragstart handler, but there's another issue. Suppose List and Card are both drag sources, Card is inside of List. Suppose Card has canDrag(): false. We can't call stopPropagation() in this case, because that would prevent the event from reaching the parent.

Okay, let's instead add if (DragOperationStore.isDragging()) return; to dragstart handler. But there's another problem: even though event now has reached the parent, if you actually drag, browser will use the original (child) target as drag preview.

This is probably solvable by explicitly using this.getDOMNode() as dragPreview if it's not specified in beginDrag, so that the drag preview is guaranteed to be the current target. I haven't tried it yet. Either way, this doesn't seem like a complex issue, and is up for grabs!

bug up for grabs

Most helpful comment

Is there a solution to stop calling parent when the canDrag function return false?

All 4 comments

Certainly we need some constraints on the dragPreview

Like what?

Fixed in 0.9.2.
Live demo: http://gaearon.github.io/react-dnd/#/nesting-sources

Is there a solution to stop calling parent when the canDrag function return false?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

djeremh picture djeremh  ·  3Comments

bebbi picture bebbi  ·  3Comments

TheBolliwood picture TheBolliwood  ·  3Comments

antoineBernard picture antoineBernard  ·  3Comments

BrennanRoberts picture BrennanRoberts  ·  3Comments