Skip to content
Slotted

Dialog

A window over the page that holds one task, such as an edit, a form or a confirmation, and keeps the reader in it until the task is done or dismissed.

ap@northwindtraders.com

Installation

The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.

bash
pnpm add @slotted/react @slotted/theme @slotted/themes
tsx
import { Dialog, DialogBody, DialogClose, DialogContent,  DialogDefaultsProvider, DialogDescription, DialogFooter, DialogHeader,  DialogTitle, DialogTrigger } from '@slotted/react';

Sizes

size sets the panel’s maximum width to one of five steps: sm (32rem) for one field or one question, md (the default: the form measure, 40rem, plus the panel’s inline padding) for a form, lg (48rem) for a record with a table, xl (56rem) for two columns, and full for the whole layer less its padding. --slotted-dialog-measure-sm, -md, -lg and -xl retune one step; --slotted-dialog-measure sets every step, for a width the steps do not hold.

Placement

placement="top" holds the panel near the top of the screen instead of centering it. Use it for content that grows while the reader types, such as a note or a comment: a centerd panel moves up by half of every new line.

Long content

With the default scroll="content", the panel never grows past the window: the body scrolls and the header and footer stay, so the actions are always in reach. scroll="viewport" lets the whole panel grow and scrolls the layer instead, for a document that is read rather than acted on.

DialogHeader (slDialogHeader) lays out the title, the description and the close button; anything else written in it, such as a status badge, sits under the description. DialogBody (slDialogBody) is the row that scrolls, and DialogFooter (slDialogFooter) holds the actions, aligned to the end. Every part is optional: a dialog with no footer draws no footer row.

Reading how it closed

Close the dialog from code with a result, through the ref handle in React (dialog.current.close('wait')) or the template reference in Angular (dialog.close('wait')). React’s onOpenChange receives the result on request.result; Angular’s (closed) emits it once the dialog has closed. A close with the ✕, Escape or a press outside carries no result.

Closing only from the actions

escape="none" and outsidePress="none" keep the dialog open when the reader presses Escape or clicks the backdrop. Use them when a stray key or click must not lose a choice, and leave a visible way out in the footer.

Refusing a close with unsaved changes

Every way of closing, from the ✕, Escape, a press outside or the browser’s back gesture, goes through one request: onOpenChange in React and (openChangeRequest) in Angular. Call request.cancel() to keep the dialog open. Here an edited address keeps the dialog open and asks, in an alert dialog over it, whether to discard the change. Edit the address, then press Escape.

Pier 70, Suite 300, Seattle, WA 98121

Opening from a row

A dialog needs no trigger. Set open from the row’s own button, and keep the row’s data in its own state so the content stays filled while the dialog animates out. Focus returns to the button that opened it.

OrderCustomerTotalActions
SO-1182Contoso Foods$1,240.00
SO-1183Fabrikam Grocers$386.50
SO-1184Tailspin Market$2,075.25

Opening from a menu item

A menu item that opens a dialog sets open from onSelect in React or (select) in Angular. The menu closes as the dialog opens, so name where focus goes afterwards: finalFocus takes the menu trigger, which is where the reader started.

Initial focus

When the dialog opens, focus moves to its first focusable element, here the close button. initialFocus names another element, such as a search field; initialFocus="container" focuses the panel itself, for content that is read before it is used. While a modal dialog is open, Tab and Shift+Tab cycle inside it, and Escape closes it and returns focus to the trigger.

A dialog over a dialog

A dialog opened from inside another stacks above it. Escape and a press outside close only the top one, and focus returns to the control in the dialog below.

A form in a dialog

Put the form in the body and point the footer’s submit button at it with the form attribute, so the actions stay in the footer row. Enter in a field submits it. Validate on submit, show each error in the field, and close the dialog only when the data is valid. Submit the empty form to see the errors.

Saving

While a save is in progress, show it on the button that started it with loading, disable the other actions, and refuse every close request so the result is not lost. Close the dialog when the save completes.

Loading content

loading marks the body as busy with aria-busy and keeps a minimum height, while the header, the ✕ and Escape stay available. Fill the body with skeletons in the shape of the content that is coming, so nothing moves when it arrives.

Confirming a destructive action

AlertDialog (sl-alert-dialog) is the dialog for a confirmation. It is always modal, a press outside never closes it, and focus starts on AlertDialogCancel (slAlertDialogCancel), the safe answer. It requires a description, and has no ✕: the reader answers with the cancel or the action. Label both buttons with what they do.

Alert tones

tone sets the alert dialog’s mark and its color: danger (the default) for an action that destroys data, warning for one with consequences, accent for an ordinary confirmation, and success and secondary beside them. Give the action button the same tone.

Non-modal

modal={false} ([modal]="false") leaves the page behind interactive: no scrim is drawn, the pointer and the wheel reach the page, nothing is made inert, the page scroll is not locked, focus can leave the panel, and the panel has no aria-modal. Use it for reference content the reader works beside, with outsidePress="none" so working on the page does not close it.

Full screen

By default, a dialog fills the whole layer when the layer is narrower than 480 pixels, without margins or rounded corners. fullScreen="always" does so at every width and fullScreen="never" keeps the margins. fullscreenToggle adds a button to the header that lets the reader expand the panel and restore it.

Defaults for a section

DialogDefaultsProvider in React and provideDialogDefaults in Angular set size, placement, scroll, surface, mount, fullScreen, modal, escape, outsidePress and back once for every dialog under them. A value set on one dialog still wins.

Cancelling an order

An alert dialog can hold a field. Here the reason is required, so the action stays disabled until one is chosen; the description states what the cancellation does before the reader commits.

Order SO-1182Processing

Creating a shipment from an order

A larger dialog composes a form: a select with descriptions, a validated field, a checkbox and a submit that saves for a moment. The close requests are refused while the shipment is being created.

Editing selected rows

The selection in a table decides what the dialog edits. The selected ids are copied when the dialog opens, so the title, the description and the update name the same rows, and the selection is cleared after the update. Select two orders, then edit them.

Select orders to edit them together.
OrderCustomerStatusShips from
SO-1182Contoso FoodsProcessingReno, NV
SO-1183Fabrikam GrocersProcessingColumbus, OH
SO-1184Tailspin MarketOn holdReno, NV
SO-1185Woodgrove DeliProcessingSavannah, GA

Accessibility

KeyEffectFocus
Tabmoves to the next tabbable element inside the layer, and wraps from the last to the first while modalthe next tabbable element inside the layer
Shift+Tabmoves to the previous tabbable element inside the layer, and wraps from the first to the last while modalthe previous tabbable element inside the layer
Escapeasks the topmost layer to close, carrying the reason escape; a layer that refuses stops the request reaching the layer beneath it, so one Escape never closes tworeturns to the element that held it when the layer opened

Dialog

  • Dialog follows the WAI-ARIA dialog (modal) pattern. While a modal dialog is open, Tab and Shift+Tab move through the focusable elements inside it and wrap from the last to the first and back. Escape closes the topmost dialog only; a dialog that refuses the close keeps the Escape from reaching the dialog beneath it.
  • The panel carries role="dialog", aria-labelledby pointing at the title and aria-describedby pointing at the description, each only while that part is rendered. An aria-label of your own on DialogContent replaces aria-labelledby.
  • aria-modal="true" is written only while the dialog is modal. A modal dialog makes everything outside it inert, which removes the page from the accessibility tree and from the pointer, and locks the page scroll. modal={false} does none of this and writes no aria-modal.
  • When the dialog opens, focus moves to its first focusable element, to the element initialFocus names, or to the panel itself with initialFocus="container", for content that is read before it is used. When it closes, focus returns to the element that had it when the dialog opened, or to the element finalFocus names. If that element has left the document, focus goes to its nearest ancestor still in the document.
  • Containment, inertness and Escape are implemented in JavaScript rather than with the native dialog element, so every overlay of the library shares one stacking order: a select opened inside a dialog paints above it. Without JavaScript, there is no dialog.
  • The close button’s target is at least 24 by 24 pixels, and its mark is drawn from a glyph, not a character.
  • The panel has a border as well as a shadow, so its edge stays visible under forced colors, where shadows are removed and the scrim becomes opaque.

