Skip to content

Components

Action Button

A button for one async action. Its arrow floats apart as a glass droplet; press it and the droplet melts into the body, and stays.

Latest changeFixedv1.6.10With the pointer on the button, its end was cut off in a straight line for a few frames just after the droplet melted in: the swell that greets the merge pushed the droplet, not yet fully in, past the edge of the glass's canvas. The swell now waits until the two are one body, and the canvas makes room whenever the glass swells past it.
  1. v1.6.10FixedWith the pointer on the button, its end was cut off in a straight line for a few frames just after the droplet melted in: the swell that greets the merge pushed the droplet, not yet fully in, past the edge of the glass's canvas. The swell now waits until the two are one body, and the canvas makes room whenever the glass swells past it.
  2. v1.6.9ImprovedThe moment the action succeeds, the glass swells as it does under a hover and a press together. It stays swollen until the new label and the check are in, waits a moment, then settles. The label and the check stretch with it as it swells, a little more in height than in width, and are even again while it waits. GlassLayer has a new pulse prop for it: change its value and the glass answers once (pulseHold sets how long it stays swollen), and content with scale: var(--glass-bend, 1) follows it.
  3. v1.6.9ImprovedThe glass also swells once, as it does under the pointer, when the droplet melts in and when it splits off again.
  4. v1.6.9ImprovedMerged, the spinner and the check sit by the label as an icon in a button does: close after the text, with a little less room on their side than on the label's (20 px to 24 px on the large size). The merged button is narrower for it.
  5. v1.6.9FixedAs the droplet melts in, the button's end no longer grows taller than the rest for a moment and shrinks back: the bridge now only fills the dip between the droplet and the body.
  6. v1.6.9FixedThe blur of a label changing letter by letter is no longer cut off in a box around the text: it has room on every side and fades out softly.
  7. All changes →
glass-action-button-basic.tsx

Use it for

  • One async commit whose result belongs on the button: Deploy, Publish, Add to cart, Subscribe.
  • Actions that stay done: the merged "Deployed ✓" is the new state of the page.

Not for

  • Plain links and instant actions: use GlassButton.
  • Toggling back and forth between two states: use GlassTabs.
  • More than one per screen: the droplet is the kit's one gooey effect, keep it special.

Installation

npx shadcn@latest add https://onemorethink.dev/r/action-button.json

Usage

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

<GlassActionButton
  material="tinted"
  className="bg-neutral-900 text-white"
  pendingLabel="Deploying"
  successLabel="Deployed"
  onAction={deploy} // return the promise
>
  Deploy
</GlassActionButton>

The flow

  • Idle. The arrow floats apart from the body as a separate glass droplet.
  • Press. The droplet stretches back on a gooey bridge and melts into the body.
  • Pending. One body; the label morphs to pendingLabel and a spinner turns where the arrow was, until the promise from onAction settles.
  • Success. Still one body: successLabel and a check that draws itself in. As it lands the glass swells, as if hovered and pressed at the same time, and stretches the label and the check with it; it lets go a moment after the label is in. It stays merged, unless you set resetAfter.
  • Error. If onAction throws, the droplet splits off again and onActionError gets the error.
  • Start over. Change resetKey and the droplet splits off again from any state. Don't remount the button with key: that snaps it back.

API reference

PropTypeDefault
children

The idle label, and the button's accessible name.

ReactNode—
onAction

Required. Runs on press; return a promise to stay pending until it settles.

() => unknown—
onActionError

Called when onAction throws; the button returns to idle.

(error) => void—
pendingLabel

Label while onAction runs.

ReactNodechildren
successLabel

Label after it succeeds.

ReactNodechildren
resetAfter

Milliseconds before splitting off again after a success. 0 stays merged.

number0
resetKey

Change it to return to idle: the droplet splits off again. A running action's result is dropped.

unknown—
icon

The droplet's idle icon.

ReactNodearrow
material

As on GlassButton.

'clear' | 'tinted''clear'
size

Height 32, 40 or 48 px.

'sm' | 'md' | 'lg''md'
…rest

Passed to the <button> (not onClick: use onAction).

button attributes—

Accessibility

  • A real <button>; Enter and Space run the action.
  • Pending sets aria-busy, and pending or done sets aria-disabled instead of disabled, so focus stays on the button.
  • A role="status" region announces the pending and success labels.
  • With reduced motion the droplet and labels switch without animation.