DialogUpdated
A pane of glass that rises over the whole page: the page dims and waits, the pane comes up in the middle of the screen in Card's frosted glass, a little past its size, then settled, and keeps the focus until it is closed.
Latest changeFixedv3.0.9The pane leaves on a strong ease-out instead of an ease-in, so it answers the close at once; still 150 ms.
- v3.0.9FixedThe pane leaves on a strong ease-out instead of an ease-in, so it answers the close at once; still 150 ms.
- v2.2.2ImprovedDialog can be an alert dialog.
alertonGlassDialogis for a question that must be answered: a press outside does not close it, focus starts on the first Close part, and screen readers hear analertdialog.createConfirm()asks it from code,if (await ask()) remove(), andvariant="destructive"on a Close part paints the answer that deletes red. The pane and its glass are the same. - v2.2.1ImprovedEverything that opens over the page wears one glass, tuned over a page of text: Dialog's pane, the list of a Select, a Dropdown Menu, a Popover, and a Menu with its submenus. A 10 px frost in place of 5 lets the lines behind sit back, so what is on the surface reads; 11% of the sharp page still shows through it. The tint is 60%, white on a light page and black on a dark one, what shows through is 1.5 times as vivid, and the bend stays close to the edge. The line at the edge is 0.3 px: black at 8% on light glass, white at 79% on dark. The controls these surfaces open from keep Button's glass, and
tint,blurandopticsonGlassDialogContentstill set your own. - v2.2.0NewDialog: a pane of glass that rises over the whole page. The page dims and waits; the pane comes up in the middle of the screen in Card's frosted glass, a little past its size, then settled, and sinks back faster than it came. It comes with a title, a description, a footer and Close parts, forms that close it once they are valid (
method="dialog"),inlineto keep it inside a frame, and a controller to open it from a menu item or from code. The inert page, the focus trap, Escape, the outside press and ARIA come from UI SDK. - All changes →
Use it for
- A task the rest of the page should wait for: renaming something, a short form, a choice that needs a sentence of context.
- Something that can be opened from anywhere: a menu item, a keyboard shortcut, your own code. It belongs to the page, not to one button.
Not for
- A little more about one control: use Popover, which comes out of its button and leaves the page usable.
- A list of actions: use Menu or Dropdown Menu. Picking a value: use Select.
- News that asks nothing of the visitor (saved, copied): do not take the page away for it.
Installation
npx shadcn@latest add https://liquidglass.onemorethink.dev/r/dialog.jsonThe behaviour (the top layer, the inert page, the focus trap, Escape, the outside press, forms, ARIA) comes from UI SDK, so Dialog needs @ui-sdk/core and @ui-sdk/react. The install command adds them at the exact version this was built on: UI SDK is in beta and its API may still change.
Usage
import {
GlassDialog,
GlassDialogClose,
GlassDialogContent,
GlassDialogDescription,
GlassDialogFooter,
GlassDialogTitle,
GlassDialogTrigger,
} from '@/components/liquid-glass/glass-dialog'
<GlassDialog>
<GlassDialogTrigger>Archive</GlassDialogTrigger>
<GlassDialogContent>
<GlassDialogTitle>Archive this board?</GlassDialogTitle>
<GlassDialogDescription>It leaves the sidebar. You can bring it back from Settings.</GlassDialogDescription>
<GlassDialogFooter>
<GlassDialogClose>Cancel</GlassDialogClose>
<GlassDialogClose variant="solid" onClick={archive}>Archive</GlassDialogClose>
</GlassDialogFooter>
</GlassDialogContent>
</GlassDialog>The page dims and stops answering, and the pane comes up in the middle of the screen: it fades up as it grows from a little under its size, lands a little past it and settles. It wears the glass of every surface that opens over the page (a Popover, a Menu, the list of a Select), tuned so that what is on the pane reads over a page of text: a 60% tint (white, or black on a dark page), a 10 px frost in place of Card's 3, and a rim that bends the page it covers, close to the edge. It takes Card's tint, blur and optics, and its text follows the tone of the glass. It only fades and grows about its own middle and never slides, so the page the glass shows is the page behind it at every moment. Closing is quicker than opening: the pane sinks a little and goes, and the dim lifts with it. A press on a Close part lights the pane where it lands. The trigger is a GlassButton and takes its props (material, size, icon); asChild puts it on an element of your own.
Forms
Put a <form method="dialog"> in the pane and give the main action type="submit": the form closes the dialog when it is submitted, and only once it is valid, so Enter in a field saves. The submit button's value comes back as details.returnValue in onOpenChange. Focus starts in the first field with its text selected; initialFocus on the content picks another place. The example at the top of the page is such a form.
<GlassDialogContent>
<GlassDialogTitle>Rename board</GlassDialogTitle>
<form method="dialog" onSubmit={(event) => rename(new FormData(event.currentTarget))}>
<input name="name" required defaultValue={name} />
<GlassDialogFooter>
<GlassDialogClose>Cancel</GlassDialogClose>
<GlassDialogClose type="submit" variant="solid">Save</GlassDialogClose>
</GlassDialogFooter>
</form>
</GlassDialogContent>Opening it yourself
A dialog does not need a trigger. Control it with open and onOpenChange, or create a controller and open it from anywhere: a menu item, a row of a table, your own code. controller.open() returns a Promise that resolves when the dialog closes, with the reason and the returnValue. Focus goes back to wherever it was before the dialog opened.
import { createDialogController, GlassDialog, GlassDialogContent } from '@/components/liquid-glass/glass-dialog'
const [rename] = useState(() => createDialogController())
<GlassMenu>
<GlassMenuTrigger aria-label="More" className="w-12 px-0"><Ellipsis /></GlassMenuTrigger>
<GlassMenuContent>
<GlassMenuItem onSelect={() => rename.open()}>Rename…</GlassMenuItem>
</GlassMenuContent>
</GlassMenu>
<GlassDialog controller={rename}>
<GlassDialogContent>…</GlassDialogContent>
</GlassDialog>A question that must be answered
alert on GlassDialog makes it an alert dialog, for a question the visitor has to answer before anything happens: deleting something, leaving unsaved work. It is the same pane in the same glass. What changes is how it is left: a press outside does not close it, focus starts on the first Close part, so put the answer that loses nothing first, and screen readers hear it as an alertdialog. Escape still closes it, as that first answer would. variant="destructive" paints the Close part that deletes red.
To ask from code, create the question once with createConfirm(), give its controller to the dialog and value="confirm" to the Close part that agrees. Calling it opens the dialog and returns a Promise of the answer: true for that part, false for every other way out. Questions asked while one is open wait their turn.
import { createConfirm, GlassDialog, GlassDialogClose, GlassDialogContent, GlassDialogFooter, GlassDialogTitle } from '@/components/liquid-glass/glass-dialog'
const [ask] = useState(() => createConfirm())
async function remove() {
if (await ask()) await deleteBoard()
}
<GlassDialog alert controller={ask.controller}>
<GlassDialogContent>
<GlassDialogTitle>Delete this board?</GlassDialogTitle>
<GlassDialogFooter>
<GlassDialogClose>Cancel</GlassDialogClose>
<GlassDialogClose variant="destructive" value="confirm">Delete</GlassDialogClose>
</GlassDialogFooter>
</GlassDialogContent>
</GlassDialog>Inside a frame
inline on GlassDialogContent keeps the pane and its dim inside the positioned box around the dialog instead of over the page: an app preview, a panel, a card. Pair it with modal="trap-focus", which keeps Tab inside the pane and leaves the page around the frame usable.
Long content
The pane is never a scroll box itself: the glass is drawn a little past its edge, and a scroll box would cut it. It is a column no taller than the screen, so give the part that should scroll min-h-0 overflow-y-auto and keep the title and the actions outside it.
API reference
| Prop | Type | Default |
|---|---|---|
open / defaultOpen / onOpenChangeOn | boolean / boolean / (open: boolean, details) => void | — |
alertAn alert dialog: always modal, a press outside does not close it, focus starts on the first Close part, and its role is | boolean | false |
modal
| boolean | 'trap-focus' | true |
dismissibleWhether Escape and a press outside close it. | boolean | true |
controllerFrom | DialogController | — |
GlassDialogTrigger material / size / icon / iconPosition / tint / pullThe trigger is a GlassButton: clear glass, | GlassButton props | — |
GlassDialogTrigger asChildPut the trigger on its single child (your own button, a | boolean | false |
GlassDialogTrigger shortcutKeys that open it, as | string | — |
GlassDialogContent dimHow dark the page goes behind the pane, 0–1. | number | 0.3 |
GlassDialogContent tint / blur / opticsThe pane's glass, as on Card: how much tint covers the page, how much it is frosted (px), and the fine-tuning. | number / number / GlassOptics | 0.6 / 10.25 |
GlassDialogContent inlineKeep the pane and its dim inside the positioned box around the dialog instead of over the page. | boolean | false |
GlassDialogContent initialFocus / finalFocusWhere focus goes as it opens (default: the first focusable element) and after it closes (default: where it was). | string | Element | () => Element | — |
GlassDialogContent classNameClasses for the pane: | string | — |
GlassDialogTitle / GlassDialogDescriptionName the dialog and say what it is for. | className | — |
GlassDialogFooterThe row of actions: side by side from the right, stacked on a phone. | className | — |
GlassDialogClose variantA soft button in the pane's own tone, the main action, or the main action in red when it deletes. It closes the dialog; | 'quiet' | 'solid' | 'destructive' | 'quiet' |
GlassDialogClose type / value / action
| 'submit' / string / () => unknown | — |
Accessibility
- A modal
dialog(analertdialogwithalert) named by its title and described by its description: always give it aGlassDialogTitle. - Focus moves into the pane as it opens and Tab stays inside it; the rest of the page is inert and does not scroll.
- Escape, a press outside and every Close part close it, and focus returns to the trigger, or to where it was. An alert dialog is not closed by a press outside.
- An icon-only trigger or Close part needs an
aria-label. - With reduced motion the pane only fades. Without WebGL2 it is a plain frosted panel.
Liquid Glass is built and maintained by one person. If it saves you time, you can sponsor the work.