Skip to content

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

By name or description, across the 41 props below

Dialog 17 props

  • opentype boolean

    Controlled open state, when not inside a DialogTrigger.

  • defaultOpentype booleandefault false

    Initial open state when uncontrolled, when not inside a DialogTrigger.

  • roletype "dialog" | "alertdialog"default "alertdialog", or "dialog" when fullScreen isn't "never"

    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 a dialog.

  • closedBytype "any" | "closerequest" | "none"default "closerequest" for an alertdialog, "any" otherwise

    How the user can close the dialog, as HTML's <dialog closedby>: any (Escape or a press outside), closerequest (Escape only) or none (only its own buttons or the app).

  • icontype ReactNode

    Icon above the title (which is then centred). Decorative. Not shown in full screen.

  • fullScreentype "never" | "always" | "compact"default "never"

    Fills the window, with a DialogHeader holding the close button, title and confirming action instead of DialogActions (or with them as a bottom bar when the header has no action). compact, the spec's recommendation, does so only below 600px; always fills every window.

  • origintype DialogOrigin

    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" (the DialogTrigger'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.

  • placementtype "center" | "top" | "bottom" | "start" | "end"default "center"

    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).

  • transitiontype "reveal" | "scale"default "reveal"

    How a basic dialog enters and leaves. reveal is 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. scale is 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 and instant turns the motion off. A full-screen dialog keeps its own motion and ignores it.

  • instanttype booleandefault false

    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.

  • reftype Ref<HTMLDivElement>

    Ref to the root element.

Events

  • onOpenChangetype ((open: boolean) => void)

    Called when the dialog opens or closes.

  • onOpenedtype (() => void)

    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.

  • onClosedtype (() => void)

    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.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

DialogTrigger 4 props

  • childrentype ReactNodeRequired

    The trigger (a Button, IconButton, …) followed by the Dialog.

  • opentype boolean

    Controlled open state.

  • defaultOpentype booleandefault false

    Initial open state when uncontrolled.

Events

  • onOpenChangetype ((open: boolean) => void)

    Called when the dialog opens or closes.

DialogTitle 3 props

  • reftype Ref<HTMLHeadingElement>

    Ref to the root element.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

DialogHeader 10 props

  • childrentype ReactNodeRequired

    The headline; it names the dialog.

  • actiontype ReactNode

    The confirming action, usually a text Button ("Save"). Shown in full screen only; without it, a full-screen dialog shows its DialogActions as a bottom bar.

  • dividertype booleandefault false

    A 1px outline-variant divider under the full-screen header.

  • closeDisabledtype booleandefault false

    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's closedBy="none" to keep Escape from closing it too.

  • closeIcontype ReactElement<unknown, string | JSXElementConstructor<any>>

    Replaces the full-screen close button's icon.

  • reftype Ref<HTMLDivElement>

    Ref to the root element.

Text

  • labelstype Partial<DialogHeaderLabels>

    Words the header announces, with English defaults. A LabelsProvider sets them for the whole app.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

DialogContent 4 props

  • dividerstype booleandefault false

    The basic dialog's optional dividers: 1px outline-variant lines across the panel above and below the content, e.g. around a scrolling list. Not drawn in full screen.

  • reftype Ref<HTMLDivElement>

    Ref to the root element.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

DialogActions 3 props

  • reftype Ref<HTMLDivElement>

    Ref to the root element.

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.

Dialog tokens (md-comp-dialog)
VariableDefaultPaintsCompose
--md-comp-dialog-container-colorvar(--md-sys-color-surface-container-high)The panel.DialogTokens.ContainerColor
--md-comp-dialog-container-shapevar(--md-sys-shape-corner-extra-large)The panel's corners.DialogTokens.ContainerShape
--md-comp-dialog-container-elevationvar(--md-sys-elevation-level-3)The panel's shadow.DialogTokens.ContainerElevation
--md-comp-dialog-headline-colorvar(--md-sys-color-on-surface)The title (`DialogTitle`, or the full-screen header's).DialogTokens.HeadlineColor
--md-comp-dialog-supporting-text-colorvar(--md-sys-color-on-surface-variant)The supporting text (`DialogContent`).DialogTokens.SupportingTextColor
--md-comp-dialog-with-icon-icon-colorvar(--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.

  • 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.

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.kt and 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-high at 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 instant turns the motion off. onOpened and onClosed fire when each motion has finished, like Material Web's opened and closed events. 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-high with no corners or elevation, a 56px header with an on-surface close icon and a title-large headline, content padded 24px at the top and sides, and the panel sliding up 48px as it fades in on the slow springs. With origin it 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.