GithubHelp home page GithubHelp logo

Nested sortable about dnd-kit HOT 6 CLOSED

clauderic avatar clauderic commented on July 26, 2024 3
Nested sortable

from dnd-kit.

Comments (6)

fedotxxl avatar fedotxxl commented on July 26, 2024 4

@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.

clauderic avatar clauderic commented on July 26, 2024 3

@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.

clauderic avatar clauderic commented on July 26, 2024 1

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.

jarredwitt avatar jarredwitt commented on July 26, 2024 1

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.

2021-03-10 11 41 58

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.

clauderic avatar clauderic commented on July 26, 2024

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.

mxck avatar mxck commented on July 26, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.