fn
onLongPress
v0.0.14testeddemoDirective-like helper that invokes a handler after a sustained long press
on a target element. Movement beyond distanceThreshold cancels the press, and an
optional onMouseUp callback reports the press duration, distance, and long-press status.
Listeners are passive by default and registered via useEventListener for automatic cleanup.
Examples
ts
onLongPress(el, () => console.log('held!'));ts
// Custom delay, cancel-on-move disabled, release reporting
const stop = onLongPress(el, onHeld, {
delay: 800,
distanceThreshold: false,
modifiers: { prevent: true },
onMouseUp: (duration, distance, isLongPress) => {
if (!isLongPress) onTap();
},
});Demo
Loading demo…
Signature
ts
export function onLongPress(
target: MaybeComputedElementRef,
handler: (event: PointerEvent) => void,
options: OnLongPressOptions ={ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
target | MaybeComputedElementRef | Element to watch for long presses |
handler | (event: PointerEvent) => void | Callback fired once the press passes delay |
options? | OnLongPressOptions | Long-press configuration |
Returns
OnLongPressReturnStop handle that removes all listeners