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.
<DialogTrigger>
<Button>Plan details</Button>
<Popover title="Pro plan">
10 team members and unlimited projects.
</Popover>
</DialogTrigger>Usage
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.
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:
.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.
Escand clicking outside close it.titlenames it. Without a title, passaria-label.- The tail is decoration and is hidden from screen readers.
API
| Prop | Type | Default | Description |
|---|---|---|---|
title | ReactNode | — | Small heading, also the popover's accessible name. |
aria-label | string | — | Accessible name. Required when there's no title. |
className | string | — | 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. |
offset | number | 12 | Gap to the trigger, in pixels. |
crossOffset | number | 0 | Shift along the trigger's edge, in pixels. |
shouldFlip | boolean | true | Flip to the other side when it doesn't fit. |
isOpen | boolean | — | Controlled open state, for popovers without a DialogTrigger. |
onOpenChange | (isOpen: boolean) => void | — | Called when it opens or closes. |
triggerRef | RefObject<Element | null> | — | Element to anchor to when there's no DialogTrigger, for example a table cell. |