javascriptdragula

Dragula not working on touch devices


I'm probably missing something obvious but I can't get Dragula to work on any iOS browser. I'm not doing anything special and the docs and issues on Github don't seem to offer any insight for debugging.

I've got the following line of code in a componentDidMount function:

dragula([document.querySelector('#left'), document.querySelector('#right')])

Nothing special about those elements, just 2 <ul>s.

I've added a viewport rule to my HTML:

<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">

I've even tried adding some touch rules to the CSS for the html elements that should be draggable (so text selection is disabled):

-webkit-touch-callout: none;
      -webkit-user-select: none;
       -khtml-user-select: none;
         -moz-user-select: none;
          -ms-user-select: none;
              user-select: none;

I've managed to replicate the issue on mac's iOS simulator. When I try to drag, it scrolls the page around instead of activating the dnd function.

Note that everything works fine on desktop.

What do?


Solution

  • Hmmm... looks like preventing the window from scrolling around fixes the trick. If you don't care about having functions attached to touchmove then this fixes the issue:

    window.addEventListener('touchmove', function() {})