Comments (6)
@clauderic can you provide an example with the support of dragging an element from one container to another one + dragging a container from one to another?
There are a lot of dnd libraries but none of them supports it. It's required to implement a complex tree structure with folders and files (and other ones) where you can drag folders and drag files.
from dnd-kit.
@mxck the library supports this, as mentioned above, I don't have time to fully update the onDragOver and onDragEnd logic at the moment, but I left some comments of what would need to be implemented from a consumer perspective to make it work:
https://codesandbox.io/s/react-nested-dnd-kit-forked-m1lkg?file=/src/App.js
from dnd-kit.
I don't have time to fully update the onDragOver
and onDragEnd
logic at the moment, but I left some comments of what would need to be implemented:
https://codesandbox.io/s/react-nested-dnd-kit-forked-m1lkg?file=/src/App.js
The main issue with your example was that you need to use a DragOverlay
because the draggable element will potentially be re-parented in onDragOver
if the depth changes mid-drag, causing it to unmount and re-mount. See https://docs.dndkit.com/api-documentation/draggable/drag-overlay#when-should-i-use-a-drag-overlay
The second issue is that you need to make sure you have a separation between presentational components and draggable/droppable/sortable components so that you can render the presentational ones within DragOverlay
, rather than rendering draggable/sortable components within the DragOverlay
, which is not supported. See the recommended patterns outlined here: https://docs.dndkit.com/api-documentation/draggable/drag-overlay#presentational-components
from dnd-kit.
Apologize for reviving a closed issue, but wanted to share my attempt at accomplishing this since I struggled to find an exact example. Here's a GIF of a rows, columns and item demo I made that I think accomplishes the nested scenario that @fedotxxl mentions above. Put some locks in place to try and make the UI behave - only columns can be added to rows.
Here's the code - https://codesandbox.io/s/dnd-kit-nested-containers-kvdgn?file=/src/app.js (inspired by some of the code from this repo's stories).
It's a little rough to say the least and could be much better, but I feel like I've gotten a hang on the library so going to move on to implementing what I need in my actual codebase.
from dnd-kit.
Closing this issue as it is more of a help request than an issue. Feel free to reopen if you run into bugs.
from dnd-kit.
@clauderic in your corrected example, it is still not possible to move the entities through the tree.
Does the library support that? In the storybook examples only have moving between containers, but no nested containers.
from dnd-kit.
Related Issues (20)
- AutoScroll absolute thresholds and acceleration
- Drag Handle stops working when its visibility is toggled (hidden then shown) HOT 2
- Multiple containers : possibility of hitting minified error due to too many re-renders
- How do I get access to the Draggable data once it is over a Droppable? HOT 1
- Automatically generate id for components
- Sorting doesn't stay at it's position or moves somewhere else HOT 1
- Cannot auto-scroll back to first vertical list when used in a horizontally scrollable parent
- pnpm add @dnd-kit/sortable
- Click-and-drop?
- DND Kit / React Virtual Re-renders more with DndContent HOT 3
- @dnd-kit/react (beta). Wrong nested scrollable elements activating HOT 8
- [next] Feature Request: Apply different `activationConstraints` based on `pointerType` HOT 1
- Dragging object does not trigger scrolling in target scroll container (despite use of DragOverlay) HOT 3
- [next] controlled or cancellable useSortable HOT 5
- Nextjs with @dnd-kit/react HOT 4
- Trouble with nested droppables HOT 1
- Add `over` property to the DropAnimationFunctionArguments
- Trouble with " select "
- Code Sandbox for Experimental Docs HOT 3
- Trouble installing `@dnd-kit/react` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dnd-kit.