Popover

A popover opened by a button

The button names the popover's id in popovertarget. A click outside or Escape closes it, and opening another popover closes this one. The popover lines up with the start of the button, below it.

Card fees

Charged per transaction.

2.9% + $0.30

Side: below, above, left and right of the button

data-side on the popover. When the popover does not fit, it flips to the opposite side.

Bottom

Opens below the button. The default.

Top

Opens above the button.

Left

Opens to the left of the button.

Right

Opens to the right of the button.

Alignment: start, center and end of the button

data-align: for a popover on the left or right, start is the top edge of the button and end its bottom edge.

Start

Lines up with the start of the button. The default.

Center

Centred on the button.

End

Lines up with the end of the button.

Side and alignment together

Top, end

Above the button, lined up with its end.

Right, center

Right of the button, centred on it.

A header with a count: a badge after the title sits on the same row

In the popover's <header> the title and a badge share a row; a <p> after them takes its own line.

Products in cart

3

Timeless Watch

Ceramic Mug

Wooden Stool

API

Methods (native)

Member Type Description
showPopover() method Opens the popover; any other open auto popover closes.
hidePopover() method Closes the popover.
togglePopover(force?) method Opens it when closed, closes it when open; force picks one. Returns the new state.
:popover-open CSS Matches while it is open: el.matches(":popover-open").

Events (native)

Event Detail Description
beforetoggle oldState, newState ("open" / "closed") Before it opens or closes; preventDefault() stops an opening.
toggle oldState, newState After it has opened or closed.

Keyboard

Key Description
Enter / Space On the button: opens or closes the popover.
Tab From the button into the popover, which comes next in the focus order.
Esc Closes the popover only; a dialog around it stays open.

No script. Without CSS anchor positioning the browser shows the popover in the middle of the window.

Attributes

Attribute / element Values Description
class="popover" on the panel The component: a bordered panel up to 20rem wide.
popover none or auto (default), manual auto closes on an outside click, Escape, or another popover; manual only by its button.
id unique id What the button's popovertarget names.
popovertarget the popover's id On the button; also makes it the anchor the popover is placed against.
popovertargetaction toggle (default), show, hide What a click on the button does.
data-side none or bottom (default), top, left, right Flips to the other side when it does not fit.
data-align none or start (default), center, end Start/end: left/right edge below or above; top/bottom edge on the left or right.
> header h3, .badge, p Title and count on one row, description below.
autofocus on a control in the popover Takes focus when the popover opens.