Dialog
A modal dialog component for displaying content that requires user attention.
Code
<!-- Trigger button -->
<button type="button" data-dialog="info-dialog">View Information</button>
<!-- Dialog example -->
<Dialog id="info-dialog" title="Information">
<p>This dialog contains important information for the user.</p>
<p>It can contain more complex UI elements or longer content.</p>
<form method="dialog">
<p>
<button type="submit">OK</button>
</p>
</form>
</Dialog>
Props
Name | Type | Required | Description |
---|---|---|---|
id |
string | Yes | Unique identifier for the dialog |
title |
string | Yes | Title text displayed in the dialog header |
Usage
✅ Do’s
- Use for important information requiring user attention
- Keep dialogs simple and focused on a single task
- Provide clear actions (confirm, cancel, etc.)
- Use descriptive titles that summarize the purpose
- Allow keyboard navigation within the dialog
❌ Don’t’s
- Don’t use for non-critical information
- Don’t nest dialogs within dialogs
- Don’t use for complex multi-step processes
- Don’t use for content that should be part of the main page
- Don’t make dialogs too large or overloaded with content
Accessibility
Keyboard Navigation
- ESC key closes the dialog
- Tab key moves focus between interactive elements
- Focus is contained within the dialog
- When opened, focus moves to the first focusable element
- When closed, focus returns to the trigger element (if any)
Screen Reader Support
- When opened, the dialog context is announced to screen readers
- Uses the HTML
<dialog>
element