Interact.js: Can't prevent click event after div dragEnd

Created on 22 Jun 2015  路  5Comments  路  Source: taye/interact.js

I use Interact with angular and have ng-click handler on element. Click has called after my dragend event. How I can prevent that? Where I can add

.on('dragend', function (event) { 
  event.interactable.preventDefault(true); // doesn't work
  event.interactable.options.preventDefault = true ; // doesn't work
  event.preventDefault() ; // doesn't work

or smth else?

Most helpful comment

I would think that this is really more of an Angular issue since interact.js' tap event exists to bypass click problems.

There's no default action from InteractEvents so their preventDefault method does nothing. Also, calling preventDefault on mousedown or mouseup events doesn't stop clicks from happening.
If you want to stop the click event then you should add a click event listener with useCapture that just calls event.stopImmediatePropagation().

interact(target).on('click', function (event) {
  event.stopImmediatePropagation();
}, true /* useCapture */);

All 5 comments

I would think that this is really more of an Angular issue since interact.js' tap event exists to bypass click problems.

There's no default action from InteractEvents so their preventDefault method does nothing. Also, calling preventDefault on mousedown or mouseup events doesn't stop clicks from happening.
If you want to stop the click event then you should add a click event listener with useCapture that just calls event.stopImmediatePropagation().

interact(target).on('click', function (event) {
  event.stopImmediatePropagation();
}, true /* useCapture */);

It's works! You save my day, thanks!

.on('dragend', function (event) {
  interact(event.target).on('click', function (_event) {
    _event.stopImmediatePropagation();
  }, true /* useCapture */);
});

It's a bad idea to do that on every dragend event. You only need to add the click event listener once.

@taye I get Uncaught TypeError: Illegal invocation for stopImmediatePropogation() can you assist?

@zeeshanjan82 sorry for the late reply. If you didn't sort it out already, a stack trace would be helpful.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

z-eleven picture z-eleven  路  9Comments

sualko picture sualko  路  9Comments

itmaor picture itmaor  路  4Comments

freefalling picture freefalling  路  3Comments

jbaartman picture jbaartman  路  4Comments