-
Notifications
You must be signed in to change notification settings - Fork 2k
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 dragging multiple elements #14
Comments
Not a priority. We can revisit after introducing drag source keys (#38 (comment)). |
I'll be interested in this down the road, although I think you might be able to just wrap a section of your component tree with a component that has a dragSource... |
Kinda. First we learn to pass null Then we add What's fun is that we can draw |
Thats a way less ugly idea than what I had in mind |
👍 for this feature :-) |
Update README to include css in getting started
Closing, as I don't currently have a use case for this, and it's a significant implementation effort. |
I used Java/Swing DnD back in the day, and they had probably an army of developers who grappled with this problem and came up with a pretty refined, extremely generic and flexible framework. I would recommend researching old desktop frameworks as they probably solved all the difficult challenges with making a good DnD framework like this. The way to do this in Java/Swing (although it had no built-in support for drag images) was to make the tree view itself the drag source, and make it able to decide whether or not a drag should be initiated based on its current state and the drag start position. Is I'd predict that treating all the items in the list as individual draggables will just be difficult compared to having the list component be the single drag source that figures out what kind of drop payload / preview image to construct based upon what's selected in it. Consider also that a developer might want to change the order of the items being dragged based upon which item the user clicked and dragged from. I believe Windows Explorer behaves this way. |
Has anyone implemented dragging multiple items with react-dnd in their applications? What's your current solution for this? |
did you mean multiple drop target for single drag source? |
+1 @danii1 : Has anyone implemented dragging multiple items ? |
I implemented it, solution is basically what is described in the first post:
|
I implemented it by:
|
I have a slightly different use case for this I think, I want to draw nodes that are draggable with edges that aren't draggable but do move when nodes they're attached to move. My current implementation is a |
@danii1 |
I will write a post and add repo about multiple and nested drag and drop with react-dnd + redux. |
@nayemmajhar, it would be great |
@nayemmajhar any update on an example with this? |
I have developed this application using react DnD with reduxJS long ago https://www.joomshaper.com/page-builder I am writing a tutorial but need time publish |
@serle Would you be able to share a code example of how you did this? |
@ianmclean2011 check it out here: #590 |
I'm trying to implement multi-drag in an example similar to the sortable example here: https://react-dnd.github.io/react-dnd/examples-sortable-simple.html. I want to be able to select any objects, and then move them as a unit up and down the list. I'm having trouble wrapping my head around how to use the examples/info shared above to do this. Any thoughts/ideas/feedback on how this might work? |
If anyone's interested, I implemented a multiple drag / grid view: https://codesandbox.io/s/9j897k0mwy. This is still a demo, but I might abstract the code a little bit more and package it in a component later. |
@melvynhills Have you investigated a solution that doesn't require passing all the selected cards to each Card component? I don't think there is a solution considering the Card's beginDrag() needs a reference to all selected Cards. |
@jmcrthrs No, it doesn't seem possible to me with react-dnd API. I don't think there's a way to know before dragging which specific item is going to be dragged. That's also the only way to know whether the dragged item is within the multiple selection you made, or if it's outside of that selection that we then need to replace. |
@melvynhills @jmcrthrs other desktop dnd frameworks I've used rely on making lists and tables the drag sources/drop targets instead of making each individual row, cell, item etc. its own drag source and/or drop target. The implementation for dragging multiple items, as well as getting the specific drop location within the list or table, comes out a lot cleaner that way. When a list receives a drag start event it can simply look at its current selected items. |
@jedwards1211 do you think it's doable with this library? Especially the use-case of starting dragging an item that wasn't selected before the drag start. I'm not sure it's the way react-dnd is supposed to work. |
Does anybody solved case in which there are multiple drop targets? EDIT: Created separate issue for this one #1650 |
@melvynhills probably if a |
This is an example of why I would recommend making the container component the drag source instead of the individual items. I haven't needed to implement multiselect with React DnD but maybe sometime I can make a sandbox to convince folks it's the more maintainable approach |
Has anyone implemented dragging multiple items with react-beautiful-dnd in their applications? What's your current solution for this? |
@abhidnyag Here is my current solution with You can try the live demo here. |
Feature request : Hover on target image makes copy of selected images which is given in below image |
There is a common pattern that is hard to implement with native drag and drop: dragging multiple elements. While selection mechanics might vary from app to app (cmd+clicking, checkboxes, predefined groups), but it would be nice to at least make it possible to support this scenario.
Because multiple dragged items may not be siblings in DOM and
setDragImage(element, x, y)
is pretty much insane and hasn't gotten any better, we won't burden ourselves with trying to render several elements in drag preview at once.How can we help implement this scenario, if we can't show a "multiple" drag preview?
In a way, this scenario is already possible: consumers can manually keep track of selected elements, set
dragPreview
to some kind of generic placeholderImage
and react appropriately to the dropping of (as far as business logic is concerned) several elements.However there is currently no supported way for one element to know that it's part of a group that's being dragged. From react-dnd's point of view, if we drag something, this component gets
getDragState(type).isDragging = true
, but other components don't. From your app point of view, if you support multiple selection, you want all logically "selected" items to be aware that they're being dragged, even if only one of them is being actually "DOM-dragged".What we need is a way for components to tell react-dnd that, “hey, although
onDragStart
was received by another component, I want to pretend that I'm being dragged too, and have mygetDragState(type)
mirror dragged component'sgetDragState(type)
, and have myendDrag(didDrop)
called too so I could do my stuff”.How would components opt into that?
The text was updated successfully, but these errors were encountered: