Menu

updated

One menu to rule them all. A dropdown and a context menu in one component that attaches to whatever it sits in.

Demo

Open Props in the corner of the example to try size. It goes from xs to xl, and items match the height of an Input of the same size. A submenu takes its parent's size unless you give it its own.

Installation

Usage

<script setup lang="ts">
import { Button } from '@/components/ui/button'
import { Menu, MenuItem } from '@/components/ui/menu'
</script>

<template>
  <Button>
    Edit
    <Menu>
      <MenuItem @select="copy">Copy</MenuItem>
      <MenuItem @select="paste">Paste</MenuItem>
    </Menu>
  </Button>
</template>

Put Menu inside the element that opens it, and it attaches there. No trigger needed. It opens on click, or, with context-menu, on right-click and long press. One component, both menus.

v-model holds the open state, and show(), hide() and toggle() work from code. By default, a click outside only closes the menu. More on overlays.

  • MenuItem: an action; fires select and closes the menu
  • MenuCheckboxItem, MenuRadioGroup + MenuRadioItem: settings
  • MenuSub, MenuSubTrigger, MenuSubContent: submenus
  • MenuLabel, MenuGroup, MenuSeparator: structure
  • MenuShortcut: a key hint at the end, display only

Items look like Select's.

Examples

With a trigger

Prefer the classic shape? Put a MenuTrigger next to the Menu, and the menu attaches to the trigger instead of the parent. It renders a button, or your own element with as-child. Handy for a table row's actions.

With trigger

Touch position

With touch-position, the menu opens where you clicked, not at the target's edge.

Touch position
Click anywhere · Blue

Open state

While the menu is open, its target gets data-state="open", so you can style it with data-[state=open]:. Works for click and context menus alike.

Open state
  • Ada LovelaceNotes on the engine
  • Alan TuringA question about machines
  • Grace HopperFound a bug

Sizing

  • fit: at least as wide as the target
  • max-height, max-width: any CSS length; the menu scrolls past it
  • cover: sits on top of the target, at least its size
Sizing

Checkbox items

MenuCheckboxItem toggles a setting. Bind it with v-model.

Checkboxes

Radio group

MenuRadioItems inside a MenuRadioGroup pick one option. Bind the group with v-model.

Radio group

Mixing plain items with checkbox or radio items? Give the plain ones inset to line up the text.

Context menu

With context-menu, the menu opens at the pointer on right-click, or after a long press on touch screens. A right-click elsewhere closes it. With :modal="false", a right-click elsewhere in the target moves the menu there instead.

Context menu
Right-click or long-press here

Click and right-click on one element

One element, two menus: one on click, one on right-click with context-menu. Render both from one v-for, and you write the items once.

Shared

Last action: nothing yet

One menu for many targets

A menu doesn't have to live in every row. In the demo, 10,000 rows of a virtualized ScrollArea share one context menu on their container, and a contextmenu listener remembers which row was pressed.

target attaches the menu somewhere else: pass a CSS selector or an element. false attaches it to nothing, for a menu opened only from code: it opens in the middle of the viewport, or at the event's position when show(event) gets one with context-menu or touch-position.

Target

Last action: nothing yet

Virtualized items

The menu can hold a virtualized ScrollArea. Arrow keys move through the items, and more render as you reach the edge.

Virtual

Positioning

anchor picks a point on the target, self a point on the menu, and the menu moves so they meet. Each is a vertical part (top, center, bottom) plus a horizontal one (left, middle, right, or start and end, which follow the reading direction). The default, anchor="bottom start" with self="top start", opens below the target, aligned to its start.

offset pushes the menu away by [x, y] pixels. There's a 4px gap by default; :offset="[0, 0]" removes it.

Doesn't fit? It flips to the side with more room, shrinks and scrolls.

Positioning

Non-modal

With :modal="false", the page keeps scrolling while the menu is open, and another row's menu opens in one click instead of two.

Non-modal menu
  • Quarterly report.pdf
  • Roadmap.fig
  • Invoices.xlsx
  • Brand guide.pdf
  • Onboarding.docx
  • Budget 2027.xlsx
  • Release notes.md
  • Interview notes.docx
  • Pitch deck.key
  • Research.pdf
  • Contracts.zip
  • Wireframes.fig

