本文へ移動
日本語
「スライドで確認」は Pro に含まれます。解除するとプレビューが表示されます。

仕組み

Position comes from one CSS variable, --_p (0 to 1): a runner exactly as wide as the travel distance moves the handle with translateX, and the fill and hint text derive from the same value, so a width change never misaligns anything. Dragging uses Pointer Events with pointer capture and writes the variable directly, without React renders. The handle is a <button>, not a slider: a plain tap only nudges it to hint that sliding is needed.

向いている場面

  • Irreversible actions that need protection from accidental taps: paying, withdrawing, confirming a delivery.
  • The main confirm action at the bottom of a mobile screen, instead of a button plus a confirmation dialog.
  • Steps with financial consequences, such as releasing funds.

向かない場面

  • Ordinary, reversible actions: a plain button is cheaper than sliding.
  • Desktop-first admin forms: a button with a confirmation dialog is handier than dragging.
  • Several confirmations side by side: use sliding only for the one that matters most.

使い方

import { useRef } from 'react'
import { SlideToConfirm } from './SlideToConfirm.jsx'

export function PayBar({ orderId }) {
  const ref = useRef(null)
  return (
    <SlideToConfirm
      ref={ref}
      label="Slide to pay"
      loadingLabel="Paying…"
      doneLabel="Payment complete"
      threshold={0.8}
      // Return a Promise: loading shows meanwhile, and failure resets the handle
      onConfirm={() => api.pay(orderId)}
    />
  )
  // To start over: ref.current?.reset(), or give the component a new key
}

プロパティ

プロパティ型既定値説明
labelReactNode'Slide to confirm'Hint text on the track (with the shimmer), also the accessible name of the handle button.
loadingLabelReactNode'Processing…'Shown while the Promise returned by onConfirm is pending.
doneLabelReactNode'Confirmed'Shown after completion.
labelsobject—Replaces other built-in text (hint, the instruction read by screen readers). Shallow-merged over the English defaults.
thresholdnumber0.8How far across the track the handle must be released to confirm, 0 to 1.
onConfirm() => void | Promise<unknown>—Called on confirm. A returned Promise shows loading, resolves to the done state and resets the handle on rejection.
disabledbooleanfalseDisables the control.
refRef<{ reset(), focus() }>—reset() returns the handle to the start and discards a pending result; focus() focuses the handle. A new key also works.
...restHTMLAttributes<HTMLDivElement>—Other attributes, such as className and style, go to the root.

アクセシビリティ

  • The handle is a focusable <button>: Enter, Space, Right Arrow and End confirm directly, and aria-describedby gives the instruction.
  • Screen reader activation (a click without a pointer press) also confirms; a plain pointer tap does not.
  • Processing and done states are read through an aria-live region; once done the button name changes and aria-disabled is set, so focus is not lost.
  • The knob is 50×50 and the track 60px tall; touch-action: pan-y keeps vertical page scrolling.
  • With reduced motion the shimmer is removed, snapping and returning are instant and the check is not drawn; dragging still follows 1:1.

モーション

Dragging has no transition and follows 1:1; returning below the threshold 360ms ease-out (no overshoot against the wall); snapping past it 240ms ease-out, then the knob lands with a 560ms spring bounce (1.12). Pressing shrinks the knob to 0.92 in 100ms and it springs back in 360ms. Icon switch 240ms spring; check draw 360ms after 80ms; shimmer 2.8s per sweep; tap nudge 14px over 520ms spring.

プロジェクトに追加

Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。

SlideToConfirm.jsxslide-to-confirm.csstokens.cssREADME.md

2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

フォーム入力
「空き時間グリッド」は Pro に含まれます。解除するとプレビューが表示されます。
「図形のブール演算」は Pro に含まれます。解除するとプレビューが表示されます。
「カスケード選択」は Pro に含まれます。解除するとプレビューが表示されます。