AlertDialog

  • AlertDialog follows the WAI-ARIA alert dialog pattern: the modal dialog pattern with role="alertdialog" and a required description. The keyboard is the same: Tab and Shift+Tab wrap inside the panel, and Escape closes it.
  • aria-describedby is required. AlertDialog throws an error when no DialogDescription is rendered, so a confirmation is never announced without the sentence that says what it does.
  • Focus starts on AlertDialogCancel, the least destructive answer, as the pattern advises for a step that cannot be undone easily.
  • A press outside never closes an alert dialog, and it is always modal. Escape closes it, which answers with the cancel; set escape="none" when cancelling is not safe either.
  • There is no close part: the reader answers with the cancel or the action. Rendering DialogClose inside AlertDialog throws an error.
  • The tone is carried by the icon’s shape as well as by its color, so it survives forced colors and readers who cannot tell the colors apart.

API

Dialog

Props

openboolean
On Dialog, AlertDialogWhether the dialog is open. Passing it makes the state controlled: the dialog asks through onOpenChange and waits for the new value.
defaultOpenboolean
On Dialog, AlertDialogWhether an uncontrolled dialog starts open. Read once.
size'sm' | 'md' | 'lg' | 'xl' | 'full'Default md
On Dialog, DialogDefaultsProviderThe maximum width of the panel: 32rem, the form measure plus the panel padding (43rem by default), 48rem, 56rem, or the whole layer less its padding. For another width, set --slotted-dialog-measure, or --slotted-dialog-measure-sm, -md, -lg or -xl for one step.
placement'center' | 'top'Default center
On Dialog, AlertDialog, DialogDefaultsProviderWhere the panel sits in the layer. Use top for content that grows while the reader types, so the panel does not move with each new line.
scroll'content' | 'viewport'Default content
On Dialog, AlertDialog, DialogDefaultsProviderWhat scrolls when the content is long. content keeps the panel inside the layer and scrolls the body, so the actions stay on screen; viewport lets the panel grow and scrolls the layer. With content, the layer still scrolls when the header and footer alone are taller than it.
mount'active' | 'lazy' | 'eager'Default active
On Dialog, AlertDialog, DialogDefaultsProviderWhen the layer is in the document. active renders it while open and removes it after the closing animation, lazy renders it on the first open and keeps it, eager renders it from the start and hides it with content-visibility and inert while closed.
escape'close' | 'none'Default close
On Dialog, AlertDialog, DialogDefaultsProviderWhether Escape asks the dialog to close. Escape reaches the topmost dialog only.
loadingbooleanDefault false
On Dialog, AlertDialogMarks the body with aria-busy and gives it a minimum height while the content is on its way. The header, the close button and Escape stay available.
messagesPartial<DialogMessages>
On Dialog, AlertDialogReplaces words of the language in force, key by key: the accessible names of the close and full-screen buttons (close, fullScreen). An aria-label on DialogClose takes precedence.
initialFocus'first' | 'container' | 'cancel' | RefObject | falseDefault first
Where focus goes when the dialog opens: the first focusable element, the panel itself (container), the cancel part, the element of a ref, or nowhere (false). Use container for content that is read before it is used, such as a list or a table.
finalFocusRefObject | false
On Dialog, AlertDialogWhere focus goes when the dialog closes. Unset, focus returns to the element that had it when the dialog opened, usually the trigger. false leaves focus where it is.
valuestring
On DialogClose, AlertDialogCancel, AlertDialogActionThe result this button closes the dialog with, read from request.result in onOpenChange. AlertDialogCancel defaults to "cancel" and AlertDialogAction to "confirm".
modalbooleanDefault true
On Dialog, DialogDefaultsProviderWhether the page behind is inert, its scroll locked and focus kept inside the panel. false does none of this, paints no scrim, lets the pointer reach the page and writes no aria-modal.
outsidePress'close' | 'none'Default close
On Dialog, DialogDefaultsProviderWhether a press outside the panel asks the dialog to close. AlertDialog fixes it at none.
back'close' | 'none'Default close
On Dialog, DialogDefaultsProviderWhether the browser’s way back, a back button or a phone’s back gesture, closes a modal dialog instead of leaving the page. Each open modal dialog holds one close watcher where the browser has CloseWatcher, and adds one history entry elsewhere; the close request carries the reason back. A dialog opened without a press shares the way back with the layer opened before it.
surface'panel' | 'plain'Default panel
On Dialog, DialogDefaultsProviderWhether Dialog paints the panel. plain removes the background, border, radius, shadow, rows and padding, and keeps the portal, the scrim, focus handling and the dismissal policy, for a panel of your own such as a Card or an image viewer. A plain panel does not keep its footer on screen for a long body.
fullScreen'never' | 'narrow' | 'always'Default narrow
On Dialog, DialogDefaultsProviderWhen the panel fills the whole layer, without margins or radius. narrow does so while the layer is narrower than 480 pixels, measured with a container query on the layer.
fullscreenTogglebooleanDefault false
Adds a button to the header that expands the panel to the whole layer and restores it, for content the reader wants more room for.
fullscreenboolean
Whether the panel is expanded by the toggle. Passing it makes the state controlled, with onFullscreenChange.
defaultFullscreenbooleanDefault false
Whether an uncontrolled panel opens expanded. Read once.

