domestic-ui GitHub

Popover

Content shown on top of the page from a button, with the popover attribute.

Where popovers are used A popover opens from a button, such as Share beside the page heading, as a small panel on top of the page under the button.

Live example

Popover

<button type="button" popovertarget="share-popover">Share</button>
<div id="share-popover" popover data-popover>
  <p>Anyone with the link can view this page.</p>
</div>

Above the button, with a close button

<button type="button" popovertarget="help-popover">Help</button>
<div id="help-popover" popover="manual" data-popover="block-start">
  <p><strong>Need a hand?</strong></p>
  <p>Read the <a href="#above-title">guide</a> or ask in the forum.</p>
  <button type="button" popovertarget="help-popover" popovertargetaction="hide" data-button="small">Close</button>
</div>

Tooltip

<div class="cluster">
  <dui-tooltip>
    <button type="button" aria-describedby="save-tip">Save</button>
    <span id="save-tip" popover="hint" role="tooltip">Shortcut: Ctrl+S</span>
  </dui-tooltip>
  <dui-tooltip>
    <button type="button" aria-label="Copy link" aria-describedby="copy-tip" data-button="quiet">⧉</button>
    <span id="copy-tip" popover="hint" role="tooltip">Copies the page address</span>
  </dui-tooltip>
</div>

Attributes

Attribute or valueWhereEffect
data-popovera [popover] elementpanel look, anchored below the invoker, aligned to its start edge
data-popover="block-start | inline-start | inline-end"place it above or beside the invoker instead
role="tooltip"a [popover] elementtooltip look, placed above the trigger
popover="auto | manual | hint"native: auto light-dismisses, manual does not

Children: with a <nav> of links, the panel takes the menu's inset, so a <p> or heading, an <hr> and a <form> with a quiet button line up with the links (an account popover).

Positioning

A popover opened by popovertarget (or by showPopover() with a source) has its invoker as an implicit anchor, so position-area places it next to the button and position-try-fallbacks flips it when it would overflow. Inside @supports only; where anchor positioning is missing the popover sits centered at the bottom of the viewport, readable and clear of the content it belongs to.

Tooltip

role="tooltip" on a popover="hint" element, referenced from the trigger with aria-describedby. The APG Tooltip pattern is still marked as work in progress, so these rules come from it and from WCAG 1.4.13 Content on Hover or Focus:

  • A tooltip supplements the trigger's own accessible name; it is never the only label, because touch and some assistive technology users never see it;
  • It appears on keyboard focus as well as on hover;
  • Esc hides it without moving focus (dismissible), the pointer can move onto it without it closing (hoverable), and it stays until focus or the pointer leaves (persistent);
  • It holds no interactive content (use a popover for that).

HTML cannot show a popover on hover or focus yet: the interestfor attribute is the coming standard, shipped only in Chromium today. Until it is interoperable, the <dui-tooltip> web component (web-components/dui-tooltip.js) does the showing and hiding. popover="hint" does not close other open popovers; where "hint" is unsupported the attribute falls back to "manual" and the component still handles Esc.

Motion

A data-popover panel fades and grows from --dui-motion-zoom over --dui-motion-duration-fast, entering with --dui-motion-easing-enter and leaving with --dui-motion-easing-exit (@starting-style and transition-behavior: allow-discrete). The zoom runs for that duration times --dui-motion-movement, so reduced motion keeps only the fade (WCAG 2.3.3). Tooltips appear at once.

Elevation

Panels use --dui-elevation-popover and --dui-elevation-popover-surface; tooltips use the popover shadow on their inverse surface. The role's 1px ring draws the edge. Both keep a transparent border, which forced colors mode paints in place of the dropped shadow.

Keyboard

KeyAction
Enter / Spaceon a popover button, opens or closes the popover
Tabmoves into the open popover, then on through the page
Esccloses an auto popover and returns focus to its button
Tab to a tooltip triggershows its tooltip / Esc: hides it, focus stays

Accessibility

  • A popover does not trap focus. Decisions belong in a modal <dialog>. For actions, use the menu button.
  • A tooltip supplements the trigger's name, shows on focus and hover, and closes on Esc (WCAG 1.4.13; APG Tooltip is a draft).

Specifications

See also

How other systems do it

For comparison only; these are not the standard this system follows.

Search