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
Signature TypeScript complète extraite du fichier du composable.
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
Paramètres
Paramètres d'entrée acceptés par ce composable.
- toggleUpDownrequis(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
Valeurs de retour
Propriétés et méthodes exposées par l'objet retourné par le composable.
- 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
Exemples
Extraits de code prêts à coller.
Press-and-hold stepper