Popover
Button that opens a floating panel next to it, built on the native popover attribute with no script.
pnpm dlx shadcn@latest add @haze/popover---
import { cn } from "../../../lib/haze/utils";
import Button from "./button.astro";
interface Props {
/** Unique on the page. Links the trigger to the panel and names the CSS anchor. */
id: string;
/** Visible trigger text. The "trigger" slot replaces it. */
label?: string;
/** Accessible name for an icon-only trigger. */
ariaLabel?: string;
variant?: "primary" | "secondary" | "outline" | "ghost";
size?: "sm" | "md" | "lg";
/** Which trigger edge the panel lines up with. */
align?: "start" | "end";
side?: "bottom" | "top";
/** Extra classes for the trigger button. */
triggerClass?: string;
/** Classes for the panel, for example a width. */
class?: string;
}
const { id, label = "Open", ariaLabel, variant = "outline", size = "md", align = "start", side = "bottom", triggerClass, class: className } = Astro.props;
// With CSS anchor positioning the panel sits next to its trigger and flips at the viewport edge.
// The margin on its far side keeps an 8 px gutter when the panel has to hug that edge; the near side stays flush with the trigger.
// Without it the same panel opens as a centered sheet over a dimmed backdrop.
const placement = {
"bottom-start": "origin-top-left -translate-y-1 starting:open:-translate-y-1 supports-[position-area:block-end]:me-2 supports-[position-area:block-end]:[position-area:block-end_span-inline-end]",
"bottom-end": "origin-top-right -translate-y-1 starting:open:-translate-y-1 supports-[position-area:block-end]:ms-2 supports-[position-area:block-end]:[position-area:block-end_span-inline-start]",
"top-start": "origin-bottom-left translate-y-1 starting:open:translate-y-1 supports-[position-area:block-end]:me-2 supports-[position-area:block-end]:[position-area:block-start_span-inline-end]",
"top-end": "origin-bottom-right translate-y-1 starting:open:translate-y-1 supports-[position-area:block-end]:ms-2 supports-[position-area:block-end]:[position-area:block-start_span-inline-start]",
};
---
<Button variant={variant} size={size} popovertarget={id} aria-label={ariaLabel} class={triggerClass} style={`anchor-name: --${id}`}>
<slot name="trigger">{label}</slot>
</Button>
<div
popover
id={id}
style={`position-anchor: --${id}`}
class={cn(
"m-auto max-h-[min(24rem,calc(100dvh-2rem))] w-72 max-w-[calc(100vw-1rem)] overflow-y-auto rounded-xl border border-border bg-popover p-4 text-[0.8125rem] leading-[1.4] text-popover-foreground shadow-float backdrop:bg-background/60",
"scale-[0.97] opacity-0 transition-[opacity,scale,translate,overlay,display] transition-discrete duration-200 ease-snappy motion-reduce:transition-none open:translate-y-0 open:scale-100 open:opacity-100 starting:open:scale-[0.97] starting:open:opacity-0",
"supports-[position-area:block-end]:mx-0 supports-[position-area:block-end]:my-1 supports-[position-area:block-end]:backdrop:bg-transparent supports-[position-area:block-end]:[position-try-fallbacks:flip-block,flip-inline,flip-block_flip-inline]",
placement[`${side}-${align}`],
className,
)}
>
<slot />
</div>When to use
- Extra controls or details that should not take page space until asked for
- Filter and display settings attached to a toolbar button
- Content that may hold form controls, unlike a tooltip
When not to use
- A plain list of links or actions; use dropdown-menu
- A task that must block the page until finished; use dialog
- A one-line hint on hover; use tooltip
Installation
Add the Haze registry to components.json once, then install Popover with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/popovernpx shadcn@latest add @haze/popoveryarn dlx shadcn@latest add @haze/popoverbunx --bun shadcn@latest add @haze/popoverFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id* | string | – | Unique on the page. Links the trigger to the panel and names the CSS anchor. |
| label | string | "Open" | Visible trigger text when the trigger slot is not used. |
| ariaLabel | string | – | Accessible name for an icon-only trigger. |
| variant | "primary" | "secondary" | "outline" | "ghost" | "outline" | Trigger button style. |
| size | "sm" | "md" | "lg" | "md" | Trigger button size. |
| align | "start" | "end" | "start" | Trigger edge the panel lines up with. |
| side | "bottom" | "top" | "bottom" | Preferred side; it flips when there is no room. |
| class | string | – | Panel classes, for example a width. |
| trigger slot | slot | – | Custom trigger content, such as an icon and text. |
| default slot* | slot | – | Panel content. |
Keyboard interactions
- EnterSpace
- Open or close the panel from the trigger
- Escape
- Close the panel and return focus to the trigger
- Tab
- Move from the trigger into the open panel
Accessibility
- The panel scales and fades in over 150 ms and out again; reduced-motion users get no animation.
- The browser handles Escape, click-outside closing, the expanded state on the button and returning focus to it.
- Focus stays on the trigger when the panel opens; the next Tab moves into the panel.
- Before Firefox 147 and Safari 26 there is no CSS anchor positioning, so the panel opens centered over a dimmed backdrop instead.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Popover" with `npx shadcn@latest add @haze/popover`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Popover from "@/components/haze/ui/popover.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/popover.md
Customize with real content
Adapt the Haze popover ui for our product. Replace the demo values of these props with our real content: id, label, ariaLabel, variant, size, align, side, class, trigger slot, default slot. Keep the layout, the heading level rules and these accessibility details: The panel scales and fades in over 150 ms and out again; reduced-motion users get no animation. The browser handles Escape, click-outside closing, the expanded state on the button and returning focus to it. Focus stays on the trigger when the panel opens; the next Tab moves into the panel. Before Firefox 147 and Safari 26 there is no CSS anchor positioning, so the panel opens centered over a dimmed backdrop instead. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using popover, check it fits: use it when extra controls or details that should not take page space until asked for; filter and display settings attached to a toolbar button; content that may hold form controls, unlike a tooltip. Avoid it when a plain list of links or actions; use dropdown-menu; a task that must block the page until finished; use dialog; a one-line hint on hover; use tooltip. Alternatives: @haze/dropdown-menu, @haze/dialog, @haze/tooltip.
Dependencies
- @haze/button
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.