dnd-kit icon indicating copy to clipboard operation
dnd-kit copied to clipboard

Scale transform and dragging issue

Open nate-kelley-buster opened this issue 1 year ago • 4 comments

I am running into an issue where the parent div has a css transform (scale) which is causing the drag functionality to behave strangely. Is there a possible workaround to this issue?

Here is an example of what I am talking about https://codesandbox.io/s/draggable-tabs-antd-5-8-5-forked-nxl43c?file=/demo.tsx

nate-kelley-buster avatar Aug 31 '23 19:08 nate-kelley-buster

I met the same issue. It seems that dnd-kit cached the origin bounding client size.

infinite2009 avatar Oct 27 '23 06:10 infinite2009

I met the same issue as well. And found that @efossvold's idea helps a lot: https://github.com/clauderic/dnd-kit/issues/638#issuecomment-1096672529

    const style: React.CSSProperties = {
        transform: `translate3d(${transform.x / scale}px, ${transform.y / scale}px, 0)`,
        // Rest of your styles ...
    };

Apply it on to your dragging elements so it will compensate the scale drifting.

k-jiang avatar Jan 19 '24 03:01 k-jiang

thanks, @k-jiang for the updates! it has saved a lot of time for others!

abhishekchotaliya avatar Feb 10 '24 10:02 abhishekchotaliya

I am also having this issue and have found partial success with using a scale parameter to fix the dragging position, however it seems dndkit is internally using the original transform to determine the isOver value.

ezgif-7-b3fcecf022

Possibly this could be solved with custom collision detection? Though I haven't looked into it yet, otherwise I would think dndkit needs to be able to take in some prop indicating the zoom/scale so it can compensate to return the right transform & isOver values automatically.

ssalka avatar Jul 12 '24 05:07 ssalka