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>;}

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

popover anatomy
Anatomy perspectiveFlat
Layers
Open detailsProject detailsA little more context.×
popover.root

The popover itself; the trigger and the surface go inside it.

  • popover.root holds whether the panel shows.
  • popover.trigger is a <button> that opens and closes the panel.
  • popover.content is the panel. It writes role="dialog", and it carries hidden while closed.
  • popover.title is an <h2>. It gives the panel its name.
  • popover.description is a <p>. A screen reader reads it after the name.
  • popover.close is 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.