useMove: expose pointerId on move events and distinguish cancellation from release
Provide a general summary of the feature here
useMove already tracks the driving pointer's id internally (first-come on pointerdown, id-matched on pointermove/pointerup/pointercancel) but never exposes it to consumers, and it registers pointercancel to the same handler as pointerup, so a cancelled drag is indistinguishable from a committed one. Request: expose pointerId (or an opaque interaction id) on the movestart/move/moveend events, and provide a cancellation signal distinct from release — either an onMoveCancel callback or a canceled flag on moveend.
Expected Behavior?
- Move events carry the identity of the interaction that produced them:
pointerId(or an opaque id that also distinguishes a keyboard-initiated interaction from a live pointer drag). - A drag terminated by
pointercancelis distinguishable from one terminated bypointerup, e.g.onMoveEndreceivescanceled: true, or a separateonMoveCancelfires.
Current Behavior
- The callback stream carries only
pointerType, deltas, and modifier keys. The pointer iduseMovetracks in its internal state ref is never surfaced. pointercancelis registered to the same handler aspointerup(observed in react-aria 3.51.0 source), so consumers cannot implement discard-on-cancel semantics from the events alone.- Keyboard arrows fire synchronous
start → move → endbursts through the same callbacks while a pointer drag is live, with nothing butpointerTypeto disambiguate the two concurrent interactions.
Possible Solution
useMove already has both pieces of information internally — state.current.id and which of pointerup/pointercancel ended the drag. Exposing them looks additive and non-breaking:
interface MoveMoveEvent {
// existing fields …
pointerId?: number; // undefined for keyboard
}
interface MoveEndEvent {
// existing fields …
canceled?: boolean; // true when the drag ended via pointercancel
}Current workaround (what we ship today): (a) re-derive the pointer id from our own onPointerDown chained via mergeProps beside useMove's, with first-come guards so a second pointer pressed before any movement doesn't replace the recorded driver id, plus one-shot window listeners to release the id when a press ends without a drag; and (b) capture-phase window pointercancel/keydown (Escape) listeners attached for the duration of the drag, purely to observe cancellation before useMove's own bubble-phase listeners treat it as a release. The requested fields would delete most of that bespoke listener code.
Context
We built an APG window-splitter–style resize handle (role="separator", arrow keys to resize, drag with any pointer) on useMove, with discard-on-cancel semantics: pointercancel or Escape mid-drag must revert the preview rather than commit it. Getting there required the workaround above, and the identity gap produced two real defects that shipped past review before being caught: a keyboard arrow press during a live pointer drag stranded the drag's state (the synchronous keyboard burst ended "the" interaction), and a second touch's pointercancel discarded — and after a first fix, a second touch pressed before movement made the driving pointer's cancel commit — because the events carry no pointer identity to match against.
For what it's worth, useTableColumnResize works around the same gaps internally (own Escape handling; cancel commits via moveend), so the need seems to exist inside the library too.
Examples
Desired consumer code:
const { moveProps } = useMove({
onMoveStart(e) { begin(e.pointerId); },
onMove(e) { if (owns(e.pointerId)) preview(e.deltaX); },
onMoveEnd(e) { e.canceled ? discard() : commit(); },
});Your Company/Team
Bonterra / Stitch design system
Tracking Issue
Internal (not publicly available)
Source: adobe/react-spectrum