Directory
- Welcome
Dialog Component
The Dialog component creates modal overlays that focus user attention on important content or actions. It features a semi-transparent backdrop, smooth animations, and comprehensive accessibility support.
Key Features
-
Flexible Positioning: Top, middle, or bottom screen placement
-
Smooth Animations: Polished transitions for opening and closing
-
Backdrop Management: Semi-transparent overlay with click-to-close
-
Focus Management: Maintains proper keyboard focus states
-
Accessibility: Full ARIA support and keyboard navigation
Basic Usage
Create a dialog with a trigger button:
<Button id="open-dialog">Open Dialog</Button><Dialog position="middle" triggerQuery="#open-dialog"> <h2>Welcome to the Dialog Component</h2> <p>This is a live example of the Dialog component in action.</p></Dialog>
Dialog Component Props API
Prop | Type | Default | Description |
---|---|---|---|
position | top | middle | bottom | middle | Vertical position of the dialog |
triggerQuery | string | Query selector for the element that triggers the dialog | |
closeButtonProps | ComponentProps<typeof Button> | Props for the close button |
Event Handling
The component emits custom events for changes:
document.querySelector('dialog-wrapper').addEventListener(DialogEventNames.Open, (event) => { // Handle open});
document.querySelector('dialog-wrapper').addEventListener(DialogEventNames.Close, (event) => { // Handle close});
Accessibility Features
- Escape to close
- Tab trap within dialog
- Return focus on close
Common Applications
Limited Time Launch Sale
Create engaging user interactions with our pre-built Dialog component. Get the AstroJS starter template now and build better web experiences.
GET 60% OFF!