Skip to content

Components

Dialog Updated

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 change Improved v3.1.1 The inside of the pane follows the Alerts page of Apple's Human Interface Guidelines, measured on its drawings: the title and the message 22 px in from the edge, the buttons 14 px, as 48 px capsules that share the row in one width with the main action trailing, and corners of 38 px that run with the buttons' own. Three answers, or two whose words need more than half the row, stack with the main action on top and Cancel at the bottom (stack on the footer decides it yourself). The main action is Apple's blue, and destructive is now Apple's red in words on the soft button, for an answer that destroys what the visitor did not set out to destroy. An alert is narrower (20rem), GlassDialogIcon puts an icon over the title, and Command-Period closes the pane as Escape does. The trash example now confirms with the main action and offers "Don't ask again", and a new example asks with three answers.
  1. v3.1.1 Improved The inside of the pane follows the Alerts page of Apple's Human Interface Guidelines, measured on its drawings: the title and the message 22 px in from the edge, the buttons 14 px, as 48 px capsules that share the row in one width with the main action trailing, and corners of 38 px that run with the buttons' own. Three answers, or two whose words need more than half the row, stack with the main action on top and Cancel at the bottom (stack on the footer decides it yourself). The main action is Apple's blue, and destructive is now Apple's red in words on the soft button, for an answer that destroys what the visitor did not set out to destroy. An alert is narrower (20rem), GlassDialogIcon puts an icon over the title, and Command-Period closes the pane as Escape does. The trash example now confirms with the main action and offers "Don't ask again", and a new example asks with three answers.
  2. v3.0.9 Fixed The pane leaves on a strong ease-out instead of an ease-in, so it answers the close at once; still 150 ms.
  3. v2.2.2 Improved Dialog can be an alert dialog. alert on GlassDialog is 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 an alertdialog. createConfirm() asks it from code, if (await ask()) remove(), and variant="destructive" on a Close part paints the answer that deletes red. The pane and its glass are the same.
  4. v2.2.1 Improved Everything 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, blur and optics on GlassDialogContent still set your own.
  5. v2.2.0 New Dialog: 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"), inline to 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.
  6. All changes→
glass-dialog-basic.svelte

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.
  • Asking before something common that can be undone (moving a file to the trash), or anything as the page loads: ask only before what cannot be taken back.

Installation

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

The 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

app.tsx
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.

Inside the pane

The pane is laid out as Apple lays out an alert in its Human Interface Guidelines. The title and the message lead, 22 px in from the edge; the buttons sit closer to it, 14 px, as capsules a finger can find (48 px). One or two buttons share the row in one width, the main action trailing; three, or two whose words do not fit side by side, stack, the main action on top and Cancel at the bottom. Write them in the order of a row, Cancel first: the footer turns them over when it stacks (stack stacks them always). The pane's corners are the buttons' corners grown by the space around them (14 + 24 = 38 px), so the two curves run together. An alert is narrower than a dialog: 20rem, the width of an alert on a phone, where a dialog keeps 28rem for a form. GlassDialogIcon puts an icon over the title, as a Mac shows the app's icon in an alert. The main action is Apple's blue and a destructive answer Apple's red, each with its dark-mode value. Command-Period closes the pane, as Escape does.

  • The title says what happened, in two lines at most, never just "Error". A whole sentence ends in its mark ("Empty the trash?"); a fragment takes a capital on each word and no mark ("Rename Board").
  • The message is there only when it adds something: short, in whole sentences. It does not explain the buttons; their words should.
  • Three answers at most, each a verb or two for what it does ("Empty Trash", "Save"), never "Yes" or "No", and "OK" only when the pane only informs. The way out is always called "Cancel", and it is never the main action.
  • variant="destructive" is for an answer that destroys what the visitor did not set out to destroy ("Don't Save" when they only closed a draft). When they chose it (Empty Trash), the answer that confirms it is the main action, solid, and Cancel is always there beside a destructive one.
  • An alert that comes back every time can offer to stop asking: a checkbox ("Don't ask again") above the buttons.
Three answers, stacked
glass-dialog-stack.svelte

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.

rename.tsx
<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.

from-a-menu.tsx
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" writes the Close part that destroys something in red.

Empty the trash?
glass-dialog-alert.svelte

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.

delete.tsx
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.

An album in its own frame
glass-dialog-inline.svelte

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

PropTypeDefault
open / defaultOpen / onOpenChange

On GlassDialog: control the dialog yourself, or let it keep its own state. details.reason says why it changed and details.returnValue what closed it.

boolean / boolean / (open: boolean, details) => void—
alert

An alert dialog: always modal, a press outside does not close it, focus starts on the first Close part, and its role is alertdialog. Its controller comes from createAlertDialogController() or createConfirm().

booleanfalse
modal

true: the page is inert and does not scroll. trap-focus: Tab stays in the pane, the page still scrolls and takes presses. false: a pane beside the page, with no dim.

boolean | 'trap-focus'true
dismissible

Whether Escape and a press outside close it. false while a form has unsaved changes; onDismissAttempt then tells you someone tried.

booleantrue
controller

From createDialogController(): opens and closes the dialog from anywhere, and connects triggers outside it.

DialogController—
GlassDialogTrigger material / size / icon / iconPosition / tint / pull

The trigger is a GlassButton: clear glass, md, by default.

GlassButton props—
GlassDialogTrigger asChild

Put the trigger on its single child (your own button, a GlassButtonGroupItem) instead of a GlassButton.

booleanfalse
GlassDialogTrigger shortcut

Keys that open it, as mod+k (Command on Apple platforms, Control elsewhere).

string—
GlassDialogContent dim

How dark the page goes behind the pane, 0–1. 0 leaves it as it is.

number0.3
GlassDialogContent tint / blur / optics

The pane's glass, as on Card: how much tint covers the page, how much it is frosted (px), and the fine-tuning.

number / number / GlassOptics0.6 / 10.25
GlassDialogContent inline

Keep the pane and its dim inside the positioned box around the dialog instead of over the page.

booleanfalse
GlassDialogContent initialFocus / finalFocus

Where focus goes as it opens (default: the first focusable element) and after it closes (default: where it was).

string | Element | () => Element—
GlassDialogContent className

Classes for the pane: w-[min(28rem,calc(100%-2rem))] (20rem for an alert), rounded-[38px], px-[22px] pt-[23px] pb-3.5, gap-4 by default.

string—
GlassDialogIcon

An icon over the title, at its leading edge: your app's mark or a symbol of what the pane is about.

className—
GlassDialogTitle / GlassDialogDescription

Name the dialog and say what it is for.

className—
GlassDialogFooter stack

The answers, written Cancel first. One or two share the row in one width; three, or two that do not fit, stack with the main action on top. true stacks them always, false keeps three in a row.

boolean—
GlassDialogClose variant

A soft button in the pane's own tone (Cancel and every other answer), the main action in Apple's blue (systemBlue), or Apple's red (systemRed) in words on the soft button for an answer that destroys what the visitor did not set out to destroy. It closes the dialog; onClick runs as it does.

'quiet' | 'solid' | 'destructive''quiet'
GlassDialogClose type / value / action

type="submit" submits the <form method="dialog"> around it. value is reported as the returnValue. An action that returns a Promise keeps the dialog open, and the button pending, until it settles.

'submit' / string / () => unknown—

Accessibility

  • A modal dialog (an alertdialog with alert) named by its title and described by its description: always give it a GlassDialogTitle.
  • 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 Svelte is open source and MIT licensed. If it saves you time, you can support the project.