Basic Modal
A basic modal dialog with proper backdrop styling and accessibility features.
Small Modal
A smaller modal variant for simple confirmations and alerts.
Large Modal
A larger modal for more complex content and forms.
Fullscreen Modal
A fullscreen modal that takes up the entire viewport.
Simple Modal
A minimal modal without header or footer sections.
Backdrop Testing
Test the modal backdrop behavior and styling across different browsers.
What to test:
- Backdrop should be semi-transparent and darken background content
- Clicking the backdrop should close the modal
- ESC key should close the modal
- Content behind the modal should be hidden from screen readers
- Focus should be trapped within the modal
HTML Structure
Here's the basic HTML structure for modals:
<dialog class="modal">
<header class="header">
<h3 class="headline">Modal Title</h3>
<button class="control close" aria-label="Close">×</button>
</header>
<div class="content">
Modal content goes here
</div>
<footer class="footer">
<button class="btn">Cancel</button>
<button class="btn primary">OK</button>
</footer>
</dialog>
Auto-Opening Modals
Modals can automatically open when the page loads using data attributes.
Examples
Immediate auto-open:
<dialog class="modal" data-modal-auto-open="true">
<div class="content">This opens immediately</div>
</dialog>
Delayed auto-open:
<dialog class="modal" data-modal-auto-open="true" data-modal-auto-open-delay="3000">
<div class="content">This opens after 3 seconds</div>
</dialog>
JavaScript Usage
Initialize modals with the service:
import { initModals, createModal } from '@/modal/scripts/services/modal'
// Initialize all modals on the page (includes auto-open functionality)
initModals()
// Create a modal with auto-open programmatically
const modal = createModal('#my-modal', {
backdropClose: true,
escapeClose: true,
autoOpen: true, // Auto-open on initialization
autoOpenDelay: 3000, // Delay in milliseconds (optional)
onOpen: (element) => console.log('Modal opened'),
onClose: (element) => console.log('Modal closed')
})
// Programmatic control
modal.openModal()
modal.close()