Skip to main content
Sensors are responsible for detecting user input and initiating drag operations. They handle the actual interaction layer (mouse, touch, keyboard, etc.) and translate those interactions into drag operations that the manager can coordinate.

Overview

Sensors:
  • Detect user input (pointer events, keyboard events, etc.)
  • Validate activation constraints
  • Initiate drag operations by calling manager actions
  • Handle movement and completion
  • Clean up event listeners when done

Built-in sensors

dnd-kit provides two primary sensors in @dnd-kit/dom:

PointerSensor

Handles mouse, touch, and pen input:
The PointerSensor uses the Pointer Events API, which unifies mouse, touch, and pen interactions.

KeyboardSensor

Handles keyboard navigation:
The KeyboardSensor enables accessibility by allowing users to drag items using arrow keys.

Default configuration

By default, both sensors are enabled:

Sensor architecture

Base class

All sensors extend the abstract Sensor base class:

Lifecycle

  1. Binding: The sensor binds to each draggable element
  2. Activation: User interaction triggers activation constraints
  3. Start: Constraints are met, drag operation starts
  4. Move: Sensor tracks movement and updates position
  5. End: User completes or cancels the drag
  6. Cleanup: Event listeners are removed

PointerSensor

The PointerSensor handles pointer-based input.

Activation constraints

Activation constraints prevent accidental drags:

Built-in constraints

Delay constraint:
Distance constraint:

Default behavior

The PointerSensor has smart defaults:

Configuration options

Custom activator elements:
Prevent activation:

KeyboardSensor

The KeyboardSensor enables keyboard-based dragging.

Activation

By default:
  • Press Space or Enter on a draggable to start dragging
  • Use arrow keys to move
  • Press Space or Enter again to drop
  • Press Escape to cancel

Configuration

Custom sensors

You can create custom sensors by extending the Sensor base class.

Basic example

Using manager actions

Sensors interact with the manager through actions:

Activation constraints

Activation constraints determine when a drag should start:

ActivationController

The ActivationController manages constraints:

Per-draggable sensors

You can configure sensors per draggable:
This overrides the manager’s default sensors for this specific draggable.

Configuration pattern

Sensors use the configurator pattern for options:

How it works

The configure static method returns a descriptor:
The manager resolves descriptors when creating sensor instances:

Sensor implementation details

Binding to draggables

When a draggable is registered, sensors bind to it:

Movement tracking

Sensors track movement and update the manager:

Cleanup

Sensors clean up when destroyed:

Best practices

Use both sensors by default: The PointerSensor and KeyboardSensor work well together and provide the best experience for all users.
Don’t forget activation constraints: Always configure appropriate activation constraints to prevent accidental drags, especially on touch devices.
Test on multiple input types: Make sure to test your drag and drop implementation with mouse, touch, and keyboard to ensure all sensors work correctly.

Sensors API

Sensors API reference

Custom sensors

Build your own sensors

Accessibility

Keyboard navigation

Touch devices

Touch-specific configuration