The key bit that’s missing is the check whether the default behaviour of an event has been prevented. That is, there’s a matching sibling to d3.event.preventDefault()
— d3.event.defaultPrevented
. You need to check this in your click
handler to see whether any dragging action is going on.
See also the answer to this question.