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&apos;s some amazing content. It&apos;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.

State: closed

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.

PropTypeDefault
defaultOpenboolean
openboolean
onOpenChangefunction
modalbooleanfalse

Popover.Trigger

The button that toggles the popover. By default, the Popover.Content will position itself against the trigger.

PropTypeDefault
asChildbooleanfalse
classNamestring

Data attributeValues
[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.

PropTypeDefault
asChildbooleanfalse
classNamestring

Popover.Close

The button that closes an open popover.

PropTypeDefault
asChildbooleanfalse
classNamestring

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.

PropTypeDefault
asChildbooleanfalse
arrowbooleantrue
onOpenAutoFocusfunction
onCloseAutoFocusfunction
onEscapeKeyDownfunction
onPointerDownOutsidefunction
onFocusOutsidefunction
onInteractOutsidefunction
forceMountboolean
sideenum"bottom"
sideOffsetnumber6
alignenum"center"
alignOffsetnumber0
avoidCollisionsbooleantrue
collisionBoundaryBoundary[]
collisionPaddingnumber | Padding0
arrowPaddingnumber0
stickyenum"partial"
hideWhenDetachedbooleanfalse
classNamestring

Data attributeValues
[data-state]"open" | "closed"
[data-side]"left" | "right" | "bottom" | "top"
[data-align]"start" | "end" | "center"

CSS VariableDescription
--radix-popover-content-transform-originThe transform-origin computed from the content and arrow positions/offsets.
--radix-popover-content-available-widthThe remaining width between the trigger and the boundary edge.
--radix-popover-content-available-heightThe remaining height between the trigger and the boundary edge.
--radix-popover-trigger-widthThe width of the trigger.
--radix-popover-trigger-heightThe 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.