on-long-press
Call a handler when an element is pressed and held.
| Package | @vizejs/composable/on-long-press |
| Own the source | vize lib pull composable:on-long-press |
| Runtime exports | onLongPress |
| Gzip budget | 2560 B |
Usage
import { onLongPress } from "@vizejs/composable/on-long-press";
Runtime contract
| Utility | Category | Stability | SSR | Hydration | Cleanup | Targets | Host globals | Uses |
|---|---|---|---|---|---|---|---|---|
onLongPress |
input | experimental | deterministic-fallback | stable | caller, reactive-scope | web, desktop | globalThis |
resolveElement, tryOnScopeDispose |
API
onLongPress
Call a handler when an element is pressed and held. Uses Pointer Events, so mouse, touch, and pen behave alike. Moving more than distanceThreshold or releasing early cancels the press. Nothing is registered during server rendering; listeners and the timer are released with the owning scope or the returned stop function.
function onLongPress( target: MaybeElementTarget, handler: (event: PointerEvent) => void, options: OnLongPressOptions = {}, ): () => void
Types
LongPressModifiers
Event modifiers applied to the pointer events handled by onLongPress.
| Member | Type | Description |
|---|---|---|
stop? |
boolean |
Call stopPropagation(). |
once? |
boolean |
Fire at most once. |
prevent? |
boolean |
Call preventDefault(). |
capture? |
boolean |
Listen in the capture phase. |
self? |
boolean |
Only start when the element itself (not a descendant) is pressed. |
LongPressRelease
Summary passed to OnLongPressOptions.onRelease.
| Member | Type | Description |
|---|---|---|
duration |
number |
Milliseconds between press and release. |
distance |
number |
Pointer travel in CSS pixels. |
isLongPress |
boolean |
Whether the long-press handler fired. |
OnLongPressOptions
Options for onLongPress.
| Member | Type | Description |
|---|---|---|
delay? |
number |
Hold time in milliseconds. |
distanceThreshold? |
number |
Maximum pointer travel before the press is cancelled. |
modifiers? |
LongPressModifiers |
Event modifiers. |
onRelease? |
(release: LongPressRelease, event: PointerEvent) => void |
Called on every release with timing details. |
now? |
() => number |
Clock for durations. |
scheduler? |
TimeoutScheduler |
Owns the hold timer. |