Menu
A dropdown of actions anchored to a button.
mq-menu is a compound primitive modelled on Base UI's Menu: a trigger in
slot="trigger" and one mq-menu-item per action. It ships from
@mediquo/ui as custom elements and as React components.
Install
// Custom elements — the import registers <mq-menu> and <mq-menu-item>
import "@mediquo/ui/components/menu";// React
import { Menu, MenuItem } from "@mediquo/ui/react/menu";
<Menu label="Más opciones" side="top" align="end">
<button slot="trigger">Opciones</button>
<MenuItem onClick={reschedule}>Modificar cita</MenuItem>
<MenuItem variant="negative" onClick={cancel}>
Anular cita
</MenuItem>
</Menu>;Positioning
- The popup renders in the browser's top layer (Popover API), so an ancestor
with
overflow: hiddenor atransformcannot clip it, and noz-indexis needed. - It opens on
side(defaultbottom) and flips to the other side when only that one has room.align(defaultstart) lines up an edge with the trigger, then the popup shifts so it stays 8px inside the viewport. - It follows the trigger on scroll and resize while open.
- Browsers without the Popover API (before Safari 17 and Chrome 114) fall back
to
position: fixed: it still stays inside the viewport, but a transformed ancestor can clip it.
Accessibility
It implements the WAI-ARIA menu button pattern.
- The popup is
role="menu"andlabelis its accessible name; each item isrole="menuitem". - The trigger gets
aria-haspopup="menu"and anaria-expandedthat followsopen. A native<button>takes the attributes directly;mq-buttonforwards them to its inner button. - Enter, Space and
ArrowDownopen on the first item,ArrowUpon the last. A mouse or touch click focuses the menu itself, so no item is highlighted until the pointer moves over one or an arrow key is pressed. Arrows move between items and wrap;HomeandEndjump to the ends. - Enter or Space on an item runs it. Running an item or pressing
Escapecloses the menu and gives focus back to the trigger.Tabcloses it and moves on from the trigger. - A pointer down outside closes it and leaves focus where it was.
- The mouse moves focus to the item under it, so the keyboard and the pointer never highlight two items at once.
Motion
Like shadcn's dropdown: it opens with a fade, a zoom from 95% and a short
slide away from the trigger, and closes with a fade and zoom back, in 150ms.
With prefers-reduced-motion it only fades.
Behaviour worth knowing
- Listen to
clickon each item for its action; the menu closes itself afterwards, so there is no open state to reset. onopenchangefires only for user-driven changes. Settingopenyourself does not emit it.
Styling
::part(popup)styles the popup (background, border, radius, shadow,min-width).mq-menu-itemcan be styled directly from the surrounding scope;::part(item)reaches its padding.variant="negative"uses--mq-feedback-error-strong.