Concepts
Draggable
Make elements draggable to drop them over droppable targets.
Usage
First, create a DragDropManager instance to orchestrate the drag and drop system. Then use the Draggable class to make elements draggable:
Handles
By default, the entire element can be used to initiate dragging. You can restrict dragging to a specific handle element:
const element = document.createElement('div');
const handle = document.createElement('div');
handle.classList.add('handle');
handle.innerHTML = '⋮'; // Three dots menu icon for drag handle
element.appendChild(handle);
const draggable = new Draggable({
id: 'draggable-1',
element,
handle, // Only allow dragging from the handle
}, manager);Types
You can assign types to draggable elements to restrict which droppable targets they can be dropped on:
// Assign a type
const draggable = new Draggable({
id: 'draggable-1',
element,
type: 'item', // Only droppables accepting 'item' type will be valid targets
}, manager);Feedback
You can customize how the element behaves while being dragged using the Feedback plugin’s per-entity configuration:
import {Draggable, DragDropManager, Feedback} from '@dnd-kit/dom';
const draggable = new Draggable({
id: 'draggable-1',
element,
plugins: [Feedback.configure({ feedback: 'clone' })],
}, manager);Available feedback options:
'default': The original element moves with the drag (best for most cases)'clone': A copy of the element stays in place while the original moves (good for drag-to-copy)'move': The element moves without a placeholder (minimal visual feedback)'none': No visual feedback (useful for custom drag overlays)
API Reference
Arguments
The Draggable class accepts the following arguments:
A unique identifier for this draggable element within the same drag and drop context provider.
The DOM element to make draggable. While not required in the constructor, it must be set to enable dragging.
Optionally specify a drag handle element. If not provided, the entire element will be draggable. See drag handles.
Optionally assign a type to restrict which droppable targets can accept this element. See types.
An array of plugin descriptors for per-entity plugin configuration. Use Plugin.configure() to create descriptors. See feedback.
Set to true to temporarily prevent dragging this element.
An array of modifiers to customize drag behavior.
An array of sensors to detect drag interactions.
Optional data to associate with this draggable element, available in event handlers.
destroy() method of this instance.Properties
The Draggable instance provides these key properties:
id: The unique identifierelement: The main DOM elementhandle: The drag handle element (if specified)type: The assigned typedisabled: Whether dragging is disabledisDragging: Whether this element is currently being draggedisDropping: Whether this element is being dropped
Methods
register(): Register this draggable with the managerunregister(): Remove this draggable from the managerdestroy(): Clean up this draggable instance and remove all listeners