Dialog
A dialog is a modal window that overlays the current page to grab the user's attention.
Usage
cv-dialog--hero
When to use
They are used for tasks that require immediate focus, such as confirmations, log-in forms, or input forms. Modals should be used sparingly to avoid disrupting the user experience. A modal typically requires the user to take action before they can continue interacting with the rest of the page.
Variant | Purpose |
|---|---|
Default | Display critical information or actions requiring focused user attention |
Recommendations
cv-dialog_do--recommendation
cv-dialog_dont--recommendation
Usage -- additional resources
Style
Anatomy
cv-dialog_anatomy
- Provides details about the request.
- Provides a brief description of the message or request.
- Contains the header, body, and buttons.
- Actions the user can take on the message or request.
Typography
Use these text styles for dialog:
- body-1
- headline-6
- button
cv-dialog_typography
Content guidelines
Two scenarios require a modal dialog:
- Confirming the user's action.
- Communicating a high-severity error.
Confirming the user's action
If the user initiates a destructive action, display a modal dialog to give the user a chance to review their work before proceeding with the action.
cv-dialog_do--content_1
If the user is not aware of an action that's been initiated, for example, they accidentally select the Back button on their browser while editing a form, display a modal dialog to communicate what happened and the actions they can take.
cv-dialog_do--content_2
Communicating a high-severity error
Not all errors call for displaying a modal dialog. When critical issues require the user's immediate attention, use a modal dialog. For complete details on designing content for high-severity errors, see Errors in Content.
Variants
Action buttons can be horizontally aligned or vertically stacked.
cv-dialog_anatomy_variants
Anatomy | Color token |
|---|---|
1 | on-surface-variant |
2 | on-surface |
3 | surface-container |
4 | primary |
Web components
Demos
- Default
- Delete confirmation
Default
Props
Prop | Description |
|---|---|
| Whether the dialog is open |
| Whether to hide the action buttons |
| Whether action buttons are stacked vertically |
| The dialog heading text |
| Action to take when the scrim is clicked |
| Action to take when the escape key is pressed |
| The default action |
| Attribute for action elements |
| Attribute for initial focus element |
How to import
Methods
Method signature | Description |
|---|---|
| Forces dialog to relayout (animation frame time). May be required if dialog size is incorrect or if stacked layout has not been triggered correctly. |
| Focuses on the initial focus element if defined. |
| Blurs the active element. |
| Opens the dialog. |
| Closes the dialog. |
Listeners
Event name | Target | Description |
|---|---|---|
| root element | Detects if clicked target is a dialog action. |
| window | Performs dialog layout (passive). |
| window | Performs dialog layout (passive). |
| mwc-dialog | Listens for the enter key to click the default button (passive). |
| document | Listens for the escape key to close the dialog. |
Events
Event name | Target | Detail | Description |
|---|---|---|---|
|
|
| Fired when the dialog is beginning to open. |
|
|
| Fired once the dialog is finished opening (after animation). |
|
|
| Fired when the dialog is beginning to close. Detail is the action that closed the dialog. |
|
|
| Fired once the dialog is finished closing (after animation). Detail is the action that closed the dialog. |
Web components -- additional resources
Accessibility
Overview
The Dialog component ensures inclusivity by supporting seamless navigation for keyboard and assistive technology users. Proper focus management, clear labeling, and adherence to WCAG standards make dialogs perceivable, operable, and user-friendly. This ensures a consistent and equitable experience for all users.
Keyboard interactions
Focus management
- Focus is automatically set to the first interactive element when the dialog opens.
- Ensure focus is returned to the triggering element upon closing.
Tab index
- Tab navigation cycles through all focusable elements within the dialog.
- Prevent focus from moving outside the dialog while it is open.
cv-dialog_accessibility
ARIA roles
- Use
role="dialog"and associate it with alabeloraria-labelledbyfor screen reader accessibility. - Provide contextual descriptions with
aria-describedbyfor better comprehension.
Escape key support
- Dialogs should be dismissible with the Escape key for intuitive closure.