Skip to content

useLongPress ​

Listen for a long press on an element.

Code demonstration ​

API ​

typescript
const { isPressing , pressingTime } = useLongPress(target: BasicTarget , options?: LongPressOptions)

Result ​

PropertyDescriptionType
isPressingIndicates the current pressing state. If pressing, the value is true; otherwise it's false.Readonly<Ref<boolean>>
pressingTimeRepresents the duration of pressing (possibly in milliseconds). This value will only be updated during the pressing period.Readonly<Ref<number>>

Params ​

PropertyDescriptionTypeDefault
targetDOM element or ref() => Element | Element | MutableRefObject<Element>-
optionsAdditional configUseLongPressOptions-

DropOptions ​

PropertyDescriptionTypeDefault
delayTime in ms till longpress gets callednumber500
minUpdateTimeMinimum time interval in ms for updating the longpress eventnumber100
cancelOnMoveWhether to cancel the longpress event when mouse movebooleantrue
modifierslongpress event modifiersLongPressModifiers-

LongPressModifiers ​

PropertyDescriptionTypeDefault
stopstopPropagation eventboolean-
onceeventListener once optionboolean-
preventpreventDefault eventboolean-
captureeventListener capture optionboolean-
selfcheck event target element same as selfboolean-

Source ​

Source · Document · Demo

Released under the MIT License.