A contextual floating component for displaying information and interactive content anchored to a trigger element. Uses Floating UI for intelligent positioning with arrow indicator support and click-outside-to-close behavior.
The default popover with a trigger button and positioned content.
---
import Popover from "../popover.astro";
import Button from "@pindoba/astro-button";
import { stack } from "@pindoba/styled-system/patterns";
---
<div class={stack({ gap: "md", direction: "column", align: "start" })}>
<Popover id="astro-demo-popover-default" title="Popover Title">
This is the popover content. Click outside to close.
</Popover>
<Button id="astro-demo-popover-trigger">Open Popover</Button>
</div>
<script>
import { usePopover } from "@pindoba/astro-popover/use-popover";
const trigger = document.getElementById("astro-demo-popover-trigger");
usePopover({ id: "astro-demo-popover-default", trigger });
</script>Use the placement prop to control where the popover appears relative to its trigger. Automatically flips and shifts when there is insufficient space.
---
import Popover from "../popover.astro";
import Button from "@pindoba/astro-button";
import { stack } from "@pindoba/styled-system/patterns";
---
<div
class={stack({
gap: "md",
direction: "row",
align: "center",
flexWrap: "wrap",
})}
>
<Popover id="astro-demo-popover-top" title="Top">
Placed above the trigger.
</Popover>
<Button id="astro-demo-popover-top-trigger">Top</Button>
<Popover id="astro-demo-popover-bottom" title="Bottom">
Placed below the trigger.
</Popover>
<Button id="astro-demo-popover-bottom-trigger">Bottom</Button>
<Popover id="astro-demo-popover-left" title="Left">
Placed to the left.
</Popover>
<Button id="astro-demo-popover-left-trigger">Left</Button>
<Popover id="astro-demo-popover-right" title="Right">
Placed to the right.
</Popover>
<Button id="astro-demo-popover-right-trigger">Right</Button>
</div>
<script>
import { usePopover } from "@pindoba/astro-popover/use-popover";
usePopover({
id: "astro-demo-popover-top",
trigger: document.getElementById("astro-demo-popover-top-trigger"),
placement: "top",
});
usePopover({
id: "astro-demo-popover-bottom",
trigger: document.getElementById("astro-demo-popover-bottom-trigger"),
placement: "bottom",
});
usePopover({
id: "astro-demo-popover-left",
trigger: document.getElementById("astro-demo-popover-left-trigger"),
placement: "left",
});
usePopover({
id: "astro-demo-popover-right",
trigger: document.getElementById("astro-demo-popover-right-trigger"),
placement: "right",
});
</script>| Prop | |
|---|---|
open | open Controls the open/closed state of the popover. Bindable in Svelte. Type Default Required |
placement | placement Preferred placement of the popover relative to the trigger. Floating UI will flip or shift as needed to stay in the viewport. Type Default Required |
trigger | trigger Snippet (Svelte) that renders the trigger element. Receives an onclick handler. Type Default Required |
triggerElement | triggerElement Reference to the trigger DOM element. Bindable. Used for positioning when the trigger is managed externally. Type Default Required |
id | id Unique identifier for the popover dialog element. Type Default Required |
title | title Dialog title displayed in the popover header. Type Default Required |
passThrough | passThrough Custom styling and props for popover slots. The arrow slot controls the positioning indicator. All dialog slots are also available. Type Default Required |
children | children Content rendered inside the popover. Type Default Required |