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

Is there a way to select multiple RnD div's together and drag them? #911

Open
tulasinandan654 opened this issue Aug 16, 2023 · 1 comment

Comments

@tulasinandan654
Copy link

I have a parent RnD with child RnD div's in it. When a parent is moved, the child's in it should be moved together relative to parent.

@aleciavogel
Copy link

aleciavogel commented Mar 21, 2024

Here's a working example I put together (everything you need is in src/App.tsx): CodeSandbox Link

Screen.Recording.2024-03-21.at.1.57.28.PM.mov

To summarize my solution:

  • Use setState to track an array of selectedIds
  • When you drag an item, subtract its current position from the new position being passed into your onDrag handler. This will be our delta that we can use to calculate the new positions of all the other selected items.
  • Iterate through all items that need to be moved (either just the current item, or all items that have an id in selectedIds), adding the delta.x and delta.y to each item's position.x and position.y respectively.

You may need to create a context that tracks the selectedIds and handles the drag events, depending on how complicated your nesting structure is (ie, detecting if all selected ids are for items in the same row/layer). In my example, I just have one giant container component that handles everything, so YMMV.

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

No branches or pull requests

2 participants