Overview
Sensors detect user input and translate it into drag and drop operations.
Sensors are used to detect different input methods in order to initiate drag operations, respond to movement and end or cancel the operation.
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
Respond to mouse, touch and pen input using the Pointer sensor.
Keyboard
Respond to keyboard input using the Keyboard sensor.
Usage
Sensors can be applied globally or to individual draggable elements.
The Pointer sensor and Keyboard sensor are enabled by default.
Global sensors
Sensors can be applied globally by passing them to the DragDropManager instance. For example, if you wanted to only enable the Pointer sensor:
Local sensors
Sensors can also be applied to individual draggable elements by passing them to the modifiers option.
For example, if you wanted to only enable the KeyboardSensor for this specific draggable element, while using the PointerSensor
globally for all other draggable elements:
Custom sensors
You can also create custom sensors to detect input from other input sources, or extend the built-in sensors to add additional functionality on top of them.
To do so, you can create a new sensor by extending the Sensor
class and implementing the required methods.