usePointerDrag
Tracks pointer drag gestures on a target element with axis locking and movement thresholds.
Loading preview...
The usePointerDrag hook tracks pointer drag gestures on a target element using setPointerCapture so dragging continues smoothly even when the pointer leaves the element bounds, supporting axis locking ('x', 'y', or 'both') and activation distance thresholds.
Installation
Usage
Examples
Draggable Card with Transform Offset
Translate an element by deltaX and deltaY while dragging and accumulate the final offset in onDragEnd.
API Reference
UsePointerDragOptions
Configuration options and gesture callbacks for pointer dragging.
Property
Specification
enabled?uniondefault:true
Whether pointer drag tracking is enabled
Full Signature
axis?uniondefault:'both'
Constrain drag deltas to a specific axis
Full Signature
threshold?numberdefault:0
Minimum distance in pixels before dragging starts
Full Signature
preventUserSelect?uniondefault:true
Disable text selection on
document.body while draggingFull Signature
preventDefault?uniondefault:false
Call
event.preventDefault() on pointer eventsFull Signature
onDragStart?function
Callback fired when dragging begins.
Full Signature
Parameters
(statePointerDragState, event: PointerEventonDragMove?function
Callback fired on each pointer move while dragging.
Full Signature
Parameters
(statePointerDragState, event: PointerEventonDragEnd?function
Callback fired when the drag operation ends or is cancelled.
Full Signature
Parameters
(statePointerDragState, event: PointerEventPointerDragState
Live coordinates and movement deltas returned by the hook.
Property
Specification
isDraggingunion
Whether a drag gesture is currently active.
Full Signature
xnumber
Current pointer X coordinate (
clientX).ynumber
Current pointer Y coordinate (
clientY).startXnumber
Initial pointer X coordinate where the drag started.
startYnumber
Initial pointer Y coordinate where the drag started.
deltaXnumber
Total horizontal displacement from
startX.deltaYnumber
Total vertical displacement from
startY.movementXnumber
Horizontal distance moved since the previous pointer move event.
movementYnumber
Vertical distance moved since the previous pointer move event.