useTouch

Commons
stable

Enables swipe-to-open / swipe-to-close gesture handling for drawer-like components. Listens to touchstart / touchmove / touchend on window, computes drag progress relative to a positioned edge (left, right, top, bottom), and resolves the gesture via velocity-based fling detection using useVelocity.

API

Signature

Signature TypeScript complète extraite du fichier du composable.

typescript

useTouch is used internally by OrigamNavigationDrawer. It attaches passive listeners to window for touchstart and touchend, and a non-passive listener for touchmove (to call preventDefault during confirmed drags). Disable gesture support via touchless when the content itself needs to scroll horizontally.

API

Paramètres

Paramètres d'entrée acceptés par ce composable.

isActive
requis
Ref<boolean>
Whether the drawer is currently open. The composable writes to this ref when a fling gesture settles.
isTemporary
requis
Ref<boolean>
When true the drawer is temporary (modal overlay). The touch zone logic also activates for touches anywhere inside the element body, not only at the edge.
width
requis
Ref<number>
Pixel width (or height for top/bottom positions) of the drawer. Used to compute drag progress as a fraction in [0, 1].
touchless
requis
Ref<boolean>
When true all touch handling is disabled. Lets the consumer disable swipe gestures without unmounting the composable.
position
requis
Ref<'left' | 'right' | 'top' | 'bottom'>
The edge from which the drawer slides in. Determines the touch zone, coordinate axis, and transform direction.

API

Valeurs de retour

Propriétés et méthodes exposées par l'objet retourné par le composable.

isDragging
True while a confirmed drag is in progress (threshold of 3px perpendicular movement must be exceeded before dragging starts).
dragProgress
Fraction in [0, 1] representing how open the drawer is during a drag. 0 = fully closed, 1 = fully open.
dragStyles
Inline styles to apply during a drag to move the drawer with the finger. Undefined when not dragging (CSS transitions take over). Bind to the drawer root element.

Usage

Exemples

Extraits de code prêts à coller.

Swipeable navigation drawer

vue