defaultCollisionDetection
The default collision detection algorithm that combines pointer and shape intersection detection.Description
Returns the droppable that has the greatest intersection area with the pointer coordinates. If there are no pointer coordinates, or the pointer is not intersecting with any droppable, returns the greatest intersection area between the collision shape and other intersecting droppable shapes.Parameters
The current drag operation containing shape and position information
The droppable element to check for collision
Returns
Returns a collision object with
id, value, type, and priority properties, or null if no collision is detectedUsage Example
closestCenter
Detects collisions based on the distance between the center of the draggable and the center of droppables.Description
Returns the distance between the droppable shape and the drag operation shape. Falls back todefaultCollisionDetection if a collision is already detected.
Parameters
The current drag operation containing shape and position information
The droppable element to check for collision
Returns
Returns a collision object with
value calculated as 1 / distance, or null if the droppable has no shapeUsage Example
closestCorners
Detects collisions based on the average distance between the corners of draggable and droppable elements.Description
Returns the distance between the corners of the droppable shape and the drag operation shape. Calculates the average distance between all four corners.Parameters
The current drag operation containing shape and position information
The droppable element to check for collision
Returns
Returns a collision object with
value calculated as 1 / (average corner distance), or null if the droppable has no shapeUsage Example
pointerIntersection
A high precision collision detection algorithm that detects whether the pointer intersects with a droppable element.Description
Returns the distance between the pointer coordinates and the center of the droppable element if the pointer is within the droppable element. Returnsnull if the pointer is outside of the droppable element.
Parameters
The current drag operation containing pointer position
The droppable element to check for pointer intersection
Returns
Returns a collision object with:
type:CollisionType.PointerIntersectionpriority:CollisionPriority.Highvalue:1 / distancefrom pointer to droppable center
null if pointer is outside the droppableUsage Example
pointerDistance
Detects collisions based on the distance between the pointer and the center of droppables.Description
Returns the distance between the droppable shape center and the drag operation pointer position. UnlikepointerIntersection, this algorithm doesn’t require the pointer to be inside the droppable.
Parameters
The current drag operation containing pointer position
The droppable element to check for collision
Returns
Returns a collision object with
value calculated as 1 / distance, or null if the droppable has no shapeUsage Example
shapeIntersection
Detects collisions based on the intersection area between draggable and droppable shapes.Description
Returns the droppable with the greatest intersection area with the collision shape. Uses both intersection ratio and distance to pointer for prioritization.Parameters
The current drag operation containing shape information
The droppable element to check for shape intersection
Returns
Returns a collision object with:
type:CollisionType.ShapeIntersectionpriority:CollisionPriority.Normalvalue:intersectionRatio / distance
null if there’s no intersection or shapes are missingUsage Example
directionBiased
A directional collision detection algorithm that prioritizes droppables in the direction of movement.Description
Detects collisions based on the direction of drag movement. Only considers droppables that are positioned in the direction the draggable is moving. Falls back todefaultCollisionDetection when there’s no movement direction.
Parameters
The current drag operation containing shape, position, and direction information
The droppable element to check for collision
Returns
Returns a collision object if the droppable is in the direction of movement, or
null otherwiseUsage Example
CollisionDetector Type
All collision detection algorithms implement theCollisionDetector type:
Choosing an Algorithm
- defaultCollisionDetection: Best general-purpose algorithm, works well for most use cases
- closestCenter: Good for free-form layouts where items can be placed anywhere
- closestCorners: Ideal for grid layouts with precise positioning requirements
- pointerIntersection: Use when you need high precision pointer-based interactions
- pointerDistance: Good for detecting the nearest droppable without requiring direct overlap
- shapeIntersection: Best when you want to base collisions on overlapping areas
- directionBiased: Optimal for keyboard navigation or when direction of movement matters