Sensors
Detect user input and translate it into drag and drop operations.
Overview
Sensors detect user input and translate it into drag and drop operations. They handle the initiation, movement, and completion of drag operations from different input sources.
Built-in Sensors
The @dnd-kit/dom
package provides a set of built-in sensors that can be used to detect user input in the browser:
Pointer
Handles mouse, touch, and pen input with configurable activation constraints.
Keyboard
Enables keyboard navigation and activation using customizable key bindings.
Usage
Sensors can be configured both globally and per draggable element:
Local sensors configured on individual draggable elements take precedence over global sensors.
Creating Custom Sensors
You can create custom sensors by extending the Sensor
class:
Sensor Lifecycle
-
Construction
- Sensor instance created
- Options configured
- Initial setup performed
-
Binding
- Sensor bound to draggable element
- Event listeners registered
- Effects set up
-
Operation
- Input detected
- Coordinates tracked
- Drag operations managed
-
Cleanup
- Event listeners removed
- Effects cleaned up
- Resources released
API Reference
Base Sensor Class
Reference to the drag and drop manager instance.
Optional configuration options for the sensor.
Methods
bind(source: Draggable)
: Bind sensor to draggable elementenable()
: Enable the sensordisable()
: Disable the sensorisDisabled()
: Check if sensor is disableddestroy()
: Clean up sensor resources
Static Methods
configure(options)
: Create a configured sensor descriptor