Browse docs

Popover menu

A dropdown menu anchored to its trigger - native Popover API, CSS anchor positioning, @starting-style entry/exit animation.

stableSince 0.1.0

On this page
  1. Semantic HTML
  2. Rich menu rows
  3. Class contract
  4. Multiple menus
  5. Sidebar placement
  6. Tokens consumed
  7. Anchor positioning
  8. Enter / exit animation
  9. Accessibility
ExampleScroll inside to see moreOpen in a new page

The .pl-c-menu is a dropdown menu anchored to its trigger. It uses the native Popover API (top-layer rendering and light-dismiss) + CSS anchor positioning (tethered to the trigger) + @starting-style for a native enter/exit animation. No JavaScript is required for this disclosure pattern.

This component is deliberately not an ARIA menu. It is a simple disclosure containing ordinary links and buttons, so users move through its contents with Tab. Use Dropdown when an application needs the full menu-button interaction model (role="menu", arrow-key navigation, managed focus, and synchronized aria-expanded).

Semantic HTML

<div class="pl-c-menu">
  <button class="pl-c-button pl-c-menu__trigger" popovertarget="account-menu">
    Account
  </button>
  <div class="pl-c-menu__popover" id="account-menu" popover>
    <a href="#">Settings</a>
    <a href="#">Billing</a>
    <hr class="pl-c-menu__divider" />
    <button type="button" data-tone="danger">Sign out</button>
  </div>
</div>

The trigger’s popovertarget="id" opens the popover declaratively - no JS. The popover element MUST have the popover attribute.

Rich menu rows

Plain direct-child links and buttons work. For denser enterprise menus, use the optional .pl-c-menu__item* anatomy for icons, descriptions, shortcuts, and selected/current rows.

<div class="pl-c-menu__popover" id="reports-menu" popover>
  <a class="pl-c-menu__item" href="/reports" aria-current="page">
    <svg class="pl-c-menu__item-icon" aria-hidden="true">...</svg>
    <span class="pl-c-menu__item-body">
      <span class="pl-c-menu__item-label">Overview</span>
      <span class="pl-c-menu__item-description">Executive KPI rollup</span>
    </span>
    <kbd class="pl-c-menu__item-shortcut">R</kbd>
  </a>
  <button class="pl-c-menu__item" type="button" data-tone="danger">
    Delete report
  </button>
</div>

Rows can be real <a> or <button> elements. [aria-current], [aria-selected="true"], and [data-selected] get the selected/current treatment; [data-tone="danger"] gets destructive color.

Class contract

Selector Role
.pl-c-menu The wrapper (inline-block).
.pl-c-menu__trigger The opening button and implicit popover anchor.
.pl-c-menu__popover The popover element.
.pl-c-menu__item Optional row class for links/buttons.
.pl-c-menu__item-icon Leading icon slot.
.pl-c-menu__item-body Label + description stack.
.pl-c-menu__item-label Truncated primary row text.
.pl-c-menu__item-description Secondary row text.
.pl-c-menu__item-shortcut Trailing keyboard shortcut or hint.
.pl-c-menu__divider A horizontal rule between item groups.
Items <a>, <button> Direct children of .pl-c-menu__popover.
[data-tone="danger"] Destructive item (danger-text / danger-bg on hover).
[data-placement="inline-end"] Sidebar/flyout placement beside the trigger.

Multiple menus

Each popover needs a unique HTML id matched by its trigger’s popovertarget. The browser anchors each popover to its own trigger, including when a page has many menus. No per-instance CSS anchor name is needed:

<div class="pl-c-menu">
  <button class="pl-c-button pl-c-menu__trigger" popovertarget="menu-a">
    Menu A
  </button>
  <div class="pl-c-menu__popover" id="menu-a" popover>...</div>
</div>
<div class="pl-c-menu">
  <button class="pl-c-button pl-c-menu__trigger" popovertarget="menu-b">
    Menu B
  </button>
  <div class="pl-c-menu__popover" id="menu-b" popover>...</div>
</div>

For an intentionally different named anchor, set --pl-c-menu-anchor on the component root; this overrides the implicit association. When opening a popover programmatically, pass its trigger as showPopover({ source: trigger }).

Use data-placement="inline-end" for desktop sidebar or icon-rail flyouts. This changes the anchor position from below the trigger to beside it.

<div class="pl-c-menu" data-placement="inline-end">...</div>

Tokens consumed

--pl-color-{surface,surface-2,border,text,danger-bg,danger-text}, --pl-focus-color, --pl-shadow-3, --pl-radius-{lg,sm}, --pl-space-{1,2,3}, --pl-duration-2, --pl-ease-standard, --pl-overlay-popover-bg, and --pl-menu-row-*.

Anchor positioning

Anchor positioning is @supports-gated. Chrome 149+ tethers the popover to the trigger’s block-end span-inline-end corner via position-area. Browsers without anchor support fall back to the UA’s default centering. inset: auto resets the UA centering so the anchor positioning takes over.

Enter / exit animation

The popover animates with @starting-style (opacity + translateY) and transition-behavior: allow-discrete on overlay/display so the exit transition runs (normally display: none kills transitions instantly).

Accessibility

  • Keyboard: Tab to the trigger and Enter/Space to open. Continue with Tab to reach the links and buttons. Esc closes the popover; light-dismiss (click outside) also closes it.
  • Focus management: a non-modal popover does not trap focus. The browser handles declarative opening and closing, but an app that needs menu-style initial focus, arrow keys, or deterministic focus return must implement the menu-button contract described by Dropdown.
  • Items: each item is a real <a> or <button> (full-width, keyboard-focusable, semantic role).
  • Forced colors: border falls back to ButtonBorder, focus to Highlight.

Search Porchlight