V2 to V3

[BREAKING CHANGE] Drop support for 'both' option in detect param

Returning both mouse and touch handlers as a hook result caused unintended edge cases on touch devices that emulated clicks. Therefore 'both' value was removed and hook is now using 'pointer' as a default value for detect param.

This also enables to support more type of events in the future.

Pointer events should be sufficient replacement for 'both' option, but you can also programmatically detect if current device support touch events and set proper detect value based on that.

Before

const bind = useLongPress(() => console.log('Long pressed'), {
  detect: 'both',
})

After

const bind = useLongPress(() => console.log('Long pressed'), {
  detect: 'pointer',
})

[BREAKING CHANGE] Typings and param values

TypeScript's typings were refactored to use more consistent and precise names. Also changed callback reason values (see LongPressEventReason)

  • Changed generics order from useLongPress<Target, Callback, Context> to useLongPress<Target, Context, Callback>

  • Renamed LongPressDetectEvents enum to LongPressEventType

    • LongPressDetectEvents.MOUSE -> LongPressEventType.Mouse

    • LongPressDetectEvents.TOUCH -> LongPressEventType.Touch

  • Added LongPressEventType.Pointer

  • Renamed LongPressEventReason enum to LongPressCallbackReason

    • LongPressEventReason.CANCELED_BY_MOVEMENT ('canceled-by-movement') -> LongPressCallbackReason.CancelledByMovement ('cancelled-by-movement')

    • LongPressEventReason.CANCELED_BY_TIMEOUT ('canceled-by-timeout') -> LongPressCallbackReason.CancelledByRelease ('cancelled-by-release')

  • Removed Coordinates type

  • Renamed EmptyObject type to LongPressEmptyHandlers

  • Renamed CallableContextResult type to LongPressResult

  • Renamed LongPressResult type to LongPressHandlers

  • Added mouse and touch handlers types - LongPressMouseHandlers and LongPressTouchHandlers

Last updated