useLongPress
@astryxdesign/core v0.7.1 · useLongPress
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
options | LongPressOptions | — | Configuration object. Required. |
options.onLongPress | (point: { x: number, y: number }) => void | — | Fired with the press start point once the press is held for delayMs. Required. |
options.disabled | MaybeRefOrGetter<boolean> | false | When true the detector is inert, so a disabled trigger can flip the flag without re-registering anything. Read on each press, so a ref or a getter works as well as a plain boolean. |
options.isDisabled | MaybeRefOrGetter<boolean> | — | The same switch under its other name; either one being true keeps the detector inert. |
options.delayMs | number | 500 | Hold duration before the press fires, in milliseconds. |
options.moveCancelPx | number | 10 | Movement past this distance on either axis cancels the press, treating it as a scroll or drag. |
Returns
| Name | Type | Description |
|---|---|---|
handlers | { onTouchStart, onTouchMove, onTouchEnd, onTouchCancel } | The four touch listeners to spread onto the target element, e.g. <button v-on="press.handlers">. A second finger, a lift, or a cancel ends the press; a move past moveCancelPx does too. |
start | (point: { x: number, y: number }) => void | Begins detection at a point. Call it from pointerdown. It clears any pending press first, then re-arms the timer. |
moveTo | (point: { x: number, y: number }) => boolean | Reports the pointer's new position. Returns true while the press is still inside the tolerance; past it the press is cancelled and it returns false. Returns false as well when no press is pending. |
cancel | () => void | Drops any pending press. Bind it to pointerup and pointercancel. Also runs when the component unmounts. |