Menu
Action menu namespace. Menu is Root for compound menus; use Menu.FromSections, Menu.ContextMenu, or Menu.Overflow for common presets. onOpenChange(open, details) reports details.reason (trigger-press, escape-key, outside-press, focus, imperative); details.cancel() vetoes the change. The trigger child must forward DOM props — there is no render prop.
The popup is a native popover element rendered in place (top layer, positioned with CSS anchor positioning), so there is no portal and no portalContainer. placement on Menu.Popup takes top | bottom | start | end, optionally with an alignment (bottom end, top start); it flips automatically when it does not fit, and start/end follow the writing direction. Works inside a modal Dialog.
State attributes, anchor positioning variables, and onOpenChange reasons are documented in Overlay lifecycle.
Examples
Compound parts
Compose Menu.Trigger, Menu.Popup, Menu.Item, Menu.Section, and Menu.Separator.
import { Button, Menu } from '@var-ui/react';
<Menu>
<Menu.Trigger>
<Button>Song</Button>
</Menu.Trigger>
<Menu.Popup>
<Menu.Item id="lib" onAction={() => {}}>Add to Library</Menu.Item>
<Menu.Separator />
<Menu.Section title="Danger">
<Menu.Item id="delete" onAction={() => {}}>Delete</Menu.Item>
</Menu.Section>
</Menu.Popup>
</Menu>Submenus
Menu.Submenu nests a menu inside Menu.Popup. It takes a label, an optional icon (a registry name or a node) and disabled, plus the same children as the popup: Menu.Item, Menu.Section, Menu.Separator and further Menu.Submenus, to any depth. Native props (className, data-*, aria-*) go on the trigger item.
The child menu opens beside its item (to the inline end, mirrored in RTL) with its first item level with the trigger. Hovering the item opens it after a short delay; ArrowRight, Enter and Space open it with the first item focused (ArrowLeft in RTL). ArrowLeft and Escape close only that submenu and put focus back on its trigger item; the parent menu stays open while the pointer or focus is inside the submenu. Choosing an item runs its onAction once and closes every open menu. There is no safe-triangle: the pointer must stay on the item or cross directly into the submenu.
import { Button, Menu } from '@var-ui/react';
<Menu>
<Menu.Trigger>
<Button>File</Button>
</Menu.Trigger>
<Menu.Popup aria-label="File">
<Menu.Item id="new">New</Menu.Item>
<Menu.Submenu label="Share" icon="copy">
<Menu.Item id="link">Copy link</Menu.Item>
<Menu.Item id="email">Email</Menu.Item>
<Menu.Separator />
<Menu.Submenu label="Export as">
<Menu.Item id="pdf">PDF</Menu.Item>
<Menu.Item id="png">PNG</Menu.Item>
</Menu.Submenu>
</Menu.Submenu>
<Menu.Submenu label="Archive" disabled>
<Menu.Item id="zip">Zip</Menu.Item>
</Menu.Submenu>
<Menu.Separator />
<Menu.Item id="quit">Quit</Menu.Item>
</Menu.Popup>
</Menu>Single choice
Pass value (controlled), defaultValue or onValueChange to make a menu a single choice, like a sort order or a view mode. Items render as menuitemradio with a check mark next to the chosen one, and choosing an item checks it and calls onValueChange(id). null means selectable with nothing checked yet. Selection applies to the top-level items; a Menu.Submenu trigger stays a plain item. Menu.FromSections forwards the same props. In Astro, Menu takes defaultValue with the same meaning.
const [sort, setSort] = useState<string | null>('name');
<Menu value={sort} onValueChange={setSort}>
<Menu.Trigger>
<Button>Sort</Button>
</Menu.Trigger>
<Menu.Popup>
<Menu.Item id="name">Name</Menu.Item>
<Menu.Item id="date">Date modified</Menu.Item>
</Menu.Popup>
</Menu>;<Menu triggerLabel="Sort" defaultValue="name" sections={[{ items: sortItems }]} />From sections
Pass a trigger and sections of items (optional section labels, shortcuts, icon, swatch, danger, disabled). In Astro, icon is a registry name or { svg } markup, so data-driven items can carry custom icons without a named slot per item. A section with layout: 'row' lays its items out side by side as compact icon buttons (each needs an icon; its label becomes the accessible name), for example a Light / Dark / System switch above a list of themes; left and right arrows move along the row. An item with an items array of child items opens them as a submenu (the same applies to Menu.ContextMenu, Menu.Overflow and Menu.Content); shortcut, danger and onAction are ignored on such an item.
import { Button, Menu } from '@var-ui/react';
<Menu.FromSections
trigger={<Button>Actions</Button>}
sections={[{ items: [{ id: 'edit', label: 'Edit' }] }]}
/>import { Button, Menu } from '@var-ui/react';
<Menu.FromSections
trigger={<Button>File</Button>}
sections={[
{
label: 'Edit',
items: [
{ id: 'cut', label: 'Cut', shortcut: '⌘X' },
{ id: 'copy', label: 'Copy', shortcut: '⌘C' },
{ id: 'paste', label: 'Paste', shortcut: '⌘V' },
],
},
{
label: 'Danger zone',
items: [
{ id: 'archive', label: 'Archive' },
{ id: 'delete', label: 'Delete…', danger: true },
],
},
]}
/>Context menu
Wrap a surface and pass sections. Right-click (or the platform context-menu gesture) opens the menu at the pointer; from the keyboard (Shift+F10 / the context-menu key) it opens at the surface’s bottom-start corner. The child must be a DOM element Pressable can attach a ref to (e.g. a div).
import { Menu } from '@var-ui/react';
<Menu.ContextMenu sections={[{ items: [{ id: 'copy', label: 'Copy' }] }]}>
<div>Right-click me</div>
</Menu.ContextMenu>import { Menu } from '@var-ui/react';
<Menu.ContextMenu
sections={[
{
label: 'Edit',
items: [
{ id: 'rename', label: 'Rename' },
{ id: 'duplicate', label: 'Duplicate' },
],
},
{
label: 'Clipboard',
items: [
{ id: 'copy', label: 'Copy' },
{ id: 'paste', label: 'Paste' },
{ id: 'delete', label: 'Delete', danger: true },
],
},
]}
>
<div>Project card — right-click for actions</div>
</Menu.ContextMenu>Overflow
Icon-only overflow menu using the moreHorizontal glyph — same sections shape as other presets.
import { Menu } from '@var-ui/react';
<Menu.Overflow sections={[{ items: [{ id: 'edit', label: 'Edit' }] }]} />import { Menu } from '@var-ui/react';
<Menu.Overflow
aria-label="Row actions"
sections={[
{
items: [
{ id: 'share', label: 'Share' },
{ id: 'duplicate', label: 'Duplicate' },
{ id: 'archive', label: 'Archive' },
{ id: 'delete', label: 'Delete', danger: true },
],
},
]}
/>Menus in long lists
Give every row its own Menu.FromSections, Menu.Overflow or Menu.ContextMenu. A menu’s popup (the [popover] element) mounts the first time the menu opens, and its items only while it is open. So a 60-row list costs 60 triggers, not 60 hidden popovers. The trigger stays mounted, so focus returns to it on close.
Props
Accessibility
Built on React Aria MenuTrigger / Menu inside a native popover. Focus moves to the first item on open and returns to the trigger on close. Arrow keys move between items, Enter/Space activates, Escape closes. A submenu trigger item has aria-haspopup and aria-expanded, and its child menu is named by it.
| Key | Action |
|---|---|
| Right arrow (Left in RTL), Enter, Space | On a submenu trigger: opens it and focuses its first item |
| Left arrow (Right in RTL), Escape | In a submenu: closes it and focuses its trigger item |
| Escape | In the top-level menu: closes it |
| Down / Up arrow | Next / previous enabled item |
| Enter / Space (on an item) | Runs onAction and closes every open menu |
The Astro Menu.astro has no submenus; use the React component when you need them. Give destructive items clear labels — visual tone is not enough. For Menu.ContextMenu, ensure essential actions are also available without right-click for keyboard-only users.