Events

NamePayloadWhen
onOpenChange(open: boolean, request: DialogChangeRequest)Before the dialog opens or closes, whatever caused it. The request carries the new value, the previous value, the reason (pointer, keyboard, dismiss, escape, outsidePress, back, submit or programmatic), the result of the close, the originating event, and cancel(), which keeps the dialog as it is. One handler therefore guards the ✕, Escape, a press outside, the way back and the ref handle together.
onOpenChangeComplete(open: boolean)After the entrance or the exit has ended: true once the layer is settled open, false once it has left — the moment an application that renders the layer conditionally removes it, so the exit runs. A layer mounted open enters from its closed style, as one opened later does.
onFullscreenChange(fullscreen: boolean, request: DialogFullscreenRequest)Before the panel expands to the whole layer or is restored. The request carries the new value, the previous value, the reason (pointer, keyboard or programmatic), the originating event, and cancel(), which keeps the panel as it is.
onClick, onKeyDown and the other native events, on every partthe element’s own eventWhenever the element fires them. Your handler runs before the dialog’s own, and calling preventDefault() in it cancels the dialog’s behavior, such as opening on a trigger press or closing on a close press.

Composition

render(props) => ReactNode
On every partReplaces the element a part renders and passes it every attribute the part writes. Use it to make the trigger, the cancel and the action a Button.
refRef<DialogHandle> on Dialog, Ref<HTMLElement> on every part
On Dialog, AlertDialog, every partOn a part, the element. On Dialog and AlertDialog, a handle with open(), close(result), focus() and content, the panel element once it is rendered.
--slotted-dialog-measurelengthDefault from size
On the root partThe maximum width of the panel, for a width the five sizes do not hold, such as a two-column form at 46rem. Set it with a style attribute on one dialog, with a rule for a region, or once in the theme. It takes precedence over size, and a step token takes precedence over it.
--slotted-dialog-measure-sm, -md, -lg, -xllengthDefault from size
On the root partThe maximum width of one size step, read before --slotted-dialog-measure, so a theme widens one step and keeps the others.
containerElement | null
On Dialog, AlertDialogThe element this dialog is rendered into, instead of the shared portal root. To change the portal root for the whole document, call setPortalContainer from @slotted/core/portal.
useDialog()() => DialogContextValue
On inside Dialog or AlertDialogWhat the parts read: the open state, the ids, the resolved axes and close(reason, result). It throws outside Dialog and AlertDialog.
DialogDefaultsProvider{ size, placement, scroll, surface, mount, fullScreen, modal, escape, outsidePress, back }
On a subtreeSets these ten values once for every dialog under it. A value set on one dialog takes precedence.

Parts

