$npx @dinachi/cli@latest add hold-to-confirm
variantdurationresetAfterconfirmedLabeldisableddata-agent-confirmdelete-project.tsx
import { HoldToConfirm } from "@/components/ui/hold-to-confirm"
export function DeleteProject({ onDelete }: { onDelete: () => void }) {
return (
<HoldToConfirm
confirmedLabel="Deleted"
onConfirm={onDelete}
>
Hold to delete
</HoldToConfirm>
)
}Usage
import { HoldToConfirm } from "@/components/ui/hold-to-confirm"
export function DeleteProject() {
return (
<HoldToConfirm onConfirm={() => deleteProject()} confirmedLabel="Deleted">
Hold to delete
</HoldToConfirm>
)
}Examples
A bar sweeps behind the label.
import { HoldToConfirm } from '@/components/ui/hold-to-confirm';
export function Example() {
return (
<HoldToConfirm onConfirm={deleteProject} confirmedLabel="Deleted">
Hold to delete
</HoldToConfirm>
);
}Fill, ring, or the button's own border.
import { Trash2 } from 'lucide-react';
import { HoldToConfirm } from '@/components/ui/hold-to-confirm';
export function Example() {
return (
<>
<HoldToConfirm>Fill</HoldToConfirm>
<HoldToConfirm variant="border">Border</HoldToConfirm>
{/* Icon-only, so the name has to come from somewhere other than the label. */}
<HoldToConfirm variant="ring" aria-label="Hold to delete project">
<Trash2 className="h-4 w-4" />
</HoldToConfirm>
</>
);
}
Duration, and whether the confirmed state returns.
import { HoldToConfirm } from '@/components/ui/hold-to-confirm';
export function Example() {
return (
<>
<HoldToConfirm duration={800} confirmedLabel="Revoked" onConfirm={revokeKey}>
Hold briefly
</HoldToConfirm>
{/* The row is about to disappear, so there is nothing to return to. */}
<HoldToConfirm resetAfter={0} confirmedLabel="Deleted" onConfirm={deleteProject}>
Stays confirmed
</HoldToConfirm>
</>
);
}Notes
Motion tier
Needs motion. add --all skips it; install with add --motion or by name.
Variants
fill(default): a bar sweeps from the left behind the label.ring: a stroke closes around the button. For square icon-only buttons.border: the button's outline draws itself. For dense UI.
When to use it
- Actions with no undo: deleting a project, revoking a key, ending a session.
- Skip it for repeated actions; each use costs the full hold.
- Skip it for reversible actions; offer undo instead.
Timing
- Progress fills over
durationand unwinds in 200ms. - Pressing again mid-unwind resumes from the current progress.
- The hold survives a small drag off the button.
State attributes
data-holding is set while held, data-confirmed once confirmed. Style on these instead of :active.
API
onConfirm
Runs when the hold completes or an agent presses. agent
(details) => voiddetails.cancel() unwinds instead.variant"fill" | "ring" | "border" = "fill"
How progress is drawn. See Variants.durationnumber = 1600
Milliseconds the press must be held.resetAfternumber = 1600
Milliseconds the confirmed state lasts. 0 stays confirmed.confirmedLabelReactNode
Replaces the label while confirmed; announced.holdHintstring = "Press and hold to confirm"
The description assistive tech reads.fillClassNamestring
Class for the progress fill or stroke.disabled
Blocks people and agents.agent
boolean = falserenderReactElement | (props, state) => ReactElement
Swap the element, keep the behaviour.Agent
Inside an AgentProvider, it appears in agent.snapshot() as button.
Reads
labelThe button's text, or its aria-label.
disabledTrue when the button is disabled.
confirmSet by default: a person approves each press.
Actions
press()Completes the hold at once and runs onConfirm. Fails if already confirmed.
A press needs a person's approval by default: the step fails unless the agent's allow grants it, or data-agent-confirm="none" lifts it. The press runs through onConfirm, where isAgentChange(details) is true and details.cancel() refuses it; the agent is told the app refused. A disabled button refuses on its own.
await agent.act({
steps: [{ ref: "Hold to delete", action: "press" }],
})Accessibility
- A native button. With a non-button
render, disabled becomes aria-disabled. holdHintis linked through aria-describedby.confirmedLabelis announced from a polite live region beside the button.- Key repeat is ignored, so a held key is one hold.
- Give a
ringbutton an aria-label. - Reduced motion drops the press scale and keeps the progress.
Keyboard
SpaceEnterHold to fill the progress. Releasing the key cancels
TabMoving focus away cancels the hold
SpaceEnterHold to fill the progress. Releasing the key cancels
TabMoving focus away cancels the hold