Dialog
MYDS-compliant dialog component for seamless transition starting point from HTML/CSS to React
Overview
The MYDS HTML/CSS Dialog provides a modal component for applications not using React. It ensures proper state handling, accessibility features, and design harmony across public-sector interfaces.
1. Setup
Follow these steps to prepare the dialog styles in your HTML project.
Recommended Import Order Make sure to load the stylesheets in this sequence to ensure proper styling:
This guarantees that:
- The CSS reset applies first.
- The dialog base styles override the reset where necessary.
- The dark theme styles apply last, so they can override both the reset and base dialog styles when needed.
Step 2 - Include the required font
The Inter font is part of the MYDS design guidelines. Add it inside your <head>:
Your <head> should look similar to:
2. Usage
The dialog uses the native HTML <dialog> element with the following structure:
3. Structure
The dialog consists of the following elements:
- Trigger Button: Opens the dialog using
showModal() - Dialog Element: Native HTML5 dialog element
- Dialog Header: Contains the title
- Dialog Content: Main content area
- Dialog Footer: Contains action buttons wrapped in
myds-dialog-actions-group - Close Button: Positioned absolutely in the top-right corner
4. States
Each button in the dialog supports:
- Default
- Hover
- Focused
- Disabled
5. Anatomy
| Selector | Purpose |
|---|---|
dialog | Native HTML dialog element with custom styling |
dialog::backdrop | The backdrop overlay (styled via pseudo-element) |
.myds-dialog-header | Header section |
.myds-dialog-title | Dialog title styling |
.myds-dialog-content | Content area |
.myds-dialog-footer | Footer section |
.myds-dialog-actions-group | Wrapper for footer buttons |
.myds-dialog-close | Close button |
.button-myds | Base button styles |
.button-myds-primary | Primary action button |
.button-myds-secondary | Secondary action button |
.page-center | Centers content on the page |
6. Customization
You can override default styles in your stylesheet. Example:
7. JavaScript
The implementation uses the native dialog API:
8. Accessibility
- Built with the native
<dialog>element - Keyboard navigation supported (ESC key closes dialog by default)
- Semantic button elements
- Visible focus ring for keyboard users
- SVG icon with proper viewBox for the close button