You will learn
- How to make elements draggable
- How to set up droppable targets
- How to listen to drag and drop events to move elements
Overview
The@dnd-kit/solid package provides a set of SolidJS hooks and components that you can use to build drag and drop interfaces. It is a thin SolidJS integration layer built on top of the vanilla library, so all of the same concepts are shared and can be used. You can refer to the vanilla documentation of these concepts, such as plugins, modifiers, and sensors.
@dnd-kit/solid requires SolidJS 1.8 or later.Installation
Before getting started, make sure you install@dnd-kit/solid in your project:
Making elements draggable
Let’s get started by creating draggable elements. TheuseDraggable hook requires a unique id, and returns a ref callback that you can attach to any element.
Creating droppable elements
To create drop targets, use theuseDroppable hook.
Putting all the pieces together
Wrap your draggable and droppable elements in aDragDropProvider to enable drag and drop interactions.
When passing reactive props to hooks like
useSortable, use getter syntax to maintain Solid’s fine-grained reactivity:Next steps
DragDropProvider
Create drag and drop contexts for your draggable and droppable elements.
useDraggable
Learn how to make elements draggable with the
useDraggable hook.useDroppable
Learn how to create droppable targets with the
useDroppable hook.useSortable
Learn how to create sortable elements with the
useSortable hook.