Skip to content
WANCRAFT

A.66Buttons & Controls

Swipe to Confirm

A slide-to-unlock control: drag the knob across the track to confirm, or step it there with the arrow keys.

NewReactMotionCSSTailwindintermediate

Overview

Swipe to Confirm asks for a deliberate gesture before an action runs. Drag the knob along the track: a fill follows it, the shimmering hint fades as you go, and releasing before the threshold springs the knob back. Past the threshold (or with a confident flick past halfway) it completes, draws a check, announces the result and calls onConfirm, then optionally resets. Without a pointer, the knob is a role="slider": the arrow keys move it in 10% steps and reaching 100% confirms, while leaving the control half-way springs it back.

01Installation

Method 01 · Registry

CLI verified

Uses the shadcn CLI in a project initialised with shadcn init. Installs the file to components/ui/swipe-to-confirm.tsx and adds its dependencies.

npx shadcn@latest add https://wancraft.my/r/swipe-to-confirm.json

Method 02 · Copy and paste

  1. 1. Install the dependencies below.
  2. 2. Copy the source from the Code tab into components/ui/swipe-to-confirm.tsx.
  3. 3. Import it and adjust props.
npm install motion
Dependencies
motion
Peer
react ≥ 18, tailwindcss ≥ 4
Added
13 Oct 2026
Updated
—

02Usage

The default configuration. Change properties above to generate a tailored example in the Usage tab.

example.tsx
import { SwipeToConfirm } from "@/components/ui/swipe-to-confirm";

export function SwipeToConfirmExample() {
  return (
    <div className="w-full max-w-sm">
      <SwipeToConfirm onConfirm={() => console.log("Confirmed")} />
    </div>
  );
}

03Props

PropTypeDefaultDescription
onConfirm() => void—Called once when the swipe (or keyboard steps) reach the end.
onReset() => void—Called when the control returns to the start after confirming.
labelstring"Slide to confirm"Hint in the track and accessible name of the slider.
confirmedLabelstring"Confirmed"Shown and announced once confirmed.
thresholdnumber0.8Fraction of the track (0.5–0.95) the knob must pass before release confirms.
resetDelaynumber2500Reset after this many ms; 0 keeps the confirmed state.
accentstring"#FF7448"Fill, confirmed track and focus ring colour.
inkColorstring"#0B0D0F"Text and knob colour on top of the accent once confirmed.
shimmerbooleantrueAnimated shine across the hint text.
disabledbooleanfalseDisable dragging and keyboard input.
...propsHTMLAttributes<HTMLDivElement>—Forwarded to the root; the track fills the root's width.

04Features

  • 01Motion drag with constraints; early release springs back, past the threshold (or a fast flick past halfway) completes
  • 02Fill trails the knob and the hint fades with distance — all motion values, no re-render while dragging
  • 03Shimmering hint via the Web Animations API, paused offscreen and in hidden tabs
  • 04Success state with a drawn check, confirmed label and optional automatic reset
  • 05Track width is measured with a ResizeObserver, so it works at any width
motion · springmotion · continuousinput · draginput · pointerinput · keyboardinput · focus

05Accessibility

  • The knob is a focusable role="slider" (0–100%) labelled by the hint, with aria-valuetext and an instruction linked through aria-describedby.
  • Keyboard alternative: Arrow Right / Up move 10%, Page Up 25%, Arrow Left / Down and Page Down move back, Home returns to the start; reaching 100% confirms. Blurring a partial swipe springs it back.
  • A polite live region announces the confirmed label.
  • Vertical page scrolling still works on touch (touch-action: pan-y on the knob).
  • With prefers-reduced-motion the knob moves without springs and the shimmer is off.

06Limitations

  • Pointer progress is exposed to assistive technology when the drag ends, not on every frame.