popover
onChange called 0 time(s)
import { lucide, popover } from '@markless/ui';export default function PopoverBasic() @{ <popover.root class="popover"> <popover.trigger class="button share"> <lucide.share2 class="icon" aria-hidden="true" /> Share </popover.trigger> <popover.content class="panel"> <popover.title class="title">Share this page</popover.title> <popover.description class="description">Anyone with the link can read it.</popover.description> <input class="field" value="markless.dev/ui/popover" readonly aria-label="Link" /> <popover.close class="button done">Done</popover.close> </popover.content> </popover.root>;}
.popover { display: grid; justify-items: center; align-content: start; min-height: 16.5rem; font-family: 'Shantell Sans', system-ui, sans-serif; font-size: var(--step--1); line-height: 1.5; color: var(--ink);}.button { display: inline-flex; gap: 0.5em; align-items: center; padding: 0.45em 0.9em; border: 1px solid var(--ink); border-radius: 6px; background: var(--paper); color: var(--ink); font: inherit; font-family: 'Shantell Sans', system-ui, sans-serif; cursor: pointer; transition: background 140ms ease;}.button:hover { background: color-mix(in srgb, var(--purple) 16%, var(--cream)); html.dark & { --ink: var(--on-accent); color: var(--on-accent); }}.button:active,.share[ui-open] { background: color-mix(in srgb, var(--purple) 26%, var(--cream)); html.dark & { --ink: var(--on-accent); color: var(--on-accent); }}.button:focus-visible,.field:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px;}.icon { width: 1em; height: 1em; flex: none;}.panel { z-index: 5; display: grid; gap: 0.6em; box-sizing: border-box; width: min(19rem, calc(100vw - 4rem)); margin-block-start: 0.6em; padding: 1em 1.1em; border: 1px solid var(--ink); border-radius: 6px; background: var(--raised); box-shadow: 3px 3px 0 color-mix(in srgb, var(--purple) 45%, var(--cream));}.panel[hidden] { display: none;}.title { margin: 0; font-family: 'Joy Elia', system-ui, sans-serif; font-size: var(--step-0); font-weight: 400; line-height: 1.2; text-shadow: none;}.description { margin: 0; font-family: 'Shantell Sans', system-ui, sans-serif;}.field { padding: 0.4em 0.65em; border: 1px solid var(--ink); border-radius: 6px; background: var(--paper); color: var(--ink); font: inherit; font-family: var(--font-mono); font-size: 0.9em;}.done { justify-self: end;}@media (prefers-reduced-motion: reduce) { .button { transition: none; }}
Press Share to open the panel. Press it again, press Escape, or click outside to close it.
popover is a panel that a button opens next to itself. Use it for a small task, such as a share
link or a filter. The rest of the page stays usable.
A popover is not modal. It writes no aria-modal, and it makes nothing inert. Focus stays where it
was, so Tab walks into the panel and back out again.
Anatomy
The popover itself; the trigger and the surface go inside it.
popover.rootholds whether the panel shows.popover.triggeris a<button>that opens and closes the panel.popover.contentis the panel. It writesrole="dialog", and it carrieshiddenwhile closed.popover.titleis an<h2>. It gives the panel its name.popover.descriptionis a<p>. A screen reader reads it after the name.popover.closeis a<button>that closes the panel and puts focus back on the trigger.
The root, the trigger and the panel write ui-open while the panel shows. They write ui-closed
while it does not.
Keyboard
| Key | What it does |
|---|---|
| Enter or Space | Opens or closes the panel from the trigger. |
| Escape | Closes the panel. If focus was inside it, focus goes back to the trigger. |
| Tab | Walks into the panel and out again. Nothing traps focus. |
A press outside the panel closes it, and focus stays where the person pressed. A press inside the panel never closes it. Opening a second popover closes the first.
Put the panel somewhere else
By default the panel sits below the trigger. The family places it with CSS anchor positioning, so
no script measures the page. That default lives in @layer markless. One plain rule of yours beats
it, with no specificity fight:
.share-surface {
position-area: inline-end;
}The panel also gets --ui-anchor, which holds the trigger's anchor name. Use it with anchor() for
your own placement math. The tests check that inline-end follows the writing direction in
right-to-left text.
Name the panel
popover.title names the panel, and popover.description describes it. Leave both out and the
panel has no name. The family then writes no aria-labelledby and no aria-describedby.
Render popover.title and it names the panel: the content points aria-labelledby at it, with no prop. VoiceOver and NVDA both read that name, on focus and on a walk, wherever the surface sits on the page. Use aria-label on popover.content only when there is no title. With a title rendered, aria-labelledby outranks aria-label in the accessible name, so an aria-label beside a title changes nothing.
<popover.content>
<popover.title>Share this page</popover.title>
<popover.description>Anyone with the link can read it.</popover.description>
</popover.content>Know when it closes
onChange gets the new value each time the panel opens or closes. Escape and a press outside
call it too.
<popover.root open={showing} onChange={onShowingChange}>API
Every prop is optional. The types are the family's own.
popover.root
| Prop | Type | What it does |
|---|---|---|
open |
boolean |
Whether the panel shows. Omit it and the popover starts closed. |
onChange |
(open: boolean) => void |
Gets the new value when the popover opens or closes. Escape and outside presses count. |
| Attribute | Present when | Use it for |
|---|---|---|
ui-open |
The panel shows. | The open look. |
ui-closed |
The panel does not show. | The resting look. |
The root passes anything a <div> accepts to its element, except onChange.
| Selector | Default | Why |
|---|---|---|
div:not([overlay]) |
anchor-scope: --ui-popover |
Keeps the anchor name inside this popover. Two popovers never use each other's trigger. |
popover.trigger
It has no props of its own. It renders a <button> and passes on anything a <button> accepts.
Your own onClick runs after the popover opens or closes.
| Attribute | Present when | Use it for |
|---|---|---|
aria-haspopup |
Always | dialog. It is for screen readers, not CSS. |
aria-expanded |
Always | true or false. |
aria-controls |
Always | The id of the panel this button opens. |
ui-open |
The panel shows. | The pressed look. |
ui-closed |
The panel does not show. | The resting look. |
| Selector | Default | Why |
|---|---|---|
button[aria-haspopup] |
anchor-name: --ui-popover |
The trigger is the anchor the panel sits against. |
popover.content
It renders a <div> and passes on anything a <div> accepts. Your own onDismiss runs after the
family closes the popover.
| Prop | Type | What it does |
|---|---|---|
aria-label |
string |
The panel's name when it has no popover.title. A title outranks it. |
| Attribute | Present when | Use it for |
|---|---|---|
overlay |
Always | The mark that lifts the panel above the page. It is not for CSS. |
role |
Always | dialog. |
aria-labelledby |
A popover.title exists. |
The id of the popover.title. |
aria-describedby |
A popover.description exists. |
The id of the popover.description. |
hidden |
The popover is closed. | It hides the panel. The panel stays in the page, so ids and focus survive. |
ui-open |
The panel shows. | The shown look. |
ui-closed |
The panel does not show. | The hidden look. |
| Selector | Default | Why |
|---|---|---|
[overlay] |
--ui-anchor: --ui-popover; position: absolute; position-anchor: --ui-popover; position-area: block-end |
Places the panel below the trigger with no script. It also hands you the anchor name. |
popover.title
It has no props of its own. It renders an <h2> and passes on anything an <h2> accepts.
popover.description
It has no props of its own. It renders a <p> and passes on anything a <p> accepts.
popover.close
It has no props of its own. It renders a <button> and passes on anything a <button> accepts.
It closes the panel and puts focus back on the trigger. Your own onClick runs after that.