Dialog
A modal surface for a focused task or a decision, with a title, content and actions, or full screen on compact windows.
import { Dialog, DialogTrigger, DialogTitle, DialogHeader, DialogContent, DialogActions } from '@windmorph/react';Props
Dialog 17 props
Controlled open state, when not inside a
DialogTrigger.Initial open state when uncontrolled, when not inside a
DialogTrigger.Basic dialogs are alert dialogs on the web (the spec): they need a decision, are described by their
DialogContent, and aren't dismissed by pressing outside. A dialog that can be full screen is adialog.closedBytype"any" | "closerequest" | "none"default"closerequest" for an alertdialog, "any" otherwiseHow the user can close the dialog, as HTML's
<dialog closedby>:any(Escape or a press outside),closerequest(Escape only) ornone(only its own buttons or the app).Icon above the title (which is then centred). Decorative. Not shown in full screen.
Fills the window, with a
DialogHeaderholding the close button, title and confirming action instead ofDialogActions(or with them as a bottom bar when the header has no action).compact, the spec's recommendation, does so only below 600px;alwaysfills every window.Grows the full-screen dialog out of this origin and shrinks it back into it on close, the spec's container transform from a FAB:
"trigger"(theDialogTrigger's button), an element, or a box in window coordinates. The clip, corners and container colour move from the origin to the window on the slow spatial spring and the content fades in; reduced motion keeps only the fades. Used only while the dialog is full screen.Where a basic dialog sits: centred (the spec's default) or against one side of the window, keeping 24px from its edges on compact windows and 56px on wider ones. For any other position, align it with
classNames.positioner(for example"items-start justify-end"for the top end corner). It also sets the motion's direction: centred or at the top the dialog slides down and grows downward as it enters, at the bottom up, and at the start or end along the x axis (mirrored in right-to-left layouts).How a basic dialog enters and leaves.
revealis the M3 dialog motion: it slides 50px away from the edge it sits against while its container grows from that edge, and its headline and content, then its actions, fade in.scaleis the library's original pop, an extension beyond the M3 motion: the dialog fades in while it scales up from 90%, and fades out while it scales to 95%, from the centre (placement="center") or from the edge it sits against. Either way reduced motion keeps only the fades andinstantturns the motion off. A full-screen dialog keeps its own motion and ignores it.Skips the enter and exit motion: the dialog, its parts and the scrim appear and leave at once, and the dialog leaves the document as soon as it closes. Reduced motion already keeps only the fades.
Ref to the root element.
Events
Called when the dialog opens or closes.
Called when the dialog has finished opening: once its enter motion (the slide, the container's growth and every part's fade) has ended, or right after it opens with
instant. Not called when it closes before then.Called when the dialog has finished closing: once its exit motion has ended and it has left the document, or right after it closes with
instant.
Classes for the dialog's parts, merged over the library's:
scrim,positioner(the full-window box that places the dialog; align it anywhere withitems-*andjustify-*),panel(the surface) andicon.The dimmed layer behind the dialog.
The fixed, full-window flex box that places the dialog. It pads 24px on compact windows and 56px from the medium breakpoint, and
placementsets its alignment, so alignment classes here (items-*,justify-*) position the dialog anywhere within the spec's margin, and padding classes change that margin.The dialog's surface: its colour, corners, padding, size and shadow.
The icon above the title.
Goes on the outermost element, with
className.Classes for the root element, merged with the component's own (yours win).
Also accepts the root element's HTML attributes (id, data-*, event handlers).
DialogTrigger 4 props
The trigger (a Button, IconButton, …) followed by the
Dialog.Controlled open state.
Initial open state when uncontrolled.
DialogTitle 3 props
Also accepts the root element's HTML attributes (id, data-*, event handlers).
DialogHeader 10 props
The headline; it names the dialog.
The confirming action, usually a text
Button("Save"). Shown in full screen only; without it, a full-screen dialog shows itsDialogActionsas a bottom bar.A 1px
outline-variantdivider under the full-screen header.Disables the full-screen close button, e.g. while the confirming action is saving, so the dialog can't be left halfway. Pair it with the
Dialog'sclosedBy="none"to keep Escape from closing it too.Replaces the full-screen close button's icon.
Ref to the root element.
Text
Words the header announces, with English defaults. A
LabelsProvidersets them for the whole app.
Classes for each part, by slot.
Inline styles for the root element.
Classes for the root element, merged with the component's own (yours win).
Also accepts the root element's HTML attributes (id, data-*, event handlers).
DialogContent 4 props
The basic dialog's optional dividers: 1px
outline-variantlines across the panel above and below the content, e.g. around a scrolling list. Not drawn in full screen.Ref to the root element.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
DialogActions 3 props
Also accepts the root element's HTML attributes (id, data-*, event handlers).
Tokens
M3's component tokens as CSS variables. Each is unset until you set it, on :root, a theme or any ancestor, and falls back to the default shown. The root carries data-variant (and data-size where it has sizes), which picks the variables that apply. See Component tokens in the Customisation guide.
| Variable | Default | Paints | Compose |
|---|---|---|---|
--md-comp-dialog-container-color | var(--md-sys-color-surface-container-high) | The panel. | DialogTokens.ContainerColor |
--md-comp-dialog-container-shape | var(--md-sys-shape-corner-extra-large) | The panel's corners. | DialogTokens.ContainerShape |
--md-comp-dialog-container-elevation | var(--md-sys-elevation-level-3) | The panel's shadow. | DialogTokens.ContainerElevation |
--md-comp-dialog-headline-color | var(--md-sys-color-on-surface) | The title (`DialogTitle`, or the full-screen header's). | DialogTokens.HeadlineColor |
--md-comp-dialog-supporting-text-color | var(--md-sys-color-on-surface-variant) | The supporting text (`DialogContent`). | DialogTokens.SupportingTextColor |
--md-comp-dialog-with-icon-icon-color | var(--md-sys-color-secondary) | The icon above the title (`icon`). | DialogTokens.IconColor |
Spec status
Built to the M3 Expressive dialog spec. Each item of its variants and configurations links to a live example; where the M3 Expressive column of the spec differs from the original M3 one, it wins.
| Item | Status | Details |
|---|---|---|
| Basic dialog | Built | Variant · Basic, Alert |
| Full-screen dialog | Built | Variant · Full screen |
| Icon (optional) | Built | Configuration · Icon |
| Custom position | Built | Configuration · Placement, Custom position |
| Scrolling content | Built | Configuration · Scrollable |
| Dividers (optional) | Built | Configuration · Dividers |
| Confirm a high-risk action | Built | Use case · Alert, Icon |
| Full screen on every window | Extension | fullScreen="always" fills wide windows too; the spec keeps full-screen dialogs to compact windows, which fullScreen="compact" follows. |
| Dismissal options | Extension | closedBy (HTML's <dialog closedby>) picks what closes it: any (Escape or a press outside), closerequest (Escape only, an alert dialog's default) or none. |
| Motion callbacks and no motion | Extension | onOpened and onClosed fire once the enter and exit motion have finished (Material Web's opened and closed events), and instant turns the motion off. |
| Scale transition | Extension | transition="scale" swaps the M3 dialog motion (the default, reveal) for the library's original pop: a fade with a scale from 90% entering and to 95% leaving, with no clip, slide or staggered parts. Basic dialogs only; full-screen dialogs keep their own motion. |
Full-screen dialog
BuiltVariant · Full screen
Icon (optional)
BuiltConfiguration · Icon
Custom position
BuiltConfiguration · Placement, Custom position
Scrolling content
BuiltConfiguration · Scrollable
Dividers (optional)
BuiltConfiguration · Dividers
Full screen on every window
ExtensionfullScreen="always"fills wide windows too; the spec keeps full-screen dialogs to compact windows, whichfullScreen="compact"follows.Dismissal options
ExtensionclosedBy(HTML's<dialog closedby>) picks what closes it:any(Escape or a press outside),closerequest(Escape only, an alert dialog's default) ornone.Motion callbacks and no motion
ExtensiononOpenedandonClosedfire once the enter and exit motion have finished (Material Web'sopenedandclosedevents), andinstantturns the motion off.Scale transition
Extensiontransition="scale"swaps the M3 dialog motion (the default,reveal) for the library's original pop: a fade with a scale from 90% entering and to 95% leaving, with no clip, slide or staggered parts. Basic dialogs only; full-screen dialogs keep their own motion.
Bundle size
Gzipped, as published: the component and the library code it imports. React, React Aria, Motion and the other dependencies aren't counted, and your bundler's minifier makes it smaller still. CI fails a change that grows it past its budget.
Dialog,DialogTrigger,DialogTitle,DialogHeader,DialogContent,DialogActions: 42.2 kB
M3 Expressive specs
- Shape
rounded-corner-extra-large- Elevation
level3
Differences from Compose
- Values follow Compose's
AlertDialog.ktand the dialog tokens: 280–560px wide (the minimum narrows only to keep 24px from a very narrow window's edges), 24px padding, 28px corners,surface-container-highat level 3, a 32% scrim. - Stacked actions put the confirm action on top, matching Compose's flipped
FlowRow. - Motion is not from Compose (which uses platform window animations). It follows the M3 dialog motion as Material Web encodes it, on the M3 Expressive springs: entering, the dialog slides 50px away from the window edge it sits against (down when centred or at the top, up at the bottom, along the x axis at the start or end) while its container grows from that edge, the headline and content fade in after 50ms and the actions after 150ms, and the scrim fades in. Leaving, the parts fade out, the dialog slides back while its container shrinks to 35%, then the container fades. The container is a clip on a library-owned wrapper, so it grows from 0 as the spec says (Material Web starts at 35% because its container doesn't clip the text). Reduced motion keeps only the fades of the dialog and the scrim, and
instantturns the motion off.onOpenedandonClosedfire when each motion has finished, like Material Web'sopenedandclosedevents.transition="scale"brings back the library's original pop instead, an extension beyond the M3 motion: a fade with a scale from 90% entering and to 95% leaving, from the centre or the edge the dialog sits against. Full-screen dialogs keep their own motion either way. - Compose has no full-screen dialog component; the full-screen type follows the M3 dialog spec:
surface-container-highwith no corners or elevation, a 56px header with anon-surfaceclose icon and atitle-largeheadline, content padded 24px at the top and sides, and the panel sliding up 48px as it fades in on the slow springs. Withoriginit is a container transform instead: the clip, corners and container colour move from the origin to the window on the slow spatial spring. Closing, they go back into the origin over 250ms (emphasized accelerate), the container staying opaque until it fades over the last 100ms.