component
Popover
A small plate that opens over the page with more about something, and closes when you click away. Card's grey, with an edge and the floating shadow.
Paid on 4 November, by bank transfer.
Defaultimport { Popover } from 'rost/components/popover/Popover'
<button popovertarget="paid">Paid</button>
<Popover id="paid">
<Text variant="paragraph" tone="secondary">Paid on 4 November, by bank transfer.</Text>
</Popover> src/components/popover/Popover.tsx
import type { HTMLAttributes, ReactNode } from 'react'
import './popover.css'
export interface PopoverProps extends HTMLAttributes<HTMLDivElement> {
/** What its button points at with `popovertarget`. */
readonly id: string
/** Draws the plate in place, always open, for previews. */
readonly preview?: boolean
/** As wide as what it holds, with no 280px limit. For a Calendar, not for words. */
readonly fit?: boolean
readonly children?: ReactNode
}
const b = 'rost-popover'
/**
* A small plate that opens over the page. The browser's popover: a
* `<button popovertarget={id}>` opens it, Esc and a click outside close it.
* Where it sits is the page's job. Built from contracts/popover.contract.yaml.
*/
export function Popover({ id, preview = false, fit = false, children, className, ...rest }: PopoverProps) {
const cls = [b, fit && `${b}--fit`, className].filter(Boolean).join(' ')
const panel = <div className={`${b}__panel`}>{children}</div>
if (preview) return <div id={id} className={cls} {...rest}>{panel}</div>
return <div id={id} popover="auto" className={cls} {...rest}>{panel}</div>
}
The source for everything on this page: contracts/popover.contract.yaml (opens in a new tab). The CSS, the docs and the checks in each app are built from it.
# yaml-language-server: $schema=../schema/component-contract.schema.json
schemaVersion: 2
id: popover
name: Popover
kind: component
status: review
summary: A small plate that opens over the page with more about something, and closes when you click away. Card's grey, with an edge and the floating shadow.
category: surfaces
related: [ tooltip, dialog, menu ]
source:
tool: figma
fileKey: 1Zy0wiWKXQAvsfDBX3KR0d
nodeId: "738:48"
url: https://www.figma.com/design/1Zy0wiWKXQAvsfDBX3KR0d/UI-Kit-v01?node-id=738-48
extractedAt: "2026-11-16"
extractedBy: hand
frozenAt: "2026-11-16"
props:
id: { type: string, required: true, notes: "What the button that opens it points at, with `popovertarget`." }
children: { type: slot, notes: "A few lines, a small form, a list of links." }
fit: { type: boolean, default: false, notes: "As wide as what it holds, with no 280px limit. For a Calendar or a small table, not for words." }
elements:
root:
notes: "The browser's popover (`popover=\"auto\"`), with its own look taken away. The browser shows it, hides it and closes it on Esc or a click outside. Where it sits is the page's job."
styles:
padding: { token: spacing/gap/none, value: 0px }
border: { value: none, assert: false }
background: { value: transparent, assert: false }
overflow: { value: visible, assert: false }
color: { value: inherit, assert: false }
inset: { value: auto, assert: false, notes: "The browser centres a popover in the window. Rost places it at its button instead." }
margin: { token: spacing/gap/none, value: 0px }
margin-block-start: { token: spacing/gap/small, value: 8px, notes: "8px clear of the button." }
position-area: { value: block-end span-inline-end, assert: false, notes: "Under the button that opened it, lined up with its start. A popover opened with `popovertarget` is anchored to that button by the browser." }
position-try-fallbacks: { value: "flip-block, flip-inline", assert: false, notes: "Above the button when there's no room below, and the other way along when there's no room at the end." }
panel:
notes: "The plate: 16px inside, as wide as what it holds up to 280px."
styles:
display: { value: block, assert: false }
max-width: { value: 280px, notes: "About a sentence and a half of paragraph text a line." }
padding: { token: spacing/gap/medium, value: 16px }
border-radius: { token: spacing/radius/large, value: 16px }
background: { token: popover/background, value: "#171717" }
outline-style: { value: solid, assert: false }
outline-width: { token: spacing/outline/small, value: 1px }
outline-offset: { value: "calc(-1 * var(--spacing-outline-small))", untokenised: "Composed from a token: the edge sits inside the plate." }
outline-color: { token: popover/edge, value: "#3a3a3a" }
box-shadow: { token: shadow/floating, value: "0px 16px 24px 0px rgba(0, 0, 0, 0.16)", notes: "The kit's only drop shadow, for things that float above the page." }
variants:
- when: { fit: true }
elements:
panel:
max-width: { value: none, assert: false, notes: "A Calendar is 280px before the 16px each side. Words still wrap at 280px without `fit`." }
guidance:
status: proposed
use:
- title: More about something
text: "How a figure was worked out, the details of a payment, a few settings for one column."
avoid:
- title: A word of explanation
text: "A label for an icon or a few words on hover. That's **Tooltip**."
- title: Something that has to be answered
text: "If the page should wait for it, that's **Dialog**."
- title: Actions
text: "A list of things to do. That's **Menu**."
behaviour: |-
It's the browser's popover: a button with `popovertarget` opens and closes it, Esc and a click outside close it, and only one is open at a time. It adds no type of its own, like Card. It opens under its button, lined up with its start, and moves above it or the other way along when it doesn't fit: CSS anchor positioning, with the button as the anchor. A browser without anchor positioning puts it at the top left of the window, so check the browsers your app supports.
accessibility:
element: "A `<div popover>`, opened by a `<button popovertarget>`. The browser links the two for screen readers."
name: "Give it an `aria-label` or a heading inside when it's more than a sentence."
keyboard: "Enter or Space on its button opens it. Esc closes it and puts focus back on the button."
colour: "Text inside keeps the page's tokens and their contrast on the #171717 plate."
Install
npx github:Runceanu/rost add popover It lands in src/rost/popover/, with what it needs and its contract. Install has the rest.
When to use
More about something
How a figure was worked out, the details of a payment, a few settings for one column.
When not to use
A word of explanation
A label for an icon or a few words on hover. That's Tooltip.
Something that has to be answered
If the page should wait for it, that's Dialog.
Actions
A list of things to do. That's Menu.
Behaviour
It's the browser's popover: a button with popovertarget opens and closes it, Esc and a click outside close it, and only one is open at a time. It adds no type of its own, like Card. It opens under its button, lined up with its start, and moves above it or the other way along when it doesn't fit: CSS anchor positioning, with the button as the anchor. A browser without anchor positioning puts it at the top left of the window, so check the browsers your app supports.
Accessibility
- Element
A
<div popover>, opened by a<button popovertarget>. The browser links the two for screen readers. - Name
Give it an
aria-labelor a heading inside when it's more than a sentence. - Keyboard
Enter or Space on its button opens it. Esc closes it and puts focus back on the button.
- Colour
Text inside keeps the page's tokens and their contrast on the #171717 plate.
Props
| Prop | Type | Values | Default |
|---|---|---|---|
id | string | | |
children | slot | | |
fit | boolean | | false |
Values
Straight from the contract. Each value sits next to its token, because six tokens here all come out as #3a3a3a and the colour alone can't tell you which one is right.
Never changes
root
-
padding0pxspacing/gap/none -
margin0pxspacing/gap/none -
margin-block-start8pxspacing/gap/small
bordernone · backgroundtransparent · overflowvisible · colorinherit · insetauto · position-areablock-end span-inline-end · position-try-fallbacksflip-block, flip-inline
panel
-
max-width280pxno token yet -
padding16pxspacing/gap/medium -
border-radius16pxspacing/radius/large -
background#171717popover/background -
outline-width1pxspacing/outline/small -
outline-offsetcalc(-1 * var(--spacing-outline-small))on purpose: Composed from a token: the edge sits inside the plate. -
outline-color#3a3a3apopover/edge -
box-shadow0px 16px 24px 0px rgba(0, 0, 0, 0.16)shadow/floating
displayblock · outline-stylesolid
Only in some variants
These don't change: they're just set in some variants and not others.
Every variant
-
panel.max-widthnoneFigma frame size