Components / Overlays

Popover16

A small panel that opens next to its trigger, for a bit of detail or a quick action. It grows out of the spot you clicked. In Comic it's a speech bubble whose tail points at the trigger.

Popover · PlaygroundLive
placement
JSX
<DialogTrigger>
  <Button>Plan details</Button>
  <Popover title="Pro plan">
    10 team members and unlimited projects.
  </Popover>
</DialogTrigger>

Usage

TSX
import { Button, DialogTrigger, Popover } from "plonk-ui";

export function PlanInfo() {
  return (
    <DialogTrigger>
      <Button>Plan details</Button>
      <Popover title="Pro plan">
        10 team members and unlimited projects.
      </Popover>
    </DialogTrigger>
  );
}

A popover is a small, non-modal dialog: it uses DialogTrigger too, and the page around it stays usable. It opens on the side given by placement and flips when there's no room.

Actions inside

Children as a function get close. Here the popover closes itself a moment after the link is copied.

Popover · ShareLive
TSX
import { useState } from "react";
import { Button, DialogTrigger, Input, Popover } from "plonk-ui";

const LINK = "https://plonk.dev/s/a8f3";

export default function Share() {
  const [copied, setCopied] = useState(false);

  return (
    <DialogTrigger onOpenChange={() => setCopied(false)}>
      <Button variant="secondary">Share</Button>
      <Popover title="Share link">
        {({ close }) => (
          <div className="flex flex-col gap-3">
            <Input aria-label="Link" defaultValue={LINK} readOnly />
            <Button
              size="sm"
              className="self-start"
              onPress={async () => {
                await navigator.clipboard?.writeText(LINK);
                setCopied(true);
                setTimeout(close, 700);
              }}
            >
              {copied ? "Copied!" : "Copy link"}
            </Button>
          </div>
        )}
      </Popover>
    </DialogTrigger>
  );
}

For text only, with nothing to click, use a Tooltip instead.

Personalities

Sticker grows the panel out of the point you clicked, with a slight twist. Retro shows it instantly, like a system menu. Comic turns it into a speech bubble with a tail that points at the trigger, and Arcade grows it in hard steps. With reduced motion it fades in.

Corner hook

Like the dialog, the popover reads its corner radius from a variable, --plonk-popover-radius:

CSS
.plonk-popover {
  --plonk-popover-radius: 0;
}

Accessibility

  • It's a dialog: focus moves into it when it opens and returns to the trigger when it closes.
  • Esc and clicking outside close it.
  • title names it. Without a title, pass aria-label.
  • The tail is decoration and is hidden from screen readers.

API

PropTypeDefaultDescription
titleReactNode—Small heading, also the popover's accessible name.
aria-labelstring—Accessible name. Required when there's no title.
classNamestring—Extra classes for the panel.
placement"left" | "right" | "bottom" | "bottom left" | "bottom right" | "bottom start" | "bottom end" | "top" | "top left" | "top right" | "top start" | "top end" | "left top" | "left bottom" | "start" | "start top" | "start bottom" | "right top" | "right bottom" | "end" | "end top" | "end bottom""bottom"Preferred side of the trigger. It flips when there's no room.
offsetnumber12Gap to the trigger, in pixels.
crossOffsetnumber0Shift along the trigger's edge, in pixels.
shouldFlipbooleantrueFlip to the other side when it doesn't fit.
isOpenboolean—Controlled open state, for popovers without a DialogTrigger.
onOpenChange(isOpen: boolean) => void—Called when it opens or closes.
triggerRefRefObject<Element | null>—Element to anchor to when there's no DialogTrigger, for example a table cell.