Dialog
A dialog (Fluent UI v2 style), modal by default: Dialog holds the open state; Dialog.Trigger opens and closes it and Dialog.Content renders the surface in a portal while open (and, with unmountOnClose={false}, keeps it there while closed, hidden and inert).
- **Modal**: focus moves into the dialog and Tab stays inside it (toasts included), the rest of the page is inert (instead of aria-modal, so toasts and live regions stay announced), and the page does not scroll.
- **Closing**: Escape (only the topmost layer: a popup opened inside closes first), a click on the backdrop (a drag that starts inside does not close it), the Close button and Dialog.Close. onOpenChange gets the reason as its second argument (details.reason), so a controlled dialog can refuse some of them. A backdrop press blurs the focused field before the dialog closes, so a typed value is committed as with the Close button; when a controlled dialog refuses the press, the field gets focus back (an alert dialog's press leaves focus where it was). Focus returns to the first of these that can take focus: finalFocusRef, the element that had focus when the dialog opened, the trigger, an element next to where that opener was.
- **Alert dialogs**: modalType="alert" renders role="alertdialog" for a confirmation that needs an answer; a backdrop press does not close it.
- **Non-modal dialogs**: modalType="non-modal" leaves the page usable (no backdrop, no focus trap, nothing inert, the page scrolls). Focus moves in on open; Tab and Shift+Tab leave the dialog in the page's order right after the element that opened it; Escape closes it only while focus is inside it; presses on the page never close it; focus returns to the opener only from inside. Keep the page's controls clear of the dialog, which covers the page under it.
- **Size**: Dialog.Content size caps the width at 400px (small), 600px (medium, the default) or 940px (large); full covers the viewport and pads its safe-area insets.
- **Backdrop**: the backdrop is the surface's sibling and a slot (backdrop: null removes it, appearance picks dimmed or transparent). A modal opened over another modal dims the page once: its backdrop is transparent while the lower one is open.
- **Close button and title actions**: closeButton sets the built-in Close button's content, or hides it (null); a button passed there is merged into it. titleAction and Dialog.Title's action place header buttons before the Close button in the top end corner, in DOM and Tab order, and the titles' end padding makes room for them. Initial focus goes to the first focusable element: a title action, else the Close button.
- **Footer**: Dialog.Footer sticks to the bottom of the scrolling body, and the body keeps a focused field above it.
- **Kept mounted**: unmountOnClose={false} keeps the content mounted while the dialog is closed, so a form keeps what was typed and the components inside keep their state; each open focuses the first focusable element again (an autoFocus inside never applies), and a kept dialog opened while another overlay is open stacks above it.
- **Motion**: the surface scales and fades in and out and the backdrop fades with it (none under reduced motion); Dialog.Content's motion and backdropMotion turn each off (null) or replace it, and WaveProvider motion="none" turns both off. The surface mounts through the presence core and renders data-presence; while it exits it stays on screen, inert, and focus, the trap and the scroll lock are already released.
- **Naming**: give Dialog.Content a title, a Dialog.Title, or aria-label.
The sub-components are also exported under flat names (DialogTrigger, DialogContent, DialogFooter, DialogTitle, DialogClose) for React Server Components, which cannot use the dotted form; dotted access (Dialog.Content) needs a client file.
Examples
Default
export const Default: Story = {};Open
This example opens a dialog or panel. Use the button to show it.
export const Open: Story = {
args: { defaultOpen: true },
parameters: openStoryParameters,
};Small Size
export const SmallSize: Story = {
args: {
children: (
<>
<Dialog.Trigger>
<Button appearance="primary">Open small dialog</Button>
</Dialog.Trigger>
<Dialog.Content title="Small dialog" size="small">
<p>This is a small dialog with a maximum width of 400px.</p>
<Dialog.Footer>
<Dialog.Close>
<Button appearance="primary">OK</Button>
</Dialog.Close>
</Dialog.Footer>
</Dialog.Content>
</>
),
},
};With Dialog Title
export const WithDialogTitle: Story = {
args: {
children: (
<>
<Dialog.Trigger>
<Button appearance="primary">Delete file</Button>
</Dialog.Trigger>
<Dialog.Content>
<Dialog.Title>
Delete <em>report.pdf</em>?
</Dialog.Title>
<p>The file is moved to the recycle bin.</p>
<Dialog.Footer>
<Dialog.Close>
<Button appearance="subtle">Cancel</Button>
</Dialog.Close>
<Dialog.Close>
<Button appearance="primary">Delete</Button>
</Dialog.Close>
</Dialog.Footer>
</Dialog.Content>
</>
),
},
};Narrow Viewport
This example opens a dialog or panel. Use the button to show it.
export const NarrowViewport: Story = {
args: {
defaultOpen: true,
children: (
<Dialog.Content title="Terms of service">
{Array.from({ length: 12 }, (_, index) => (
<p key={index} className="mb-2">
Paragraph {index + 1}. The dialog body scrolls when the content is taller than the
viewport, so the title, the Close button and the actions stay reachable.
</p>
))}
<Dialog.Footer>
<Dialog.Close>
<Button appearance="subtle">Decline</Button>
</Dialog.Close>
<Dialog.Close>
<Button appearance="primary">Accept</Button>
</Dialog.Close>
</Dialog.Footer>
</Dialog.Content>
),
},
globals: { viewport: { value: 'mobile1', isRotated: false } },
parameters: openStoryParameters,
};Large And Full Screen
This example opens a dialog or panel. Use the button to show it.
export const LargeAndFullScreen: Story = {
args: {
defaultOpen: true,
children: (
<Dialog.Content
title="Migrate the build to Vite"
className="max-w-[72rem] max-[48rem]:m-0 max-[48rem]:h-dvh max-[48rem]:max-h-none max-[48rem]:rounded-none max-[48rem]:border-0"
>
{Array.from({ length: 6 }, (_, index) => (
<p key={index} className="mb-2">
Section {index + 1}. A task dialog that is a workspace rather than a form: its content
can lay itself out in more columns as the dialog widens, and the body scrolls when it is
taller than the dialog.
</p>
))}
<Dialog.Footer>
<Dialog.Close>
<Button appearance="subtle">Cancel</Button>
</Dialog.Close>
<Dialog.Close>
<Button appearance="primary">Save</Button>
</Dialog.Close>
</Dialog.Footer>
</Dialog.Content>
),
},
parameters: openStoryParameters,
};Alert Dialog
export const AlertDialog: Story = {
args: {
modalType: 'alert',
children: (
<>
<Dialog.Trigger>
<Button>Delete file</Button>
</Dialog.Trigger>
<Dialog.Content title="Delete report.pdf?" size="small">
<p>The file is deleted permanently. This cannot be undone.</p>
<Dialog.Footer>
<Dialog.Close>
<Button appearance="subtle">Cancel</Button>
</Dialog.Close>
<Dialog.Close>
<Button appearance="primary">Delete</Button>
</Dialog.Close>
</Dialog.Footer>
</Dialog.Content>
</>
),
},
};Unsaved Changes
export const UnsavedChanges: Story = {
render: function UnsavedChangesDialog(args) {
const [open, setOpen] = React.useState(false);
const [name, setName] = React.useState('');
const dirty = name !== '';
const handleOpenChange: NonNullable<DialogProps['onOpenChange']> = (next, details) => {
args.onOpenChange?.(next, details);
if (!next && dirty && details.reason === 'outside-press') return;
setOpen(next);
if (!next) setName('');
};
return (
// The story owns the controlled pair; every other arg is forwarded.
<Dialog {...args} open={open} onOpenChange={handleOpenChange}>
<Dialog.Trigger>
<Button appearance="primary">Rename project</Button>
</Dialog.Trigger>
<Dialog.Content title="Rename project">
<Field
label="New name"
hint={
dirty
? 'Unsaved changes: a click outside the dialog keeps it open.'
: 'Type a name, then click outside the dialog.'
}
>
<Input value={name} onValueChange={setName} />
</Field>
<Dialog.Footer>
<Dialog.Close>
<Button appearance="subtle">Cancel</Button>
</Dialog.Close>
<Dialog.Close>
<Button appearance="primary">Save</Button>
</Dialog.Close>
</Dialog.Footer>
</Dialog.Content>
</Dialog>
);
},
};Long Content
This example opens a dialog or panel. Use the button to show it.
export const LongContent: Story = {
args: {
defaultOpen: true,
children: (
<Dialog.Content title="Shipping details">
<form
aria-label="Shipping details"
className="flex flex-col gap-3"
onSubmit={(event) => event.preventDefault()}
>
{shippingFields.map((field) => (
<Field key={field} label={field}>
<Input />
</Field>
))}
<Dialog.Footer>
<Dialog.Close>
<Button appearance="subtle">Cancel</Button>
</Dialog.Close>
<Button appearance="primary" type="submit">
Save
</Button>
</Dialog.Footer>
</form>
</Dialog.Content>
),
},
parameters: openStoryParameters,
};Controlled
export const Controlled: Story = {
render: function ControlledDialog(args) {
const [open, setOpen] = React.useState(false);
const handleOpenChange: NonNullable<DialogProps['onOpenChange']> = (next, details) => {
setOpen(next);
args.onOpenChange?.(next, details);
};
return (
<>
<Button
appearance="primary"
onClick={(event) =>
handleOpenChange(true, { reason: 'trigger', event: event.nativeEvent })
}
>
Open controlled dialog
</Button>
{/* The story owns the controlled pair; every other arg is forwarded. */}
<Dialog {...args} open={open} onOpenChange={handleOpenChange}>
<Dialog.Content title="Controlled dialog">
<p>This dialog is controlled via state.</p>
<Dialog.Footer>
<Button
appearance="subtle"
onClick={(event) =>
handleOpenChange(false, { reason: 'close', event: event.nativeEvent })
}
>
Close
</Button>
</Dialog.Footer>
</Dialog.Content>
</Dialog>
</>
);
},
};Non Modal
This example opens a dialog or panel. Use the button to show it.
export const NonModal: Story = {
args: { defaultOpen: true, modalType: 'non-modal' },
render: function NonModalDialog(args) {
return (
<div className="flex flex-wrap items-end gap-2">
<Dialog {...args}>
<Dialog.Trigger>
<Button appearance="primary">Formatting help</Button>
</Dialog.Trigger>
<Dialog.Content title="Formatting help" size="small">
<p>Wrap text in asterisks for bold, and start a line with a dash for a list.</p>
<Dialog.Footer>
<Dialog.Close>
<Button appearance="primary">Got it</Button>
</Dialog.Close>
</Dialog.Footer>
</Dialog.Content>
</Dialog>
<Field label="Comment">
<Input />
</Field>
<Button>Post</Button>
</div>
);
},
parameters: openStoryParameters,
};Sizes
export const Sizes: Story = {
render: function SizesStory(args) {
return (
<div className="flex flex-wrap gap-2">
{sizes.map((size) => (
// The story renders one dialog per size; every other arg is forwarded.
<Dialog key={size} {...args}>
<Dialog.Trigger>
<Button>{`Open ${size}`}</Button>
</Dialog.Trigger>
<Dialog.Content title={`The ${size} size`} size={size}>
<p>The dialog takes the full width up to its size and never exceeds the viewport.</p>
<Dialog.Footer>
<Dialog.Close>
<Button appearance="primary">Done</Button>
</Dialog.Close>
</Dialog.Footer>
</Dialog.Content>
</Dialog>
))}
</div>
);
},
};Full Screen
This example opens a dialog or panel. Use the button to show it.
export const FullScreen: Story = {
args: {
defaultOpen: true,
children: (
<Dialog.Content title="Shipping details" size="full">
<form
aria-label="Shipping details"
className="flex flex-col gap-3"
onSubmit={(event) => event.preventDefault()}
>
{shippingFields.map((field) => (
<Field key={field} label={field}>
<Input />
</Field>
))}
<Dialog.Footer>
<Dialog.Close>
<Button appearance="subtle">Cancel</Button>
</Dialog.Close>
<Button appearance="primary" type="submit">
Save
</Button>
</Dialog.Footer>
</form>
</Dialog.Content>
),
},
parameters: openStoryParameters,
};Title Actions
export const TitleActions: Story = {
render: function TitleActionsStory(args) {
const [expanded, setExpanded] = React.useState(false);
return (
<div className="flex flex-wrap gap-2">
{/* The story renders two dialogs; every other arg is forwarded to both. */}
<Dialog {...args}>
<Dialog.Trigger>
<Button appearance="primary">Open the report</Button>
</Dialog.Trigger>
<Dialog.Content
title="Quarterly report"
size={expanded ? 'full' : 'large'}
titleAction={
<ToggleButton
appearance="subtle"
size="small"
icon={<ExpandIcon />}
aria-label="Expand"
pressed={expanded}
onPressedChange={setExpanded}
/>
}
>
<p>Revenue grew in every region; the tables below break it down by product line.</p>
<Dialog.Footer>
<Dialog.Close>
<Button appearance="primary">Done</Button>
</Dialog.Close>
</Dialog.Footer>
</Dialog.Content>
</Dialog>
<Dialog {...args}>
<Dialog.Trigger>
<Button>Share the report</Button>
</Dialog.Trigger>
<Dialog.Content>
<Dialog.Title
action={
<Button
appearance="subtle"
size="small"
icon={<LinkIcon />}
aria-label="Copy link"
/>
}
>
Share the quarterly report
</Dialog.Title>
<p>People with the link can view the report.</p>
</Dialog.Content>
</Dialog>
</div>
);
},
};No Close Button
export const NoCloseButton: Story = {
args: {
modalType: 'alert',
children: (
<>
<Dialog.Trigger>
<Button>Leave the page</Button>
</Dialog.Trigger>
<Dialog.Content title="Leave without saving?" size="small" closeButton={null}>
<p>Your changes to the report are lost.</p>
<Dialog.Footer>
<Dialog.Close>
<Button appearance="subtle">Stay</Button>
</Dialog.Close>
<Dialog.Close>
<Button appearance="primary">Leave</Button>
</Dialog.Close>
</Dialog.Footer>
</Dialog.Content>
</>
),
},
};Custom Close Button
export const CustomCloseButton: Story = {
args: {
children: (
<>
<Dialog.Trigger>
<Button appearance="primary">Open the checklist</Button>
</Dialog.Trigger>
<Dialog.Content title="Release checklist" closeButton={<Button>Done</Button>}>
<p>Every item is checked. Close the checklist when you have read it.</p>
</Dialog.Content>
</>
),
},
};Stacked Dialogs
export const StackedDialogs: Story = {
args: {
children: (
<>
<Dialog.Trigger>
<Button appearance="primary">Open settings</Button>
</Dialog.Trigger>
<Dialog.Content title="Settings">
<p>Reset every setting to its default value.</p>
<Dialog.Footer>
<Dialog modalType="alert">
<Dialog.Trigger>
<Button>Reset</Button>
</Dialog.Trigger>
<Dialog.Content title="Reset every setting?" size="small">
<p>This cannot be undone.</p>
<Dialog.Footer>
<Dialog.Close>
<Button appearance="subtle">Cancel</Button>
</Dialog.Close>
<Dialog.Close>
<Button appearance="primary">Reset</Button>
</Dialog.Close>
</Dialog.Footer>
</Dialog.Content>
</Dialog>
<Dialog.Close>
<Button appearance="primary">Done</Button>
</Dialog.Close>
</Dialog.Footer>
</Dialog.Content>
</>
),
},
};Custom Backdrop
export const CustomBackdrop: Story = {
render: function CustomBackdropStory(args) {
return (
<div className="flex flex-wrap gap-2">
{/* The story renders two dialogs; every other arg is forwarded to both. */}
<Dialog {...args}>
<Dialog.Trigger>
<Button appearance="primary">Tinted backdrop</Button>
</Dialog.Trigger>
<Dialog.Content
title="Tinted backdrop"
backdrop={{ className: 'bg-wave-primary/30 backdrop-blur-sm' }}
>
<p>The backdrop takes the brand colour and blurs the page behind it.</p>
</Dialog.Content>
</Dialog>
<Dialog {...args}>
<Dialog.Trigger>
<Button>Transparent backdrop</Button>
</Dialog.Trigger>
<Dialog.Content title="Transparent backdrop" backdrop={{ appearance: 'transparent' }}>
<p>The page is not dimmed; it is still inert, and a press outside closes the dialog.</p>
</Dialog.Content>
</Dialog>
</div>
);
},
};Keep Mounted
export const KeepMounted: Story = {
args: {
unmountOnClose: false,
children: (
<>
<Dialog.Trigger>
<Button appearance="primary">Write feedback</Button>
</Dialog.Trigger>
<Dialog.Content title="Feedback">
<div className="flex flex-col gap-3">
<Field label="Subject">
<Input />
</Field>
<Field label="Message">
<Input />
</Field>
</div>
<Dialog.Footer>
<Dialog.Close>
<Button appearance="subtle">Cancel</Button>
</Dialog.Close>
<Dialog.Close>
<Button appearance="primary">Send</Button>
</Dialog.Close>
</Dialog.Footer>
</Dialog.Content>
</>
),
},
};Motion
export const Motion: Story = {
render: function MotionDialogs(args) {
return (
<div className="flex flex-wrap gap-2">
{motionCases(riseMotion).map(({ label, motion }) => (
// The story renders one dialog per case; every other arg is forwarded.
<Dialog key={label} {...args}>
<Dialog.Trigger>
<Button>{label}</Button>
</Dialog.Trigger>
<Dialog.Content
title={label}
motion={motion}
backdropMotion={typeof motion === 'string' ? backdropFade : motion}
>
<p>Close the dialog with Escape, the Close button or Done to see its exit.</p>
<Dialog.Footer>
<Dialog.Close>
<Button appearance="primary">Done</Button>
</Dialog.Close>
</Dialog.Footer>
</Dialog.Content>
</Dialog>
))}
</div>
);
},
};Footer Layouts
export const FooterLayouts: Story = {
render: function FooterLayoutsStory(args) {
const layouts = [
{ label: 'Start group', footer: { startActions: <Button>Reset</Button> } },
{ label: 'Actions at the start', footer: { position: 'start' as const } },
{ label: 'Fluid and stacked', footer: { fluid: true, stackOnNarrow: true } },
];
return (
<div className="flex flex-wrap gap-2">
{layouts.map(({ label, footer }) => (
<Dialog key={label} {...args}>
<Dialog.Trigger>
<Button>{label}</Button>
</Dialog.Trigger>
<Dialog.Content title={label} size="small">
<p>The actions of this footer: {label.toLowerCase()}.</p>
<Dialog.Footer {...footer}>
<Dialog.Close>
<Button appearance="subtle">Cancel</Button>
</Dialog.Close>
<Dialog.Close>
<Button appearance="primary">Save</Button>
</Dialog.Close>
</Dialog.Footer>
</Dialog.Content>
</Dialog>
))}
</div>
);
},
};Title Level
export const TitleLevel: Story = {
render: function TitleLevelStory(args) {
return (
<div className="flex flex-wrap gap-2">
<Dialog {...args}>
<Dialog.Trigger>
<Button>Title as h3</Button>
</Dialog.Trigger>
<Dialog.Content title="An h3 title" titleAs="h3" size="small">
<p>The title prop renders an h3.</p>
</Dialog.Content>
</Dialog>
<Dialog {...args}>
<Dialog.Trigger>
<Button>Dialog.Title as h1</Button>
</Dialog.Trigger>
<Dialog.Content size="small">
<Dialog.Title as="h1">An h1 title</Dialog.Title>
<p>Dialog.Title renders an h1.</p>
</Dialog.Content>
</Dialog>
</div>
);
},
};Light Dismiss And Mount Node
export const LightDismissAndMountNode: Story = {
render: function LightDismissStory(args) {
const [mountNode, setMountNode] = React.useState<HTMLElement | null>(null);
return (
<div className="flex flex-wrap items-start gap-4">
<Dialog {...args} modalType="non-modal" lightDismiss>
<Dialog.Trigger>
<Button appearance="primary">Light dismiss</Button>
</Dialog.Trigger>
<Dialog.Content title="Click anywhere else" size="small">
<p>A press on the page closes this dialog.</p>
</Dialog.Content>
</Dialog>
<Dialog {...args}>
<Dialog.Trigger>
<Button>Mount into the box</Button>
</Dialog.Trigger>
<Dialog.Content title="Mounted in a node" size="small" mountNode={mountNode}>
<p>This surface is a child of the box below.</p>
</Dialog.Content>
</Dialog>
<div ref={setMountNode} className="w-full rounded-md border border-wave-border p-2">
Mount node
</div>
</div>
);
},
};Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
open | boolean | No | Controlled open state of the dialog. The surface renders only in the browser: an open dialog is closed in the server HTML and opens once it has hydrated. | |
defaultOpen | boolean | No | false | Default open state for uncontrolled usage. The surface renders only in the browser: a dialog open by default is closed in the server HTML and opens once it has hydrated. |
onOpenChange | (open: boolean, details: DialogOpenChangeDetails) => void | No | Called with the new open state when it changes. Fires only when the value changes; a controlled dialog stays as it is until the parent updates | |
modalType | 'modal' | 'alert' | 'non-modal' | No | 'modal' |
|
lightDismiss | boolean | No | false | Light dismiss of a |
finalFocusRef | React.RefObject<HTMLElement | null> | No | Where focus goes when the dialog closes, if it can take focus. Otherwise focus returns to the element that had focus when the dialog opened, then to the trigger, then to an element next to where that opener was (the next row's action after a confirm dialog deleted the row). Use it to send focus somewhere else. | |
unmountOnClose | boolean | No | true | Removes |
children | React.ReactNode | Yes |
|
Parts
Dialog.TriggerDialog.ContentDialog.FooterDialog.TitleDialog.Close