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

Full TypeScript signature sourced from the composable file.

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

Parameters

Input parameters accepted by this composable.

isActive
required
Ref<boolean>
Whether the drawer is currently open. The composable writes to this ref when a fling gesture settles.
isTemporary
required
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
required
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
required
Ref<boolean>
When true all touch handling is disabled. Lets the consumer disable swipe gestures without unmounting the composable.
position
required
Ref<'left' | 'right' | 'top' | 'bottom'>
The edge from which the drawer slides in. Determines the touch zone, coordinate axis, and transform direction.

API

Return values

Properties and methods exposed by the composable return object.

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

Examples

Ready-to-paste usage snippets.

Swipeable navigation drawer

vue