Draggable: Mirror object is in incorrect position when dragging inside a modal or similar

Created on 25 Feb 2018  路  4Comments  路  Source: Shopify/draggable

When dragging a draggable item inside a modal (or, I'd imagine, anything else which is similarly offset from the rest of the content), the mirrored item has the wrong coordinates and doesn't compensate for this.

This codepen demonstrates this inside a Materialize modal.

  • Library version: 1.0.0-beta.4
  • Browsers: all
  • Tech stack: jQuery (3.3.1) is the most complex thing in the example, other than that nothing but draggable and Materialize are included
question

Most helpful comment

Maybe we can make the appendTo option clearer by moving it inside the mirror options namespace, e.g.

new Sortable(containers, {
  mirror: {
    appendTo: 'body',
  },
  ...remainingOptions
});

All 4 comments

Hey!

I made 2 tiny tweaks to your Codepen: https://codepen.io/beefchimi/pen/PQxPNv?editors=0100

  1. I added a really high z-index for the draggable-mirror in the CSS - this allows it to be above your modal.
  2. I used appendTo on the 2nd instance of Draggable to put the mirror on the body instead of within the modal. You could append this anywhere outside of the modal if you wanted.

The offending code that caused the problem was the transform: scaleX(1) scaleY(1) on the modal. Not sure why this style is needed... nor do I fully understand why its affecting the positioning of the mirror. I've never actually used Materialize myself - but thats where the issue is.

Thanks for bringing this up! Personally I don't believe this is an issue with Draggable. Its just a matter of adjusting the styling based on the consumers specific use case. Closing this issue, but feel free to re-open and reply.

Thanks a ton for the help, I wouldn't have thought to do that. It seems I misunderstood appendTo as what where the dragged element would go upon placement.
Thanks!

Maybe we can make the appendTo option clearer by moving it inside the mirror options namespace, e.g.

new Sortable(containers, {
  mirror: {
    appendTo: 'body',
  },
  ...remainingOptions
});

@tsov yea thats a pretty good point actually... we can chat a bit about this in person but perhaps we put this on the roadmap for beta5

Was this page helpful?
0 / 5 - 0 ratings

Related issues

noloop picture noloop  路  5Comments

asmith26 picture asmith26  路  3Comments

pumpknhd picture pumpknhd  路  4Comments

shuaiyaotian picture shuaiyaotian  路  3Comments

AStoker picture AStoker  路  3Comments