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.
- 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.
- 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
pulseprop for it: change its value and the glass answers once (pulseHoldsets how long it stays swollen), and content withscale: var(--glass-bend, 1)follows it. - v1.6.9ImprovedThe glass also swells once, as it does under the pointer, when the droplet melts in and when it splits off again.
- 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.
- 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.
- 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.
- 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.jsonNo dependenciesOr copy the files by hand →
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
pendingLabeland a spinner turns where the arrow was, until the promise fromonActionsettles. - Success. Still one body:
successLabeland 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 setresetAfter. - Error. If
onActionthrows, the droplet splits off again andonActionErrorgets the error. - Start over. Change
resetKeyand the droplet splits off again from any state. Don't remount the button withkey: that snaps it back.
API reference
| Prop | Type | Default |
|---|---|---|
childrenThe idle label, and the button's accessible name. | ReactNode | — |
onActionRequired. Runs on press; return a promise to stay pending until it settles. | () => unknown | — |
onActionErrorCalled when | (error) => void | — |
pendingLabelLabel while | ReactNode | children |
successLabelLabel after it succeeds. | ReactNode | children |
resetAfterMilliseconds before splitting off again after a success. | number | 0 |
resetKeyChange it to return to idle: the droplet splits off again. A running action's result is dropped. | unknown | — |
iconThe droplet's idle icon. | ReactNode | arrow |
materialAs on GlassButton. | 'clear' | 'tinted' | 'clear' |
sizeHeight 32, 40 or 48 px. | 'sm' | 'md' | 'lg' | 'md' |
…restPassed to the | button attributes | — |
Accessibility
- A real
<button>; Enter and Space run the action. - Pending sets
aria-busy, and pending or done setsaria-disabledinstead ofdisabled, 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.