UNPKG

@base-ui/react

Version:

Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.

58 lines 2.19 kB
import * as React from 'react'; export interface UsePressAndHoldParameters { disabled: boolean; readOnly?: boolean | undefined; /** * Called on each tick during a hold. Return `false` to stop the auto-change sequence. */ tick: (triggerEvent?: Event) => boolean; /** * Called when the hold ends via the global `pointerup` event. */ onStop?: ((nativeEvent: PointerEvent) => void) | undefined; /** * Interval between ticks once the hold is active. * @default 60 */ tickDelay?: number | undefined; /** * Delay before the repeating ticks start after the initial hold. * @default 400 */ startDelay?: number | undefined; /** * Pointer movement distance (px) that cancels the hold and is treated as scrolling. * @default 8 */ scrollDistance?: number | undefined; /** * Ref to the anchor element used to resolve `ownerWindow`. */ elementRef: React.RefObject<HTMLElement | null>; } export interface UsePressAndHoldReturnValue { pointerHandlers: { onTouchStart: React.TouchEventHandler<HTMLElement>; onTouchEnd: React.TouchEventHandler<HTMLElement>; onPointerDown: React.PointerEventHandler<HTMLElement>; onPointerUp: React.PointerEventHandler<HTMLElement>; onPointerMove: React.PointerEventHandler<HTMLElement>; onMouseEnter: React.MouseEventHandler<HTMLElement>; onMouseLeave: React.MouseEventHandler<HTMLElement>; onMouseUp: React.MouseEventHandler<HTMLElement>; }; /** * Returns `true` if the `onClick` handler should be skipped. * Use this in the element's `onClick` to prevent double-firing on mouse clicks * (already handled by `onPointerDown`) and to suppress the synthesized click * that browsers fire after a touch hold. */ shouldSkipClick: (event: React.MouseEvent) => boolean; } /** * Adds press-and-hold behavior to a button element. * On pointer down, performs one action immediately, then after a delay starts * continuous repeated actions at a fixed interval. Handles mouse, touch, and pen * inputs correctly, including Android-specific quirks. */ export declare function usePressAndHold(params: UsePressAndHoldParameters): UsePressAndHoldReturnValue;