Skip to content

Implemented dragging prop in SortableElement #147

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Robinfr
Copy link

@Robinfr Robinfr commented Feb 14, 2017

I've updated SortableElement to inject the isDragging prop into the WrappedComponent. I've also changed the SortableContainer to allow the SortableElement to re-render before making a clone by making a clone after the state change has been performed.

I've updated SortableElement to inject the `isDragging` prop into the WrappedComponent. I've also changed the SortableContainer to allow the SortableElement to re-render before making a clone by making a clone after the state change has been performed.
@clauderic
Copy link
Owner

clauderic commented Feb 14, 2017

Hmm, hadn't considered that approach. Have you tested alongside the collection prop?

I actually wonder if we couldn't try using ReactDOM.unstable_renderSubtreeIntoContainer instead of having to call setState and then having to clone the node, which still feels a little hacky

@Robinfr
Copy link
Author

Robinfr commented Feb 14, 2017

@clauderic no I haven't tried that yet. I'll do that tomorrow.

The callback of setState is meant for this kind of stuff so even though I understand it feels a bit hacky, I think it's perfectly fine. Using something that has the word unstable in it on the other hand feels a bit dangerous..

@clauderic
Copy link
Owner

clauderic commented Feb 14, 2017

Hmm. It's unstable in the sense that the API may change in future releases, but it is still the preferred way of rendering a component subtree into a different container.

@Robinfr
Copy link
Author

Robinfr commented Feb 15, 2017

Do you want me to try to implement the renderSubtreeIntoContainer in a different branch or you want to see if it can be included with this?

Edit: I took a look at how the implementation works from within React. You could probably use the renderSubtreeIntoContainer to render the dragging node. The issue is that you also might want to inject the isDragging prop into the original element, e.g. to hide something in the original element so the height matches. The props should always be the same for both the original WrappedInstance and the node you are dragging, otherwise the layouts may not match causing weird issues where what you are dragging is a different size than the original component.

So I don't mind using the renderSubtreeIntoContainer but I don't think you can get around the fact that you have to set the state, and then render in the callback..

`isDragging` prop now also takes into account the `collection` prop.
@Robinfr
Copy link
Author

Robinfr commented Feb 15, 2017

I've updated the PR to also take into account the collection prop.

@Robinfr
Copy link
Author

Robinfr commented Mar 27, 2017

Resolved conflicts.

@Robinfr
Copy link
Author

Robinfr commented Apr 13, 2017

@clauderic do you have any intention to merge this? Otherwise I will close this..

@tizzle
Copy link

tizzle commented May 27, 2017

Hey @clauderic,

any news on this?

@Ricardo-Marques
Copy link
Contributor

+1 on this. I have also wanted to keep track of whether an element was being dragged and soon discovered that the element is cloned before it re renders. This feels like an elegant solution.

@minikomi
Copy link

Can this PR get another look? It seems useful for large components.

@alidavut
Copy link

Changing some styles by dragging would be very helpful. Can you update the PR?

@Chaoste
Copy link

Chaoste commented Jan 6, 2022

@clauderic Hey, is there any chance that this can be merged soon? We would like to give focus-like styles to the dragged component which appears to be impossible at the moment.

Edit 1:
At everyone else, I was able to solve it for now with some ugly global styles. In my case, the dragged element is a li element. So I added a rule like this: body > li { boxShadow: 0px 0px 0px 3px gray }
Edit 2:
Okay, you can just use helperClass to achieve this.

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

Successfully merging this pull request may close these issues.

8 participants