Constraints that must be satisfied before a drag starts.Can be a static constraint array or a function that returns constraints based on the event and source:
activationConstraints(event, source) { if (event.pointerType === 'touch') { return [new PointerActivationConstraints.Delay({ value: 250, tolerance: 5 })]; } return undefined; // No constraints for mouse}
Requires the pointer to be held down for a duration before activating.
import { PointerActivationConstraints } from '@dnd-kit/dom';new PointerActivationConstraints.Delay({ value: 250, // Milliseconds to wait tolerance: 5 // Max pixels of movement allowed});
Maximum distance in pixels the pointer can move during the delay.If the pointer moves more than this distance, the constraint fails and drag is canceled.
Multiple constraints can be combined. The drag activates when any constraint is satisfied:
PointerSensor.configure({ activationConstraints: [ // Activate after 200ms OR after moving 8px new PointerActivationConstraints.Delay({ value: 200, tolerance: 10 }), new PointerActivationConstraints.Distance({ value: 8 }) ]});
Fast: Hold Shift + arrow key to move by offset * 5 pixels
// Move 10px per keypress, or 50px with ShiftKeyboardSensor.configure({ offset: 10 });// Different speeds per axisKeyboardSensor.configure({ offset: { x: 15, y: 10 } // 75px horizontal, 50px vertical with Shift});
import { DragDropManager, PointerSensor, KeyboardSensor, PointerActivationConstraints} from '@dnd-kit/dom';const manager = new DragDropManager({ sensors: [ // Pointer with custom constraints PointerSensor.configure({ activationConstraints(event, source) { // Touch: longer delay on mobile if (event.pointerType === 'touch') { return [ new PointerActivationConstraints.Delay({ value: 300, tolerance: 8 }) ]; } // Mouse: require 5px movement return [ new PointerActivationConstraints.Distance({ value: 5 }) ]; }, // Only drag from elements with .drag-handle class activatorElements(source) { const handle = source.element.querySelector('.drag-handle'); return handle ? [handle] : []; }, // Don't drag from buttons or links preventActivation(event, source) { const target = event.target as Element; return target.tagName === 'BUTTON' || target.tagName === 'A'; } }), // Keyboard with larger movement KeyboardSensor.configure({ offset: 20, // Move 20px at a time (100px with Shift) keyboardCodes: { start: ['Space'], // Only Space to start cancel: ['Escape'], end: ['Enter'], // Only Enter to drop up: ['ArrowUp', 'w'], // Support WASD down: ['ArrowDown', 's'], left: ['ArrowLeft', 'a'], right: ['ArrowRight', 'd'] } }) ]});