Components · Menus, lists and dividers

Menu

A menu is the list surface that opens from a button or action (Dropdown menu) or from a Select field (Exposed dropdown menu). The two differ only in the element that opens the surface, so they share one component.

How to add a menu to a page. The file is components/css/menu.css.

Basic Usage

Link the shared stylesheet once per page. Never copy the rules into a page.

StepWhat to do
1. Link<link rel="stylesheet" href="/components/css/menu.css">. Both templates already have it.
2. MarkupA div.menu with a ul.menu__items[role="listbox"] of li.menu__item[role="option"] rows.
3. RowEach row has a span.menu__item-label and an empty span.menu__item-icon. Set aria-selected.
4. VariantsAdd menu--sm, menu--multi, menu--full or menu--none.
5. BehaviorChoosing, keyboard and closing belong to the opener. A Select field uses components/js/select-menu.js.


API

Classes

ClassUse
menuThe surface. Large, Select, middle-inset divider.
menu--smSmall rows.
menu--multiMulti Select: a circle on every row.
menu--fullFull-width divider.
menu--noneNo divider.
menu__itemsThe list. Scrolls after 14 rows.
menu__itemOne row.

Things to know

  • Breakpoint: Large rows are 40px below 769px and 48px from 769px. The CSS does this by itself.
  • The check icon is drawn with a pseudo-element; keep the menu__item-icon span empty.
  • Put a .list-item inside a row when it needs a leading element or trailing text.
  • The [data-state] selectors do nothing outside the documentation pages.

CSS / Tailwind

The component is one CSS file, shared by every page. Link it, never copy it. The CSS below is read from the file the page links, so it is always what you see.

CSS (components/css/menu.css)