Menus

On this page

A menu puts several actions behind one button: the actions for a row, bulk actions for a list, or the less common actions on a detail page. The kit opens, closes and positions it, and handles the keyboard.

An open menu with a label, items, a divider and a destructive itemAn open menu with a label, items, a divider and a destructive item

Figure 1: An open menu with a group label, two actions, a divider and a destructive action

<div class="ph-menu-wrap">
  <button type="button" class="ph-btn" data-ph-menu="order-menu">Actions</button>
  <div class="ph-menu ph-menu--end" role="menu" id="order-menu" hidden>
    <div class="ph-menu-label">Orders</div>
    <button type="button" role="menuitem">Export CSV</button>
    <button type="button" role="menuitem">Refresh</button>
    <div class="ph-menu-sep" role="separator"></div>
    <button type="button" role="menuitem" class="ph-menu-item--danger">Clear history…</button>
  </div>
</div>
Class or attributeWhat it does
.ph-menu-wrapWraps the trigger and the menu so the menu opens under the trigger
data-ph-menu="<id>"On the trigger: opens the menu with that id
.ph-menuThe menu. Give it role="menu", an id and hidden.
.ph-menu--endLines the menu up with the trigger's right edge (for triggers near the right of the page)
role="menuitem"Each action (a <button> or <a>)
.ph-menu-labelA small heading for a group of items
.ph-menu-sepA divider between groups
.ph-menu-item--dangerRed text for destructive actions

Keyboard

KeyOn the triggerIn the open menu
Click, Enter or SpaceOpens or closes the menuChooses the item and closes the menu
Down arrow / Up arrowOpens the menuMoves to the next / previous item
Home / EndMoves to the first / last item
EscCloses the menu and returns focus to the trigger
TabCloses the menu

Clicking outside also closes it. Disabled items (disabled or aria-disabled="true") are skipped. The kit sets aria-haspopup, aria-expanded and aria-controls on the trigger.

Guidelines

  • An icon-only trigger ("More actions", three dots) needs an aria-label.
  • End an item's label with "…" when it opens a dialog or asks for confirmation.
  • Put destructive items last, after a divider, and confirm them.
  • Don't put the page's primary action in a menu.