Skip to main content

Usage

The Droppable class creates drop targets that can receive draggable elements. First, create a DragDropManager instance:

Accepting Specific Types

You can restrict which draggable elements can be dropped by using the accept property. See the draggable types documentation for more details.

Collision Detection

By default, the Droppable class uses the defaultCollisionDetection algorithm from @dnd-kit/collision: it first checks whether the pointer is over the drop target, and falls back to rectangle intersection when there is no pointer collision (for example, during keyboard-driven drags): You can customize this behavior with different collision detection algorithms:
For example, the closestCenter detector will detect collisions based on the distance between the center points, which is ideal for card stacking:

Collision Priority

When multiple droppable targets overlap, you can set priority to determine which one should receive the drop. This is particularly useful for nested containers:

API Reference

Arguments

The Droppable class accepts the following arguments:
string | number
required
A unique identifier for this droppable target within the same drag and drop context provider.
Element
The DOM element to make droppable. While not required in the constructor, it must be set to enable dropping.
Type | Type[] | ((source: Draggable) => boolean)
Restrict which draggables can be dropped on this target. Pass a single type, an array of types, or a predicate that receives the draggable and returns true to accept it. If omitted, every draggable is accepted. See accepting specific types for more details.
string | number | Symbol
An optional identifier to categorize this droppable. Whether a draggable can be dropped on this target is determined by this droppable’s own accept rule checked against the draggable’s type — a droppable’s type is not consulted by accept rules.
CollisionDetector
A function to determine when draggable elements are over this target. See collision detection for built-in options, such as:
  • defaultCollisionDetection: Default, uses pointer intersection with a fallback to rectangle intersection
  • shapeIntersection: Uses rectangle intersection
  • pointerIntersection: Uses pointer position for precise detection
  • closestCenter: Uses center point distance, ideal for card stacking
  • directionBiased: Considers drag direction, useful for sortable lists
number
Priority level when multiple droppable targets overlap. Higher numbers take precedence. See collision priority for more details.
boolean
Set to true to temporarily prevent dropping on this target.
{[key: string]: any}
Optional data to associate with this droppable target, available in event handlers.
() => Effect[]
This is an advanced feature and should not need to be used by most consumers.
You can supply a function that returns an array of reactive effects that can be set up and automatically cleaned up when invoking the destroy() method of this instance.

Properties

The Droppable instance provides these key properties:
  • id: The unique identifier
  • element: The DOM element acting as the drop target
  • disabled: Whether dropping is currently disabled
  • isDropTarget: Whether a draggable is currently over this target
  • shape: The current bounding shape of the drop target

Methods

  • accepts(draggable): Check if this target accepts a draggable element
  • refreshShape(): Recalculate the target’s dimensions
  • register(): Register this target with the manager
  • unregister(): Remove this target from the manager
  • destroy(): Clean up this droppable instance and remove all listeners