Skip to content

Components

Slide to Confirm Updated

A slide-to-confirm track. Drag its glass thumb to the end to run one deliberate action; let go early and it springs back.

Latest change Improved v3.0.18 The thumb is lit as the slide ends in success: where it swells with the check it takes the light of a press, and on a white thumb, which cannot get brighter, the light spills around it.
  1. v3.0.18 Improved The thumb is lit as the slide ends in success: where it swells with the check it takes the light of a press, and on a white thumb, which cannot get brighter, the light spills around it.
  2. v3.0.13 Improved While the thumb moves, the glass sends the GPU only the part of the track's picture it can read: what lies under the thumb, as far as it bends and blurs it. Until now the whole picture went up on every frame. On the landing page's slide, pulled on a phone slowed six times, the picture sent during a pull went from about 212 MB to about 82 MB, in as many uploads. Nothing on the screen changes, frame by frame, and every other glass is drawn as before: the engine does this only for glass that asks for it, as the slide now does.
  3. v3.0.10 Improved While the clear thumb moves over a shimmering label, the glass takes one picture of the track a frame where it took two. The band of light is painted into that picture by hand, cut from a picture of the lit label, and that picture of the lit label was taken again on every frame, though the lit label never changes: only the band moves over it. It is now taken once and kept, and taken again only when the label's size, text, colour or font, the page's language or the theme changes, or a font loads. On the landing page's slide, pulled on a phone slowed six times, the pictures taken during a pull went from about 185 to about 110. Nothing on the screen changes, frame by frame.
  4. v3.0.9 Improved A flick confirms: let go past halfway while the thumb still moves forward at 0.6 px per ms or more, and it confirms as if dragged to the end. A second finger no longer grabs the thumb, and lifting it no longer ends the drag.
  5. v3.0.3 Fixed A thumb carried to the end of the track now confirms there, without waiting for the finger to lift. On some devices a touch that reached the end never sent its release, and the slide, this site's landing page among them, stayed at the end unconfirmed. Letting go past threshold confirms as before. The track no longer stretches past its end under a finger.
  6. v2.4.6 Improved The label of the slide is now dim, and a band of light crosses it from left to right every two seconds (motion-primitives' Text Shimmer at its defaults: light grey to black on a light page, grey to white on a dark one). It shimmers at rest and goes on while the thumb is dragged: the clear glass bends the band with the label it passes, and the fill covers both behind the thumb, where the label is written on it as before. It stops once the track has drawn in around the thumb, and does not run on an error, on a disabled slide, while the slide is out of view, or with reduced motion (the label is then plain, as it was). The reference moves a gradient clipped to the text, which a browser paints again on every frame; here the lit label lies under a mask shaped like the band, and the two move against each other, so only two transforms are animated, which a browser can run without painting anything again. The glass's picture of the track cannot see a mask, so the band is painted into it by hand, and that picture is taken on every frame while the glass is held clear over the label. No new dependency. shimmer={false} leaves the label plain.
  7. All changes→
glass-slide-to-confirm-mirror.svelte

Time to wake up

Use it for

  • A routine action a stray tap must not trigger: send money, pay, unlock, start a shift.
  • Phone-first surfaces, where a deliberate horizontal gesture replaces a confirm dialog.

Not for

  • Easily undone actions: use GlassButton.
  • An async action a single press may start: use GlassActionButton.
  • Consequences people must read first: use a dialog.

Installation

npx shadcn-svelte@latest add https://liquidglass.pulse.city/r/slide-to-confirm.json

Usage

app.tsx
import { GlassSlideToConfirm } from '@/components/liquid-glass'

<GlassSlideToConfirm
  pendingLabel="Sending"
  successLabel="Sent"
  errorLabel="Not sent, slide to retry"
  onConfirm={send} // return the promise
>
  Slide to send $240
</GlassSlideToConfirm>

The flow

  • Idle. The thumb rests at the start as frosted white glass; the instruction is written in the track, dim, and a band of light keeps crossing it (shimmer).
  • Drag. The thumb turns to clear glass and bends the fill and the label it passes; its chevron stays in place, in the fill's text colour. It stays round while held, and speed stretches it along its travel. The fill trails a moment behind, joined to the thumb by a bridge that thins as they pull apart, and the track and the fill swell around the thumb like a membrane. Pushed against the start the wall gives a little, and the thumb stays round there.
  • Let go early. Below threshold the thumb springs back; the fill's tail follows and is absorbed after it.
  • The end. A thumb carried to the end confirms there, without waiting for the finger to lift.
  • Pending. Past the threshold the thumb lands at the end, the track draws in to a ring around it and pendingLabel appears beside it while a spinner takes the chevron's place, until the promise from onConfirm settles.
  • Success. The white glass takes the fill's colour and the chevron's stroke bends into a check, beside successLabel; the thumb swells and settles as the check appears. It stays confirmed, unless you set resetAfter: then the track opens first, successLabel leaving with its edge, and the thumb flies home after it, squashing a little as it lands against the start.
  • Error. If onConfirm throws, the track opens again, the thumb returns and errorLabel replaces the instruction until the next slide.

Examples

A fill, and an action that takes a moment
glass-slide-to-confirm-compact.svelte

fill={false} leaves the track bare: the thumb pulls no fill behind it and bends the label alone, its icon dark on a light page and white on a dark one; fillClassName then colours only the success. mirror lets the held thumb's rim mirror the page around the track, so a colourful neighbour (the orange button in the preview at the top of this page) lights the rim that faces it, and the icon inside glows. Both are off unless you ask: the thumb mirrors only while it is clear, never at rest.

Colour the fill with fillClassName: its bg-* is the fill, its text-* is the label written on it, and the thumb's icon while the glass is clear. At rest the thumb is always frosted white glass with a dark icon (a flat white disc without WebGL2). The control fills its container, so set the width on a parent or with className.

API reference

PropTypeDefault
children

The instruction in the track, and the slider's accessible name.

string—
onConfirm

Required. Runs once the thumb reaches the end; return a promise to stay pending until it settles.

() => unknown—
onConfirmError

Called when onConfirm throws; the thumb springs back.

(error) => void—
pendingLabel

Written beside the spinner while onConfirm runs.

string—
successLabel

Written beside the check after it succeeds.

string—
errorLabel

Replaces the instruction after a failure, until the next slide.

string—
threshold

Share of the track the thumb must pass before letting go confirms. The end itself confirms without letting go.

number0.9
resetAfter

Milliseconds after a success before the track opens again. 0 stays confirmed.

number0
hint

Nudges the thumb every few seconds until it has been touched. Off with reduced motion.

booleantrue
shimmer

The label is dim and a band of light crosses it, at rest and while the thumb is dragged. false leaves the label plain. Off with reduced motion.

booleantrue
icon

The thumb's idle icon.

ReactNodechevron
size

Track height 40, 48, 56 or 96 px.

'sm' | 'md' | 'lg' | 'xl''md'
fillClassName

Classes of the fill: its colour and the colour of the text on it.

string'bg-[#3291FF] text-white'
fill

false leaves the track bare: no fill behind the thumb; fillClassName colours the success alone.

booleantrue
mirror

The held thumb's rim mirrors the page around the track: a colourful neighbour lights the rim that faces it, and the icon glows.

booleanfalse
disabled

Dims the control and ignores pointer and keyboard.

booleanfalse
className

Width and position of the track.

string—

Accessibility

  • A real role="slider" named by its label, with aria-valuenow kept in step with the thumb.
  • Arrow keys move the thumb in tenths, Page Up and Page Down in quarters, Home returns it and End confirms. Holding Space or Enter glides it to the end; letting go early springs it back.
  • A role="status" region announces the pending, success and error labels. While pending or confirmed the slider is aria-disabled.
  • Success is never colour alone: the chevron becomes a check and the label is written beside it.
  • Vertical page scroll still works over the control on touch. With reduced motion each state shows at once.

Liquid Glass Svelte is open source and MIT licensed. If it saves you time, you can support the project.