API Reference

Every part takes a class that merges with its own. On Menu, it styles the panel.

Data attributes

data-slotAttributesDescription
menudata-state, data-sizeThe menu's panel, with role="menu". data-size is its size, xs to xl.
menu-scrim—The transparent layer under a modal menu that takes the first outside click.
menu-triggerdata-state, aria-expandedThe element a sibling Menu attaches to, when MenuTrigger is used; with as-child the child carries it.
menu-itemdata-highlighted, data-disabled, data-inset, data-colorAn item. data-color carries its color.
menu-checkbox-itemdata-state, data-highlighted, data-disabledA checkbox item. data-state is checked, unchecked or indeterminate.
menu-radio-itemdata-state, data-highlighted, data-disabledA radio item.
menu-labeldata-insetA label for the items after it.
menu-separator—A line between groups.
menu-shortcut—A key combination at the end of an item.
menu-sub-triggerdata-state, data-highlighted, data-insetThe item that opens a submenu.
menu-sub-contentdata-state, data-side, data-sizeA submenu's panel.

Changelog

  1. registry 0.23.0

    bc6008b — Exits now use the decelerating curve, like entrances. Collapsible, Accordion, the overlay surfaces (Popover, Select, Menu, Tooltip), Drawer, Toast and InnerLoading used to close on --ease-emphasized-accelerate, which holds still for most of its duration and then snaps shut; closing on --ease-standard-decelerate starts at once and settles gently, so the same duration feels faster. The tokens themselves are unchanged.

  2. core 0.17.0

    0107e40 — The scrollbar's space is kept only while an overlay locks scrolling, as Base UI does, instead of on every page. @kappa-ui/core/tailwind.css no longer sets html { scrollbar-gutter: stable }, so a page too short to scroll no longer shows an empty strip along its edge on Windows. Dialog, Drawer, Select, Menu, Popover and DatePicker set scrollbar-gutter: stable on <html> while the page is locked and it would otherwise scroll, and remove it afterwards; a gutter your stylesheet already reserves is left alone. Keep ConfigProvider with :scroll-body="false". Want the old always-on gutter? Add html { scrollbar-gutter: stable; } to your stylesheet.

    bc6008b — Exits now use the decelerating curve, like entrances. Collapsible, Accordion, the overlay surfaces (Popover, Select, Menu, Tooltip), Drawer, Toast and InnerLoading used to close on --ease-emphasized-accelerate, which holds still for most of its duration and then snaps shut; closing on --ease-standard-decelerate starts at once and settles gently, so the same duration feels faster. The tokens themselves are unchanged.

  3. registry 0.22.0

    0b8fe94 — MenuTrigger renders type="button", so a trigger inside a form opens its menu without submitting the form; with as-child the child keeps its own type.

    cd67d47 — A Menu with target: false opens centred in the viewport instead of half off its top-left corner (an anchor or self you pass still wins), and show(event) on such a menu with contextMenu or touchPosition opens at the event's position.

    ee25b0f — The modal scrim's hold renders a comment instead of a hidden <span>, and PopoverContent, DatePickerContent and Menu put it after their slot: PopoverContent as-child renders the consumer's element as the panel instead of moving the panel's role, classes and data-slot onto the hidden span, and a panel's first element child is the consumer's again.

    a751cf6 — ScrollArea measures its content in layout pixels, as it measures its viewport: under a scaled ancestor, and in a Dialog, Popover or Menu that opens with the default scale-in, the content was measured short for its whole life, so the thumb came out too long, the end fade dropped out and reachEdge fired early.

    3d564c4 — A long Select or Combobox list shows the browser's thin scrollbar, as Menu does, instead of scrolling with no visible sign. Reka hides it with an unlayered style, so the viewports set [scrollbar-width:thin]!; hiding it again takes an important class too, such as [&_[data-slot=select-viewport]]:[scrollbar-width:none]! on SelectContent or [scrollbar-width:none]! on ComboboxViewport.

  4. core 0.16.0

    ee25b0f — The modal scrim's hold renders a comment instead of a hidden <span>, and PopoverContent, DatePickerContent and Menu put it after their slot: PopoverContent as-child renders the consumer's element as the panel instead of moving the panel's role, classes and data-slot onto the hidden span, and a panel's first element child is the consumer's again.

  5. registry 0.21.0

    02e469f — MenuItem, MenubarItem and DrawerMenuItem take color instead of variant: variant="destructive" becomes color="destructive", and every other tone (primary, neutral, success, warning, info or one you declare on [data-slot][data-color="<name>"]) now works too. The item, its icon and its hover layer read --tone-text; data-variant is gone from the item and data-color carries the colour.

  6. registry 0.19.0

    adf96cd — Parts no longer style themselves from their root's size through group-data-[size=…] variants, which beat any plain class of yours. size is the density of the root, and a class on a part wins:

    - Card, Empty, Alert and Stepper: CardTitle, CardDescription, EmptyTitle, EmptyDescription, AlertTitle, AlertDescription, StepperTitle and StepperDescription keep one text size at every root size (title-md/body-md, title-sm/body-md for Alert, title-sm/body-sm for Stepper). Empty's icon and gaps and Stepper's indicator number still follow the size, through --empty-icon, --empty-header-gap, --empty-content-gap and --stepper-text on the root. - Menu and DrawerMenu labels, Menubar triggers and the Calendar heading, weekday cells and week numbers keep scaling with the size, through --menu-label, --menubar-text, --calendar-heading and --calendar-label (each with a -leading twin) set by the root. - AlertDialog size="sm" centres its text through the content, so text-start on AlertDialogHeader wins; the footer keeps its two-column grid.

  7. registry 0.15.0

    d09f26a — Pressable parts ripple on their own: Button, Toggle, ToggleGroupItem, Item as a link or a button, the calendar days, tabs, accordion, menubar and navigation menu triggers, the items of Menu, Menubar, Select, Combobox, Command, DrawerMenu, Listbox and Tree, and the clear buttons of TagsInput and Combobox. Each imports the directive from @/lib/ripple, so add brings the ripple item along and nothing needs registering. On menu, listbox and tree rows the wave replaces the pressed layer, as state-layer already did. Bind v-ripple="false" on a Button to turn one off, or set --kappa-ripple: none on :root to turn them all off.

  8. registry 0.13.0

    839ae3d — New Menubar: a desktop-style row of menus over Reka UI's Menubar, with the shadcn-vue parts (MenubarMenu, MenubarTrigger, MenubarContent, MenubarItem, MenubarCheckboxItem, MenubarRadioGroup, MenubarRadioItem, MenubarItemIndicator, MenubarLabel, MenubarSeparator, MenubarShortcut, MenubarGroup, MenubarSub, MenubarSubTrigger, MenubarSubContent) and Menu's items, five sizes and state layers. size sets the triggers and every menu from xs to xl; variant is outline, soft or ghost. The arrow keys wrap by default, v-model is typed as the open menu's value, long menus scroll inside the viewport, and a few Reka gaps are closed: moving to an earlier menu with the arrows or the pointer no longer closes the whole bar, Tab from an open menu continues from the bar instead of the end of the page, a menu open on first render is linked to its trigger by aria-controls, and preventDefault() in @close-auto-focus keeps focus off the trigger.

    93e57a0 — Every size on the control scale is named xs to xl; default and the bare icon are gone. To move over:

    - Button: size="default" becomes size="md", or leave size out; size="icon" becomes size="icon-md". The full set is xs to xl and icon-xs to icon-xl. Toggle, ToggleGroup, ToggleGroupItem, the Toolbar parts, AlertDialogAction, AlertDialogCancel and ToastAction take the same names; Button, Toggle and ToggleGroup default to md, the Toolbar parts keep sm and ToastAction keeps xs. InputGroupButton keeps its own xs, sm, icon-xs and icon-sm, 24 and 32px to fit inside the group, xs by default. Pagination hands its md to Button as it is. Button, Toggle and ToggleGroupItem set data-variant, data-color and data-size even when you leave them at their defaults. - AlertDialogContent: size="default" becomes size="md", still the default; sm is unchanged. The size option of useConfirm's confirm, alert and prompt takes the same names. - Table and DataTable: density becomes size, data-density becomes data-size, and the TableDensity type is now TableSize. sm, md and lg keep their 36, 44 and 52px rows; xs (28px) and xl (60px) are new, and DataTable's virtual row estimates cover them. The cells' padding above and below the text is now --table-cell-py on the table: 8px as before, 3px at xs. At xs, DataTable's sort buttons and expand and group toggles shrink to fit the row. The table-density example is now table-sizes. - DrawerMenu: size takes xs to xl like Menu and reads the control scale, plus room for a thumb. sm, md and lg keep their 40, 48 and 56px rows, padding and icons; xs is 36px and xl 64px. Overriding a --control-* token on :root now resizes DrawerMenu rows as well. - Select and Combobox: the list opens at the trigger's or anchor's size instead of always at md, so <SelectTrigger size="xl"> opens an xl list. size on SelectContent or ComboboxList picks another. Behind an as-child button, set size on ComboboxAnchor to match the button. The Select list now sets its menu variables on SelectContent instead of its viewport, so a class such as [--menu-item-height:2.5rem] on SelectContent reaches the items. - Input, Textarea, InputFloating, SelectTrigger, ComboboxAnchor and Separator set data-size with the default filled in, and the anchor sets data-variant too. With as-child, the anchor leaves the button's own data-variant and data-size alone.

  9. registry 0.12.0

    c79028b — The control scale is now a set of tokens: --control-height-*, --control-padding-*, --control-icon-* and --control-gap-* for xs to xl, added to :root by the tokens item. Button, Input, InputFloating, Select, Combobox, InputNumber, TagsInput, PinInput, InputTime, InputGroup, Menu, Tabs, ColorPicker and Pagination read them, so overriding one on :root resizes every control of that size.

    Some sizes that strayed from the scale now follow it. Button icons are 20px at lg and xl instead of 16px, and so are the icons of Toggle, ToggleGroup, Toolbar and Pagination at those sizes. The gap between an icon and its label is 6, 8, 8, 10 and 12px from xs to xl, about half the icon, everywhere that has one: Button and the components built on it (where it was 4, 6, 8, 8 and 8px), Menu items and the Select, Combobox and Command lists (8, 10, 12, 12 and 12px), and Tabs triggers (6, 8, 8, 8 and 10px). Inset and checkbox or radio items move their labels with it, so they stay in line with items that have an icon. Everything else keeps its size.

  10. registry 0.10.0

    8f31bd2 — New Command: a filterable list of commands over Reka UI's Listbox, ported from shadcn-vue, in Menu's five sizes: CommandInput, CommandList, CommandEmpty, CommandGroup, CommandLabel, CommandItem, CommandSeparator, CommandShortcut and CommandDialog.

    0a9aa94 — DropdownMenu and ContextMenu are removed: Menu covers both, opening on click from the element it sits in or from a MenuTrigger, and with context-menu on right-click and long-press. It has the same parts (MenuItem, MenuCheckboxItem, MenuRadioGroup, MenuRadioItem, MenuLabel, MenuSeparator, MenuShortcut, MenuGroup, MenuSub, MenuSubTrigger, MenuSubContent), sizes and styles, so moving over means renaming the parts and replacing DropdownMenuTrigger/ContextMenuTrigger and the content part with a Menu inside the element that opens it; align="end" becomes anchor="bottom end" self="top end". Copies already in a project keep working. The Breadcrumb, ButtonGroup, DrawerMenu and overlay examples use Menu.

    93791d7 — A Menu with context-menu marks its target with data-kappa-longpress while it is attached, so a tooltip on that target leaves the long press to the menu, as it already did for the context menu trigger. MenuShortcut renders left to right in right-to-left text, as the dropdown menu's shortcut did.

  11. registry 0.5.0

    86397f1 — Add MenuTrigger: a Reka-shaped part that marks the element opening a Menu placed next to it, so <MenuTrigger as-child><Button /></MenuTrigger><Menu /> reads like a dropdown menu. A Menu with the default target prefers a sibling trigger over the element it is placed in.