Live demo
Demo source
Use a dialog for a short task that needs attention before people continue, such as a confirmation, an important message or a small form. While it is open, the page behind it is covered and can't be used. Don't open a dialog from another dialog.
Anatomy
A dialog titled Dialog Title on a dimmed overlay, with a message and two actions. Callouts mark 1 the header, 2 the body, 3 the footer, 4 the close button and 5 the overlay.
- Header (
nv-dialogheader) holds a short title and an optional subheading. - Body is the default slot: text, a form or other content.
- Footer (
nv-dialogfooter) has a cancel and a primary action, which can be a danger action. - Close button closes the dialog without saving. With
undismissable, it is removed, Escape does nothing, and the footer needs its ownundismissableto drop Cancel. - Overlay covers the page. Clicking it closes the dialog only with
clickOutside.
Sizes and themes
The design offers a regular dialog and a larger alternative. In code, the
regular dialog sizes to its content within viewport limits; full gives it a
wide, viewport-relative layout. There is no size enum. Both Spark and Ocean
provide the dialog surface, overlay and action styles.
Customising the sections
Replace the header and footer slots independently, and put body content
in the default slot. There is no named body slot. Keep the title and
primary action easy to identify even when the content is a form or another
custom layout. In Figma, give a replacement body component a fixed width so
its parent dialog resizes correctly.
Use a dialog for confirmations, focused alerts or short forms. If an action inside it needs another confirmation, restructure the task rather than opening another modal.
Opening and closing
A button in the trigger slot opens the dialog. With controlled, the
application opens it through open instead. Escape and the close button
close it and update open. Cancel emits dialogCanceled: an uncontrolled
dialog then closes itself, but a controlled one stays open until your
application sets open to false. The primary action never closes the dialog;
your application decides when the task is done.
- Name actions after what they do, such as "Delete readings" or "Save name", not "OK" or "Done".
- Keep the title short and use the subheading for context.
Accessibility
The dialog uses the browser's modal dialog behaviour. Keep a meaningful title
and a visible way to finish or dismiss the task, and preserve labelling when
replacing the header. autofocus can opt into focusing the first focusable
control; use it deliberately, especially when that control has a tooltip.