Skip to content
English

How it works

The root keeps the size of the round trigger; the two pills live in an absolutely positioned tray beside it, so opening never moves anything. Closed, each pill is clipped to a circle at its anchored end (clip-path inset with round ends) and shifted onto the trigger by a distance measured when it opens. Opening releases both: the pills travel out with a light spring while the clip opens, the far one 40ms later, so the circle reads as splitting in two, and the labels sharpen in from a 3px blur. Cancel is the pill nearest the trigger, so a hurried second click lands on the safe choice. A darker layer drains across Cancel for the length of the timeout and pauses while the pointer or focus is inside.

Use it for

  • Deleting or removing one item in a list or card: a file, a saved address, a team member.
  • Destructive actions that deserve a second look but not a dialog that interrupts the page.
  • Toolbars and rows where there is free space beside the button for the pills to open over.

Look elsewhere when

  • Consequences that need explaining, or several items at once: use a confirm dialog.
  • Actions that must not slip at all: Hold to confirm asks for more.
  • Places with no room beside the button, such as a narrow cell at the edge of the screen.

Usage

import { TwoStepButton } from './TwoStepButton.jsx'

export function FileRow({ file, onRemoved }) {
  return (
    <div className="file-row">
      <span>{file.name}</span>
      <TwoStepButton
        label={`Delete ${file.name}`}
        // A Promise shows a spinner, then a check; reject it to keep the pills open and shake
        onConfirm={() => fetch(`/api/files/${file.id}`, { method: 'DELETE' }).then((r) => {
          if (!r.ok) throw new Error('failed')
        })}
        onDone={() => onRemoved(file.id)}
        timeout={4000}
      />
    </div>
  )
}

Props

PropTypeDefaultWhat it does
labelstring'Delete'Accessible name of the round trigger, for example “Delete Itinerary.pdf”.
iconReactNodetrash iconThe 18px icon in the trigger (decorative).
onConfirm() => void | Promise—Runs when the action pill is pressed. Return a Promise to show a spinner until it settles: fulfilled shows a check and the done label, then folds; rejected shakes the pill and keeps it open for another try.
onDone() => void—Called after the done face has shown and the pills fold back: the moment to remove the item.
onCancel() => void—Called when it folds without confirming: Cancel, Escape, a press outside or the timeout.
open / defaultOpen / onOpenChangeboolean / boolean / (open) => void- / false / -Controlled or uncontrolled open state, and a callback when it changes (use it to dim the row while asking).
timeoutnumber4000Milliseconds before it folds back by itself; a layer drains across Cancel meanwhile and pauses while the pointer or focus is inside. 0 turns it off.
tone'danger' | 'ink' | 'accent''danger'Colour of the action pill and the icon.
size'sm' | 'md' | 'lg''md'Trigger and pill height: 32, 40 or 44px (sm grows to 36px on touch screens).
align'end' | 'start''end'Which side the trigger sits on: the pills open over the space to its left (end) or right (start). Nothing around it moves.
labelsobject—Replaces built-in text: confirm, cancel, done, working, group. Shallow-merged over the English defaults.
disabledbooleanfalseDisables the trigger.
...restHTMLAttributes—Other attributes go to the root <span>.

Accessibility

  • The trigger is a <button> with aria-expanded and aria-controls; opening moves focus to Cancel, and folding back returns it to the trigger.
  • The pills are real buttons in a group named by labels.group; Tab reaches both, Escape folds back.
  • While closed the tray is hidden and its buttons leave the tab order.
  • Working and done are announced through a polite live region; the action pill has aria-busy while working.
  • The countdown pauses while the pointer or keyboard focus is inside, so nobody loses the choice while deciding.
  • Reduced motion makes the pills appear in place with a short fade, without travel, blur, drain or shake.

Motion

Open: transform 460ms with a light overshoot, clip-path 380ms ease-out, the far pill 40ms later; labels fade and sharpen over 240–360ms after 110ms; the icon shrinks out. Close: 160ms ease-in. Done: the check draws in 360ms and the pair folds after 900ms. Failure: a 420ms decaying shake.

Add it to your project

Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the component next to your own.

TwoStepButton.jsxtwo-step-button.csstokens.cssREADME.md

Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.

Buttons
Aurora rim button comes with Pro. Its preview shows once you unlock it.
Bite button comes with Pro. Its preview shows once you unlock it.