Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transformed SortableContext yields an offset drag overlay #464

Closed
ranbena opened this issue Sep 30, 2021 · 12 comments · Fixed by #518
Closed

Transformed SortableContext yields an offset drag overlay #464

ranbena opened this issue Sep 30, 2021 · 12 comments · Fixed by #518
Labels
bug Something isn't working sponsored This issue is a high-priority sponsored issue

Comments

@ranbena
Copy link
Contributor

ranbena commented Sep 30, 2021

When offsetting a SortableContext with css transform (for instance, when an open sidebar pushes it sideways), the drag overlay gets wrongly positioned.

Screen Shot 2021-09-30 at 9 31 28

Sandbox demo https://codesandbox.io/s/dnd-kit-offset-b2744

Originally posted by @ranbena in #205 (comment)

@ranbena
Copy link
Contributor Author

ranbena commented Sep 30, 2021

Here's a demonstration:

Screen.Recording.2021-04-30.at.18.40.50.mov

@ranbena
Copy link
Contributor Author

ranbena commented Sep 30, 2021

#379 allows consumers to configure how to measure the draggable node, so I gave it a shot:

const measuringConfig = {
  draggable: {
    measure: (element) => {
      return {
        ...getBoundingClientRect(element),
        left: getViewportLayoutRect(element).left
      };
    }
  }
};

The result is better - there is no offset during drag 🎉
BUT the drop animation sends the overlay to an offset position.
Sandbox code: https://codesandbox.io/s/dnd-kit-offset-with-measuringconfig-6ujp6?file=/src/App.js

Screen.Recording.2021-09-30.at.9.42.18.mov

@clauderic clauderic added bug Something isn't working sponsored This issue is a high-priority sponsored issue labels Sep 30, 2021
@tflanagan
Copy link

This specific example is showing an x translation, but any translation (x/y) causes this bug.

A y translation actually induces another bug with detecting where the element is in the list. It seems to push the item to the bottom of the list, regardless of where the overlay is positioned.

@headfire94
Copy link

@ranbena did you find a workaround for animation?

@ranbena
Copy link
Contributor Author

ranbena commented Oct 26, 2021

Nah, I'm avoiding the use of transform till it's fixed :/ (using a non-gpu property animation in the meantime)

@ranbena
Copy link
Contributor Author

ranbena commented Jan 9, 2022

@clauderic in my original post I provided a reproducible sandbox demo.
I now upgraded the dependencies in the demo to @next but the issue doesn't seem to be fixed - actually even more offset.
Am I missing something?


Current: https://b2744.csb.app/
Upgraded: https://fzcdy.csb.app/

@clauderic
Copy link
Owner

clauderic commented Jan 9, 2022

Hey @ranbena,

The problem with your sandbox is that you're also rendering the DragOverlay component in the same transformed container, so it too is offset by 135px when we measure it.

It's generally recommended that you try to render the DragOverlay in a portal higher up in the DOM tree (document body or root element).

Here's a forked sandbox where that is the only change I made, everything seems to be working: https://codesandbox.io/s/dnd-kit-offset-forked-hbtwb?file=/src/App.js

@ranbena
Copy link
Contributor Author

ranbena commented Jan 9, 2022

Understood. I'll try that 👍

@ranbena
Copy link
Contributor Author

ranbena commented Jan 10, 2022

Works! 🎉

@riledigital
Copy link

riledigital commented Jan 24, 2022

This was really helpful! I had the same exact problem that was caused by some combination of flexbox layout containers. I'll see if I have time to PR a note about this being a good use case for React Portal in the dndkit docs article for DragOverlay.

Edit: I found the documentation repo and see that a Portal example is in there!

@RahulRana0707
Copy link

@clauderic what if the same issue of @ranbena occurs inside a modal of mui. As I am implementing dnd-kit inside the modal.
If we createProtal the dragoverlay stays behind mui modal is their any solution for it?

@fmukaba
Copy link

fmukaba commented Sep 4, 2024

@RahulRana0707 Did you figure something out?
I am facing the same issue with using dnd kit in a React Modal - the overlay shows up behind the Modal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sponsored This issue is a high-priority sponsored issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants