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

support transformed draggables without portals #421

Closed
wants to merge 1 commit into from

Conversation

mattkrick
Copy link

@mattkrick mattkrick commented Apr 4, 2018

Per #192 it looks like portals are not the way to go.
I agree. I usually love portals, but when performance is critical, they aren't great.
I have a hard requirement on using a transform.
We could do this without extending the API, but that would be more expensive because we'd have to climb the DOM tree looking for a transform. In the spirit of performance-first, I opted to add a single extra provided function. For those that don't use transforms, no change is required. For those that do, they add a single argument to a div.

How it works:
react-beautiful-dnd uses position: fixed, which is great, except for 1 caveat. Per MDN docs:

When an ancestor has the transform, perspective, or filter property set to something other than none, that ancestor is used as the container instead of the viewport

If the developer provides a transformRef, then that tells the Draggable that an ancestor is being transformed, and therefore the left, top should be relative to the transformed node, not the viewport. It adjusts the left, top accordingly.

@alexreardon
Copy link
Collaborator

alexreardon commented Apr 5, 2018

Thank you for putting this forward! We will no longer require a wrapping element as part of our React 16 upgrade #406. I think it best to wait until that lands before solving that problem. However, using the techniques you put forward you could solve the issue today.

When snapshot.isDragging changes to true you could grab the left/top values from your parent using this.ref.parentElement.

It would be good to have another play with this after #406

@abcNocturn
Copy link

Would really like to see this realeased as soon as possible ...
Got a transformed Element Dialog from MaterialUI which is unusable with react-dnd ....

@alexreardon
Copy link
Collaborator

We are about to release 7.0 which changes things. Feel free to create another PR to readd this change to 7.0.

Perhaps a different way to go is to implement this as a (/docs/patterns). I suspect this can be implemented as a consuming rather than needing to add it to api.

Our current recommendation is to use React.Portal if you cannot get around having a parent with a clashing style.

I am closing this PR as it is not in the state that we want to support. As mentioned, feel free to raise another

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants