Skip to content
h v3.13.3
Search the docs
Find a component, section or page.

Hold to confirm

Press and hold to confirm a destructive action.

Installation

pnpm add @heyramzi/ui

Usage

import { HoldToConfirm } from "@heyramzi/ui/components/hold-to-confirm";
<HoldToConfirm onConfirm={() => (deleted = true)}>
  {#snippet idle()}Hold to delete{/snippet}
  {#snippet holding()}Keep holding{/snippet}
</HoldToConfirm>

Keyboard and accessibility

Key Does
Space Enter Hold to fill the button. It confirms when the fill reaches the end, 800 ms by default.
  • Letting go early, or focus leaving the button, cancels and empties the fill.
  • Nothing announces the fill, so write the label as the instruction, like "Hold to delete".
  • A screen reader's activate can't hold. Its first press arms the button and reads out "Press again to confirm". A second press within 5 seconds confirms.
  • With reduced motion on, the fill tracks the hold with no easing or sheen.

API reference

duration number
Default 800
onConfirm required () => void
disabled boolean
Default false
variant "default" | "outline" | "ghost" | "destructive" | "text" | "dashed"
Default "destructive"
Uses the button recipe so call sites stop drawing their own. `variant: null` opts out, for a caller that really is a menu row.
size "sm" | "default" | "lg"
Default "default"
icon boolean
Default false
Square, for a glyph with no label. Mirrors `Button`.
class string
Default ""
idle required Snippet
holding required Snippet
confirmPrompt string
Default "Press again to confirm"
Read out when a screen reader's activate arms the button. Translate at the call site.
...rest
Every prop of HTMLButtonAttributes from svelte/elements except class
Prop Type Default
duration number 800
onConfirm required () => void
disabled boolean false
variant

Uses the button recipe so call sites stop drawing their own. `variant: null` opts out, for a caller that really is a menu row.

"default" | "outline" | "ghost" | "destructive" | "text" | "dashed" "destructive"
size "sm" | "default" | "lg" "default"
icon

Square, for a glyph with no label. Mirrors `Button`.

boolean false
class string ""
idle required Snippet
holding required Snippet
confirmPrompt

Read out when a screen reader's activate arms the button. Translate at the call site.

string "Press again to confirm"
...rest Every prop of HTMLButtonAttributes from svelte/elements except class