PartElementRequiredPurpose
rootdiv, in a portalYesThe layer, fixed over the viewport. It carries data-ui="dialog", one attribute per axis, data-open and data-loading, and a z-index of --slotted-z-index-overlay plus the depth of the layer stack, so a dialog opened over another sits above it. It is also the container that fullScreen="narrow" measures, so full screen follows the width of the layer rather than the width of the window.
triggerbutton, or the element render returnsNoThe control that opens the dialog. It stays where it is written while the layer is rendered in a portal, and carries aria-haspopup, aria-expanded and aria-controls. A press on it does not count as a press outside the dialog. Rendered as a Button, the element keeps the button’s data-part="root".
backdropdivYesThe scrim behind the panel, painted from --slotted-scrim. It does not scroll. A non-modal dialog does not paint it and lets the pointer through to the page.
viewportdivYesThe box that positions the panel and, with scroll="viewport", the box that scrolls. A panel taller than the layer aligns to the top edge, so its title stays on screen.
contentdivYesThe panel. It carries role="dialog" and, while modal, aria-modal="true". It is a grid of three rows, header, body and footer, and only the body row shrinks, so the actions stay on screen when the body is long. It draws no padding: DialogHeader, DialogBody and DialogFooter carry the panel inset. A layout that skips them reads --slotted-dialog-inset-inline and --slotted-dialog-inset-block, which the panel states, and a theme sets the inset with --slotted-dialog-padding-inline and --slotted-dialog-padding-block.
headerheader, or the element render returnsNoThree columns: the mark, the words and the corner buttons. A title that wraps makes the row taller and never pushes the close button off the line. Any other content written in the header, such as a badge, is placed in the words column under the description.
titleh2, or the element render returnsNoThe visible name of the dialog. The panel points aria-labelledby at it only while it is rendered.
descriptionp, or the element render returnsNoThe sentence that says what the dialog is for. The panel points aria-describedby at it only while it is rendered. It is optional in Dialog and required in AlertDialog.
bodydiv, or the element render returnsNoThe row that scrolls. It carries aria-busy while loading is set. Scrolling it to the end does not scroll the page behind a non-modal dialog.
footerfooter, or the element render returnsNoThe actions: a row aligned to the end that wraps when the buttons do not fit, on the sunken surface. Each row of the panel draws the rule above itself, so a panel without a body draws one rule, not two.
closebuttonNoThe ✕ button. Its target is at least 24 by 24 pixels. It closes the dialog with the reason dismiss, carrying its value as the result.
fullscreenbuttonNoThe button that expands the panel to the whole layer and restores it, rendered by DialogHeader when fullscreenToggle is set. It sits before the close button, carries aria-pressed, and its mark shows what the next press does.

AlertDialog

tsx
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogIcon, DialogBody, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from '@slotted/react';

Props

