EXEPERTAI LAB

Research alpha

Time Machine
EXEPERTAI LAB
GALLERY / COLLECTION
← Browse Astryx gallery
hooks·hook·@astryxdesign/core

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): UseLongPressHandlers
Parameters
NameType and behavior
optionsUseLongPressOptions · required
Configuration object.
options.onLongPress(point: {x: number; y: number}) => void · required
Fired with the touch start point once the press is held for delayMs.
options.disabledboolean · optional · default false
When true, the returned touch handlers are inert.
options.delayMsnumber · optional · default 500
Hold duration before the press fires, in milliseconds.
options.moveCancelPxnumber · optional · default 10
Movement past this distance on either axis cancels the press, treating it as a scroll or drag.
Returns
NameType and behavior
handlersUseLongPressHandlers
onTouchStart, 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.