useLongPress
Detects a single-finger press-and-hold and reports where it happened, so touch users can reach affordances that a pointer gets from right-click. iOS Safari never synthesizes a contextmenu event on long-press, which makes this the only touch route into a cursor-positioned surface such as ContextMenu. The press cancels on movement, lift, multi-touch or unmount.
@astryxdesign/core/hooks
Signature
Call shape
useLongPress(options: UseLongPressOptions): UseLongPressHandlersParameters
| Name | Type and behavior |
|---|---|
options | UseLongPressOptions · requiredConfiguration object. |
options.onLongPress | (point: {x: number; y: number}) => void · requiredFired with the touch start point once the press is held for delayMs. |
options.disabled | boolean · optional · default falseWhen true, the returned touch handlers are inert. |
options.delayMs | number · optional · default 500Hold duration before the press fires, in milliseconds. |
options.moveCancelPx | number · optional · default 10Movement past this distance on either axis cancels the press, treating it as a scroll or drag. |
Returns
| Name | Type and behavior |
|---|---|
handlers | UseLongPressHandlersonTouchStart, onTouchMove, onTouchEnd and onTouchCancel to spread onto the target element. |
Usage
Detects a single-finger press-and-hold and reports where it happened, so touch users can reach affordances that a pointer gets from right-click. iOS Safari never synthesizes a contextmenu event on long-press, which makes this the only touch route into a cursor-positioned surface such as ContextMenu. The press cancels on movement, lift, multi-touch or unmount.
- Use the reported point to position the surface you open, so it appears under the finger.
- Pair it with the pointer contextmenu handler rather than replacing it; this hook only covers touch.
- Use it for the primary action of a control; press-and-hold is undiscoverable as the only way to do something.