Directory
- Welcome
Toast Component
The Toast component delivers brief, non-intrusive notifications that automatically appear and disappear. Perfect for providing feedback on user actions, displaying system status, or communicating important updates without disrupting the user experience.
Key Features
-
Multiple Positions: Four strategic placement options
-
Message Variants: Success and error states
-
Auto-dismiss: Configurable display duration
-
Accessible: Screen reader and keyboard support
Quick Start
Add the Toast component to your layout and trigger it programmatically:
<Toast id="my-toast" position="bottomRight" />
// Show a success messageconst toast = await Ready(document.querySelector<ToastElement>('#my-toast'));toast.show({ message: 'Changes saved successfully!', variant: 'success', duration: 3000,});
Toast Component Props API
Prop | Type | Default | Description |
---|---|---|---|
position | topLeft | topRight | bottomLeft | bottomRight | bottomRight | Toast position on screen |
buttonProps | ButtonProps | {} | Props for close button |
Toast Functions API
interface ToastData { show: ({ message, duration, variant }: { message: string; duration?: number; variant?: 'success' | 'error' }) => void; hide: () => void;}
Best Practices
-
Message Content
- Keep messages brief and clear
- Use appropriate variants for context
- Include specific details when helpful
- Avoid technical jargon
-
Timing and Display
- Set appropriate duration for message length
- Limit simultaneous toasts
- Position consistently throughout app
- Consider mobile viewports
-
Accessibility
- Use ARIA live regions
- Ensure keyboard accessibility
- Provide sufficient contrast
- Allow manual dismissal
Common Use Cases
Limited Time Launch Sale
Add polished notifications to your website today with our Toast component. Get the AstroJS starter template and enhance your user experience instantly.
GET 60% OFF!