Directory
- Welcome
Popover Component
The Popover component creates contextual overlays that appear next to a trigger element. It features smart positioning, smooth animations, and comprehensive accessibility support.
Key Features
-
Smart Positioning: Automatically adjusts to stay within viewport
-
Multiple Alignments: Start, center, or end alignment options
-
Keyboard Support: Full keyboard navigation and accessibility
-
Click Outside: Automatic closing when clicking outside
Basic Usage
Create a simple popover with default settings:
<Popover> <p>Open Popover</p> <p>This is the popover content.</p></Popover>
Position Variants
Position Options
<Popover position="above"> <p slot="trigger">Above</p> <div class="w-max modal p-4"> <p>Appears above the trigger</p> </div></Popover>
Alignment Options
<Popover position="below" alignment="center"> <p slot="trigger">Center</p> <div class="w-max modal p-4"> <p>Center aligned content</p> </div></Popover>
Popover Component Props API
Prop | Type | Default | Description |
---|---|---|---|
alignment | 'start' | 'center' | 'end' | start | Alignment of the popover |
buttonProps | ButtonProps | Props for trigger button | |
absoluteProps | HTMLDivElement | Props for absolute container | |
position | 'above' | 'below' | 'left' | 'right' | below | Position relative to trigger |
variant | 'default' | 'none' | default | Visual style variant |
Popover Functions API
The Popover component exposes methods for programmatic control:
// Get popover instanceconst popover = document.querySelector('popover-wrapper');
// Show popoverpopover.toggle(true);
// Hide popoverpopover.toggle(false);
// Toggle popoverpopover.toggle();
Use Cases
Limited Time Launch Sale
Add interactive popovers to your website with our AstroJS starter template. Get started now!
GET 60% OFF!