Skip to main content
Sensor is the abstract base class for all sensor implementations in dnd-kit. Sensors are responsible for detecting and initiating drag operations by handling user interactions such as mouse, touch, keyboard, or custom input methods.

Sensor Class

Constructor

Creates a new sensor instance.
T extends DragDropManager
required
The drag and drop manager instance.
U extends SensorOptions
Optional sensor configuration.
extends DragDropManager<any, any>
default:"DragDropManager<Draggable, Droppable>"
Type parameter for the drag drop manager.
extends SensorOptions
default:"SensorOptions"
Type parameter for sensor options.

Properties

manager

T
The drag drop manager instance that this sensor is bound to.

options

U | undefined
The configuration options for this sensor instance.

disabled

boolean
Whether the sensor instance is disabled.
Inherited from Plugin.

Methods

bind() (abstract)

Binds the sensor to a draggable source. Must be implemented by subclasses.
Draggable
required
The draggable element to bind to.
U
Optional sensor options specific to this draggable.
CleanupFunction
A cleanup function that unbinds the sensor when called.

Inherited from Plugin

enable()

Enables a disabled sensor instance.

disable()

Disables an enabled sensor instance.

isDisabled()

Checks if the sensor instance is disabled.
boolean
true if the sensor is disabled.

configure()

Configures a sensor instance with new options.
U
The new options to apply.

destroy()

Destroys a sensor instance and cleans up its resources.

Static Methods

configure()

Configures a sensor constructor with default options.
PluginOptions
required
The options to configure the constructor with.
SensorDescriptor
A configured sensor descriptor that can be passed to the manager.

Types

SensorOptions

Base type for sensor options.

SensorConstructor

Constructor type for creating sensor instances.

SensorDescriptor

Descriptor type for configuring sensors.

Sensors

Array type for multiple sensor configurations.

Activation Constraints

ActivationConstraint

Abstract base class for activation constraints.
Activation constraints allow you to control when a drag operation should start based on specific conditions.

ActivationController

Controller for managing activation constraints.

ActivationConstraints

Array type for activation constraints.

Implementing a Custom Sensor

Basic Implementation

With Activation Constraints

Usage Examples

Using Sensors with Manager

Configuring Sensors

Per-Draggable Sensors

Dynamic Sensor Management

Extending Defaults

Common Sensor Patterns

Pointer Sensor Pattern

Keyboard Sensor Pattern

See Also