openboolean
On Dialog, AlertDialogWhether the dialog is open. Passing it makes the state controlled: the dialog asks through onOpenChange and waits for the new value.
defaultOpenboolean
On Dialog, AlertDialogWhether an uncontrolled dialog starts open. Read once.
size'sm' | 'md' | 'lg' | 'xl' | 'full'Default sm
The maximum width of the panel. AlertDialog defaults to sm, 32rem.
placement'center' | 'top'Default center
On Dialog, AlertDialog, DialogDefaultsProviderWhere the panel sits in the layer. Use top for content that grows while the reader types, so the panel does not move with each new line.
scroll'content' | 'viewport'Default content
On Dialog, AlertDialog, DialogDefaultsProviderWhat scrolls when the content is long. content keeps the panel inside the layer and scrolls the body, so the actions stay on screen; viewport lets the panel grow and scrolls the layer. With content, the layer still scrolls when the header and footer alone are taller than it.
mount'active' | 'lazy' | 'eager'Default active
On Dialog, AlertDialog, DialogDefaultsProviderWhen the layer is in the document. active renders it while open and removes it after the closing animation, lazy renders it on the first open and keeps it, eager renders it from the start and hides it with content-visibility and inert while closed.
escape'close' | 'none'Default close
On Dialog, AlertDialog, DialogDefaultsProviderWhether Escape asks the dialog to close. Escape reaches the topmost dialog only.
loadingbooleanDefault false
On Dialog, AlertDialogMarks the body with aria-busy and gives it a minimum height while the content is on its way. The header, the close button and Escape stay available.
messagesPartial<DialogMessages>
On Dialog, AlertDialogReplaces words of the language in force, key by key: the accessible names of the close and full-screen buttons (close, fullScreen). An aria-label on DialogClose takes precedence.
initialFocus'first' | 'container' | 'cancel' | RefObject | falseDefault cancel
Where focus goes when the dialog opens. The default, cancel, is the least destructive answer.
finalFocusRefObject | false
On Dialog, AlertDialogWhere focus goes when the dialog closes. Unset, focus returns to the element that had it when the dialog opened, usually the trigger. false leaves focus where it is.
valuestring
On DialogClose, AlertDialogCancel, AlertDialogActionThe result this button closes the dialog with, read from request.result in onOpenChange. AlertDialogCancel defaults to "cancel" and AlertDialogAction to "confirm".
tone'accent' | 'secondary' | 'info' | 'success' | 'warning' | 'danger'Default danger
The kind of decision. It sets the mark AlertDialogIcon draws and its color.
modalbooleanDefault true
Fixed: an alert dialog is always modal.
outsidePress'close' | 'none'Default none
Fixed: a press outside never closes an alert dialog.
back'close' | 'none'Default close
Whether the browser’s way back cancels the confirmation, as Escape does. The close request carries the reason back.
surface'panel' | 'plain'Default panel
Whether AlertDialog paints the panel. plain removes the paint and keeps the behavior.
fullScreen'never' | 'narrow' | 'always'Default never
When the panel fills the whole layer. AlertDialog keeps its margins at every width by default.

Events

NamePayloadWhen
onOpenChange(open: boolean, request: DialogChangeRequest)Before the dialog opens or closes, whatever caused it. The request carries the new value, the previous value, the reason (pointer, keyboard, dismiss, escape, outsidePress, back, submit or programmatic), the result of the close, the originating event, and cancel(), which keeps the dialog as it is. One handler therefore guards the ✕, Escape, a press outside, the way back and the ref handle together.
onOpenChangeComplete(open: boolean)After the entrance or the exit has ended: true once the layer is settled open, false once it has left — the moment an application that renders the layer conditionally removes it, so the exit runs. A layer mounted open enters from its closed style, as one opened later does.
onFullscreenChange(fullscreen: boolean, request: DialogFullscreenRequest)Before the panel expands to the whole layer or is restored. The request carries the new value, the previous value, the reason (pointer, keyboard or programmatic), the originating event, and cancel(), which keeps the panel as it is.
onClick, onKeyDown and the other native events, on every partthe element’s own eventWhenever the element fires them. Your handler runs before the dialog’s own, and calling preventDefault() in it cancels the dialog’s behavior, such as opening on a trigger press or closing on a close press.

Composition

render(props) => ReactNode
On every partReplaces the element a part renders and passes it every attribute the part writes. Use it to make the trigger, the cancel and the action a Button.
refRef<DialogHandle> on Dialog, Ref<HTMLElement> on every part
On Dialog, AlertDialog, every partOn a part, the element. On Dialog and AlertDialog, a handle with open(), close(result), focus() and content, the panel element once it is rendered.
--slotted-dialog-measurelengthDefault from size
On the root partThe maximum width of the panel, for a width the five sizes do not hold, such as a two-column form at 46rem. Set it with a style attribute on one dialog, with a rule for a region, or once in the theme. It takes precedence over size, and a step token takes precedence over it.
--slotted-dialog-measure-sm, -md, -lg, -xllengthDefault from size
On the root partThe maximum width of one size step, read before --slotted-dialog-measure, so a theme widens one step and keeps the others.
containerElement | null
On Dialog, AlertDialogThe element this dialog is rendered into, instead of the shared portal root. To change the portal root for the whole document, call setPortalContainer from @slotted/core/portal.
useDialog()() => DialogContextValue
On inside Dialog or AlertDialogWhat the parts read: the open state, the ids, the resolved axes and close(reason, result). It throws outside Dialog and AlertDialog.
DialogDefaultsProvider{ size, placement, scroll, surface, mount, fullScreen, modal, escape, outsidePress, back }
On a subtreeSets these ten values once for every dialog under it. A value set on one dialog takes precedence.

