Dropdown menu
BetaNavigationOpen in the workshop
A short list of actions behind a button: row actions, “more”, the account menu.
.xg-dropdown[data-xg-dropdown] > button[aria-haspopup="menu"][aria-expanded] + ul.xg-menu[role=menu][hidden] > li > button.xg-menu__item[role=menuitem] · --danger · .xg-menu__sep · .xg-menu__labelExample and markup
Live, from xg-ui.css and xg-ui.js. Switch the brand and mode on the example itself, or for the whole site in the header.
Markup
<div class="xg-dropdown" data-xg-dropdown>
<button class="xg-btn xg-btn--secondary" type="button" aria-haspopup="menu" aria-expanded="false">Actions <svg class="xg-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<path d="m6 9 6 6 6-6"/>
</svg>
</button>
<ul class="xg-menu" role="menu" hidden>
<li role="none">
<button class="xg-menu__item" role="menuitem" type="button">
<svg class="xg-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<path d="M4 20h4L19 9a2.8 2.8 0 0 0-4-4L4 16v4Z"/>
<path d="m13.5 6.5 4 4"/>
</svg>Edit <kbd class="xg-kbd">E</kbd>
</button>
</li>
<li role="none">
<button class="xg-menu__item" role="menuitem" type="button">
<svg class="xg-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<rect x="8" y="8" width="13" height="13" rx="2"/>
<path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3"/>
</svg>Duplicate</button>
</li>
<li role="none">
<button class="xg-menu__item" role="menuitem" type="button">
<svg class="xg-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<rect x="6" y="5" width="4" height="14" rx="1"/>
<rect x="14" y="5" width="4" height="14" rx="1"/>
</svg>Pause</button>
</li>
<li role="separator" class="xg-menu__sep">
</li>
<li role="none">
<button class="xg-menu__item xg-menu__item--danger" role="menuitem" type="button">
<svg class="xg-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<path d="M4 7h16"/>
<path d="M10 11v6"/>
<path d="M14 11v6"/>
<path d="M6 7l1 13h10l1-13"/>
<path d="M9 7V4h6v3"/>
</svg>Delete</button>
</li>
</ul>
</div>States
Hover, focus and pressed are forced here with .is-hover, .is-focus and .is-active so they can be seen side by side; in a product they come from :hover, :focus-visible and :active.
| State | Menu item |
|---|---|
| Default | |
| Hover / focus | |
| Danger | |
| Disabled |
Variants
Markup
<ul class="xg-menu" role="menu" aria-label="Example" style="max-width:240px">
<li class="xg-menu__label" role="presentation">Campaign</li>
<li role="none">
<button class="xg-menu__item is-hover" role="menuitem" type="button">
<svg class="xg-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<path d="M4 20h4L19 9a2.8 2.8 0 0 0-4-4L4 16v4Z"/>
<path d="m13.5 6.5 4 4"/>
</svg>Edit</button>
</li>
<li role="none">
<button class="xg-menu__item" role="menuitem" type="button">
<svg class="xg-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<rect x="8" y="8" width="13" height="13" rx="2"/>
<path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3"/>
</svg>Duplicate</button>
</li>
<li role="none">
<button class="xg-menu__item" role="menuitem" type="button" aria-disabled="true">
<svg class="xg-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<path d="M7 4.5v15l12-7.5-12-7.5Z"/>
</svg>Resume</button>
</li>
<li role="separator" class="xg-menu__sep">
</li>
<li role="none">
<button class="xg-menu__item xg-menu__item--danger" role="menuitem" type="button">
<svg class="xg-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<path d="M4 7h16"/>
<path d="M10 11v6"/>
<path d="M14 11v6"/>
<path d="M6 7l1 13h10l1-13"/>
<path d="M9 7V4h6v3"/>
</svg>Delete</button>
</li>
</ul>When to use it
Use it for
secondary actions on one object; switching account or brand.
Not for
choosing a form value (Select); navigation with many items.
Rules
- Destructive items last, after a separator, in danger color, and confirmed.
- Keyboard shortcuts on the right as .xg-kbd.
- Seven items at most.
Accessibility
- Menu button pattern: Enter/Space/↓ opens and focuses the first item, arrows move, Escape closes and returns focus.
Every color pair this component uses is measured for both brands in light and dark on the Accessibility page.
Related
Also in Navigation: Sidebar navigation, Topbar, Tabs, Breadcrumb, Wizard steps. Used in the patterns Reporting table.
Status Beta: usable; class names may still change in a minor release, with a note (see Releasing).