Popover
A floating panel anchored to a trigger, built on Radix Popover with Hummingbird's popover styling.
Default
tsx
import { Popover, Button } from "@hummingbirdui/react";
export default function PopoverDefault() {
return (
<Popover>
<Popover.Trigger asChild>
<Button>Open popover</Button>
</Popover.Trigger>
<Popover.Content>
<Popover.Header>Popover title</Popover.Header>
<Popover.Body>
And here's some amazing content. It's very engaging. Right?
</Popover.Body>
</Popover.Content>
</Popover>
);
}Placement
Use side and align to position Popover.Content relative to the trigger.
tsx
import { Popover, Button } from "@hummingbirdui/react";
export default function PopoverPlacement() {
return (
<div className="flex flex-wrap gap-2">
<Popover>
<Popover.Trigger asChild>
<Button variant="outline">Top</Button>
</Popover.Trigger>
<Popover.Content side="top">
<Popover.Body>Opens above the trigger.</Popover.Body>
</Popover.Content>
</Popover>
<Popover>
<Popover.Trigger asChild>
<Button variant="outline">Right</Button>
</Popover.Trigger>
<Popover.Content side="right">
<Popover.Body>Opens to the right.</Popover.Body>
</Popover.Content>
</Popover>
<Popover>
<Popover.Trigger asChild>
<Button variant="outline">Bottom</Button>
</Popover.Trigger>
<Popover.Content side="bottom">
<Popover.Body>Opens below the trigger.</Popover.Body>
</Popover.Content>
</Popover>
<Popover>
<Popover.Trigger asChild>
<Button variant="outline">Left</Button>
</Popover.Trigger>
<Popover.Content side="left">
<Popover.Body>Opens to the left.</Popover.Body>
</Popover.Content>
</Popover>
</div>
);
}With a Close Button
Popover.Close dismisses the popover from within the content.
tsx
import { Popover, Button, CloseButton } from "@hummingbirdui/react";
export default function PopoverWithClose() {
return (
<Popover>
<Popover.Trigger asChild>
<Button>Dismissable</Button>
</Popover.Trigger>
<Popover.Content>
<Popover.Header className="flex items-center justify-between">
Heads up
<Popover.Close asChild>
<CloseButton />
</Popover.Close>
</Popover.Header>
<Popover.Body>
Click the close button to dismiss this popover.
</Popover.Body>
</Popover.Content>
</Popover>
);
}Controlled
Use open with onOpenChange to control the popover state.
tsx
import * as React from "react";
import { Popover, Button } from "@hummingbirdui/react";
export default function PopoverControlled() {
const [open, setOpen] = React.useState(false);
return (
<div className="flex items-center justify-center gap-3">
<Popover open={open} onOpenChange={setOpen}>
<Popover.Trigger asChild>
<Button>Toggle popover</Button>
</Popover.Trigger>
<Popover.Content>
<Popover.Header>Controlled</Popover.Header>
<Popover.Body>
The open state is driven by React through <code>open</code> and{" "}
<code>onOpenChange</code>.
</Popover.Body>
</Popover.Content>
</Popover>
<span className="text-sm">State: {open ? "open" : "closed"}</span>
</div>
);
}API Reference
Built on the Radix UI Popover primitive. Each part forwards all props to its Radix counterpart.
Popover
Contains all the parts of a popover.
| Prop | Type | Default |
|---|---|---|
defaultOpen | boolean | — |
open | boolean | — |
onOpenChange | function | — |
modal | boolean | false |
Popover.Trigger
The button that toggles the popover. By default, the Popover.Content will position itself against the trigger.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
className | string | — |
| Data attribute | Values |
|---|---|
[data-state] | "open" | "closed" |
Popover.Anchor
An optional element to position the Popover.Content against. If this part is not used, the content will position alongside the Popover.Trigger.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
className | string | — |
Popover.Close
The button that closes an open popover.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
className | string | — |
Popover.Content
The component that pops out when the popover is open. It renders inside a portal and includes a styled arrow automatically, so separate Portal and Arrow parts are not needed.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
arrow | boolean | true |
onOpenAutoFocus | function | — |
onCloseAutoFocus | function | — |
onEscapeKeyDown | function | — |
onPointerDownOutside | function | — |
onFocusOutside | function | — |
onInteractOutside | function | — |
forceMount | boolean | — |
side | enum | "bottom" |
sideOffset | number | 6 |
align | enum | "center" |
alignOffset | number | 0 |
avoidCollisions | boolean | true |
collisionBoundary | Boundary | [] |
collisionPadding | number | Padding | 0 |
arrowPadding | number | 0 |
sticky | enum | "partial" |
hideWhenDetached | boolean | false |
className | string | — |
| Data attribute | Values |
|---|---|
[data-state] | "open" | "closed" |
[data-side] | "left" | "right" | "bottom" | "top" |
[data-align] | "start" | "end" | "center" |
| CSS Variable | Description |
|---|---|
--radix-popover-content-transform-origin | The transform-origin computed from the content and arrow positions/offsets. |
--radix-popover-content-available-width | The remaining width between the trigger and the boundary edge. |
--radix-popover-content-available-height | The remaining height between the trigger and the boundary edge. |
--radix-popover-trigger-width | The width of the trigger. |
--radix-popover-trigger-height | The height of the trigger. |
Popover.Header
The header region of the popover panel. Renders a div with Hummingbird's popover-header class.
Popover.Body
The body region of the popover panel. Renders a div with Hummingbird's popover-body class.
Styling
Hummingbird React popover is styled entirely through Hummingbird's utility classes and CSS variables.
- See the full list of available popover classes in the Class overview.
- Visit the CSS Variables documentation to explore all available variables.