Parts

PartElementRequiredPurpose
rootdiv, in a portalYesThe layer, fixed over the viewport. It carries data-ui="dialog", one attribute per axis, data-open and data-loading, and a z-index of --slotted-z-index-overlay plus the depth of the layer stack, so a dialog opened over another sits above it. It is also the container that fullScreen="narrow" measures, so full screen follows the width of the layer rather than the width of the window.
triggerbutton, or the element render returnsNoThe control that opens the dialog. It stays where it is written while the layer is rendered in a portal, and carries aria-haspopup, aria-expanded and aria-controls. A press on it does not count as a press outside the dialog. Rendered as a Button, the element keeps the button’s data-part="root".
backdropdivYesThe scrim behind the panel, painted from --slotted-scrim. It does not scroll. A non-modal dialog does not paint it and lets the pointer through to the page.
viewportdivYesThe box that positions the panel and, with scroll="viewport", the box that scrolls. A panel taller than the layer aligns to the top edge, so its title stays on screen.
contentdivYesThe panel. It carries role="alertdialog" and, while modal, aria-modal="true". It is a grid of three rows, header, body and footer, and only the body row shrinks, so the actions stay on screen when the body is long. It draws no padding: DialogHeader, DialogBody and DialogFooter carry the panel inset. A layout that skips them reads --slotted-dialog-inset-inline and --slotted-dialog-inset-block, which the panel states, and a theme sets the inset with --slotted-dialog-padding-inline and --slotted-dialog-padding-block.
headerheader, or the element render returnsNoThree columns: the mark, the words and the corner buttons. A title that wraps makes the row taller and never pushes the close button off the line. Any other content written in the header, such as a badge, is placed in the words column under the description.
titleh2, or the element render returnsNoThe visible name of the dialog. The panel points aria-labelledby at it only while it is rendered.
descriptionp, or the element render returnsYesThe sentence that says what is about to happen. Required: the alertdialog pattern makes aria-describedby mandatory, and AlertDialog throws an error when it is missing.
bodydiv, or the element render returnsNoThe row that scrolls. It carries aria-busy while loading is set. Scrolling it to the end does not scroll the page behind a non-modal dialog.
footerfooter, or the element render returnsNoThe actions: a row aligned to the end that wraps when the buttons do not fit, on the sunken surface. Each row of the panel draws the rule above itself, so a panel without a body draws one rule, not two.
iconspanNoThe mark of the tone, drawn from a glyph, so the kind of decision does not depend on color alone. Under forced colors it is the only signal of the tone.
cancelbuttonYesThe least destructive answer, and where focus lands when the dialog opens. It closes with the reason dismiss and the result "cancel". Rendered as a Button, the element keeps the button’s data-part="root".
actionbuttonYesThe action being confirmed. It closes with the reason submit and the result "confirm". Rendered as a Button, the element keeps the button’s data-part="root".

Theming

Each token is a CSS custom property: set it in a theme, or on any element to retune every dialog inside it.

Dialog tokens

