0

Below is the canDrag method of my drag source spec:

const itemDragSource = {
    canDrag(props, monitor) {
        if(props.canDrag && !props.canDrag(props.itemData)) {
            if(props.dragUndraggable){
                debugger;
                props.dragUndraggable(props.itemData, monitor.getInitialClientOffset());
            }
            return false;
        }
        return true;
    }
}

The problem is that monitor.getInitialClientOffset returns null, so does getInitialSourceClientOffset and getClientOffset? Any ideas on how to get mouse position at this point?

cclusetti
  • 343
  • 1
  • 2
  • 11

1 Answers1

0

Those two functions (and all of the get position functions) return null inside of canDrag because at that point nothing is being dragged (per: http://gaearon.github.io/react-dnd/docs-drag-source-monitor.html). So if you can't put that logic elsewhere (such as within isDragging or endDrag) you'll need to implement some external scheme to keep track of the mouse position, perhaps something like what was suggested here: Javascript - Track mouse position

Community
  • 1
  • 1
Ben Hare
  • 4,365
  • 5
  • 27
  • 44