useLongPress @astryx-svelte/core v0.5.2 · hooks

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.
ts
import { hooks } from '@astryx-svelte/core/hooks';

Best practices

GuidancePractices
DoUse the reported point to position the surface you open, so it appears under the finger.
DoPair it with the pointer contextmenu handler rather than replacing it; this hook only covers touch.
Don'tUse it for the primary action of a control; press-and-hold is undiscoverable as the only way to do something.

Parameters

ParameterTypeDefaultDescription
options Required () => UseLongPressOptionsConfiguration object.
options.onLongPress Required (point: { x: number; y: number; }) => voidFired with the touch start point once the press is held for delayMs.
options.disabled booleanfalseWhen true, the returned touch handlers are inert.
options.delayMs number500Hold duration before the press fires, in milliseconds.
options.moveCancelPx number10Movement past this distance on either axis cancels the press, treating it as a scroll or drag.

Returns

FieldTypeDefaultDescription
handlers UseLongPressHandlersonTouchStart, onTouchMove, onTouchEnd and onTouchCancel to spread onto the target element.

Not declared by core, so this type is mapped from upstream's rather than read from the compiler.