use-hold-repeat-handlers
Press-and-hold-to-repeat event handlers for pointer, mouse, touch and keyboard
Source
Package
Usage
use-hold-repeat-handlers returns event handlers that add press-and-hold-to-repeat behavior to an element.
It supports all use-hold-repeat options. Press and hold the buttons to change the value:
0
Definition
Event sources
By default, the hook returns pointer event handlers. Use the events option to choose
which events start and stop the hold:
Do not combine pointer with mouse or touch, pointer already handles both.
Keyboard
With keyboard events, use the keys option to restrict which keys start the hold:
To handle several keys on one element, call the hook once per key and merge the handlers with mergeEventHandlers. Focus the input and hold ArrowUp or ArrowDown to change the value:
Combining handler bundles
mergeEventHandlers merges several objects with event handlers into one.
Handlers with the same name are called in order:
Wrap the call in useMemo if you need stable handler references.
preventDefault
By default, event.preventDefault() is called on the start event. Set preventDefault: false
to keep the browser behavior. Touch start events are not prevented, use the
touch-action CSS property
to stop scrolling during a touch hold:
Imperative start/stop
The returned object also includes start and stop functions. Use them to control the hold
from events that the handlers do not cover:
Exported types
UseHoldRepeatEvent, UseHoldRepeatHandlersOptions and UseHoldRepeatHandlersReturnValue types
are exported from the @mantine/hooks package; you can import them in your application: