Drag & physics

Drag to dismiss

Flick notifications, cards or sheets away. A short drag springs back; a fling sends it flying.

Paste it into ChatGPT, Claude, Cursor or v0.
axis
direction
threshold0.40

Usage

React
import { useDragDismiss } from '@vizzele/react';

function Notification({ onClose, children }) {
  const ref = useDragDismiss<HTMLDivElement>({ axis: 'x', onDismiss: onClose });
  return <div ref={ref} className="vz-card">{children}</div>;
}

Props

PropTypeDefaultDescription
axis'x' | 'y''x'Drag axis.
direction'both' | 'positive' | 'negative''both'Which way dismisses; the other resists.
thresholdnumber0.4Fraction of size to drag before release dismisses.
velocitynumber700Flick speed (px/s) that dismisses.
fadebooleantrueFade while dragging away.
onDismiss(dir: 1 | -1) => void—Remove the element here.

Accessibility

  • Always offer a visible close button too — dragging is never the only way to dismiss.