useHold
NumberField
stable
Implements a press-and-hold repeat pattern for increment/decrement controls. Fires the toggle callback once immediately on press, then starts an auto-repeat loop after an initial delay. Used internally by OrigamNumberField stepper buttons.
API
Signature
Full TypeScript signature sourced from the composable file.
Timers are cleared automatically via onScopeDispose — no manual cleanup needed in setup(). holdStop is still required on mouseup/touchend to cancel an in-progress hold.
API
Parameters
Input parameters accepted by this composable.
- toggleUpDownrequired(increment: boolean) => void
- Callback invoked on each tick. Receives true for increment (up), false for decrement (down).
- holdRepeatMaybeRefOrGetter<number>NUMBER_FIELD_DEFAULT_HOLD_REPEAT
- Repeat interval in milliseconds once the hold is established. Defaults to 50ms.
- holdDelayMaybeRefOrGetter<number>NUMBER_FIELD_DEFAULT_HOLD_DELAY
- Initial delay in milliseconds before the repeat loop starts. Defaults to 500ms.
API
Return values
Properties and methods exposed by the composable return object.
- holdStart
- Call on mousedown/touchstart. Pass 'up' to increment or 'down' to decrement. Fires once immediately, then begins the repeat loop after holdDelay.
- holdStop
- Call on mouseup/touchend/mouseleave to clear the timeout and interval. Also called automatically on scope dispose.
Usage
Examples
Ready-to-paste usage snippets.
Press-and-hold stepper