TokenDefault
--slotted-dialog-backdrop-filternone
--slotted-dialog-body-colorvar(--slotted-text, CanvasText)
--slotted-dialog-border-colorvar(--slotted-border-subtle, ButtonBorder)
--slotted-dialog-close-active-backgroundvar(--slotted-tone-secondary-subtle-active)
--slotted-dialog-close-colorvar(--slotted-text-muted, GrayText)
--slotted-dialog-close-hover-backgroundvar(--slotted-tone-secondary-subtle-hover)
--slotted-dialog-colorvar(--slotted-text, CanvasText)
--slotted-dialog-description-colorvar(--slotted-text-muted, GrayText)
--slotted-dialog-footer-gapvar(--slotted-action-gap, 8px)
--slotted-dialog-footer-surfacevar(--slotted-surface-sunken, Canvas)
--slotted-dialog-measurecalc(var(--slotted-form-measure, 40rem) + 2 * var(--_padding-inline))
--slotted-dialog-measure-lgvar(--slotted-dialog-measure, 48rem)
--slotted-dialog-measure-mdvar( --slotted-dialog-measure, calc(var(--slotted-form-measure, 40rem) + 2 * var(--_padding-inline)) )
--slotted-dialog-measure-smvar(--slotted-dialog-measure, 32rem)
--slotted-dialog-measure-xlvar(--slotted-dialog-measure, 56rem)
--slotted-dialog-padding-blockvar(--slotted-space-7, 1.25rem)
--slotted-dialog-padding-block-smvar(--slotted-space-6, 1rem)
--slotted-dialog-padding-inlinevar(--slotted-space-8, 1.5rem)
--slotted-dialog-padding-inline-smvar(--slotted-space-7, 1.25rem)
--slotted-dialog-radiusvar(--slotted-radius-lg, 8px)
--slotted-dialog-rule-colorvar(--slotted-border-subtle, ButtonBorder)
--slotted-dialog-scrimvar(--slotted-scrim, Canvas)
--slotted-dialog-scrim-backdrop-filternone
--slotted-dialog-surfacevar(--slotted-surface-raised, Canvas)
--slotted-dialog-title-colorvar(--slotted-text, CanvasText)
--slotted-dialog-title-font-familyvar( --slotted-font-family-heading, var(--slotted-font-family-sans, ui-sans-serif, system-ui, sans-serif) )

Theme tokens it reads

TokenDefault
--slotted-action-gapcomfortable 8px · compact 6px · dense 4px
--slotted-border-subtleSet per scheme by the theme
--slotted-border-width-thick2px
--slotted-border-width-thin1px
--slotted-control-font-familyvar(--slotted-font-family-sans)
--slotted-control-icon-size-lgcomfortable 18px · compact 16px · dense 14px
--slotted-control-inner-size-lgcomfortable 28px · compact 24px · dense 22px
--slotted-control-radiusvar(--slotted-radius-sm)
--slotted-control-transition-durationvar(--slotted-duration-short)
--slotted-control-transition-easingvar(--slotted-easing-standard)
--slotted-duration-long320ms
--slotted-duration-medium200ms
--slotted-duration-short120ms
--slotted-easing-exitcubic-bezier(0.3, 0, 0.8, 0.15)
--slotted-easing-standardcubic-bezier(0.2, 0, 0, 1)
--slotted-focus-ring-colorSet per scheme by the theme
--slotted-focus-ring-offsetvar(--slotted-border-width-thick)
--slotted-focus-ring-widthvar(--slotted-border-width-thick)
--slotted-font-family-headingvar(--slotted-font-family-sans)
--slotted-font-family-sans'Geist Variable', ui-sans-serif, system-ui, sans-serif
--slotted-font-size-lg1rem
--slotted-font-size-md0.875rem
--slotted-font-size-xl1.125rem
--slotted-font-weight-semibold600
--slotted-form-measure40rem
--slotted-line-height-md1.5
--slotted-radius-lg8px
--slotted-radius-sm4px
--slotted-scrimSet per scheme by the theme
--slotted-shadow-lgSet per scheme by the theme
--slotted-space-124rem
--slotted-space-20.25rem
--slotted-space-40.5rem
--slotted-space-50.75rem
--slotted-space-61rem
--slotted-space-71.25rem
--slotted-space-81.5rem
--slotted-surface-raisedSet per scheme by the theme
--slotted-surface-sunkenSet per scheme by the theme
--slotted-target-comfortable44px
--slotted-target-min24px
--slotted-textSet per scheme by the theme
--slotted-text-mutedSet per scheme by the theme
--slotted-tone-accent-textSet per scheme by the theme
--slotted-tone-danger-textSet per scheme by the theme
--slotted-tone-info-textSet per scheme by the theme
--slotted-tone-secondary-subtle-activeSet per scheme by the theme
--slotted-tone-secondary-subtle-hoverSet per scheme by the theme
--slotted-tone-secondary-textSet per scheme by the theme
--slotted-tone-success-textSet per scheme by the theme
--slotted-tone-warning-textSet per scheme by the theme
--slotted-z-index-overlay1000