cnippet/ui
  1. ui
  2. navigation
  3. menu

navigation

Menu

A list of actions in a dropdown, enhanced with keyboard navigation. Built with Base UI and Tailwind CSS. Copy-paste ready.

API Reference

Installation

Usage

Anatomy

Good to know

  • Built on Base UI, not Radix. Handle item actions with onClick. There is no onSelect.
  • The DropdownMenu* names are aliases (DropdownMenuContent is MenuPopup, DropdownMenuLabel is MenuGroupLabel). Prefer the Menu* names.
  • MenuTrigger is unstyled. Style it with render={<Button variant="outline" />}. There is no asChild.
  • Clicking a MenuItem closes the menu. Checkbox and radio items keep it open. Change this per item with closeOnClick.
  • MenuGroupLabel must be inside a MenuGroup or MenuRadioGroup; otherwise it throws an error.
  • Every MenuRadioItem needs a value. The selection lives on MenuRadioGroup (value, defaultValue, onValueChange).
  • For links, use render on the item: <MenuItem render={<Link href="/settings" />}>Settings</MenuItem>.
  • variant="destructive" styles an item in red. inset indents an item without an icon so it lines up with items that have one. MenuCheckboxItem variant="switch" shows a switch instead of a check mark.

API Reference

Root provider. Also exported as DropdownMenu.

Button that opens the menu. Also exported as DropdownMenuTrigger.

The floating menu panel. Also exported as DropdownMenuContent.

Groups related menu items. Also exported as DropdownMenuGroup.

Label displayed above a MenuGroup. Also exported as DropdownMenuLabel.

Standard action item. Also exported as DropdownMenuItem.

Toggleable item with a checkmark indicator. Also exported as DropdownMenuCheckboxItem.

Single-selection group. Also exported as DropdownMenuRadioGroup / DropdownMenuRadioItem.

Horizontal divider between item groups. Also exported as DropdownMenuSeparator.

Right-aligned keyboard hint <kbd> element. Also exported as DropdownMenuShortcut.

Nested submenu. Also exported as DropdownMenuSub, DropdownMenuSubTrigger, DropdownMenuSubContent.

Examples

Open on Hover

The menu popup opens when the trigger is hovered rather than clicked, useful for navigation bars and toolbars.

With Checkbox

Uses MenuCheckboxItem to let users toggle individual options on or off within a persistent menu.

With Switch

MenuCheckboxItem supports a variant="switch" prop that displays a decorative switch indicator instead of a checkmark. Groups notification channels and activity types, each independently toggled via a switch.

With Radio Group

Uses MenuRadioGroup and MenuRadioItem to enforce single selection among a set of mutually exclusive options.

Renders MenuItem elements as anchor tags for navigating to routes directly from the menu popup.

With Group Label

Organizes menu items into labeled sections using MenuGroup and MenuGroupLabel for better scanability.

Nested Menu

Opens a MenuSub popup from a parent item to reveal a secondary list of options without closing the parent menu.

Close on Click

Demonstrates controlling closeOnClick behavior so the menu dismisses immediately when an item is selected.

Open a Dialog

Triggers a Dialog from a MenuItem, allowing secondary confirmation flows to be launched directly from a menu.

Account Menu

A circular avatar trigger with user info in the MenuGroupLabel header, account links, and a destructive "Sign out" item at the bottom.

File Actions

A labeled "File actions" trigger grouping rename, duplicate, move, and download items with keyboard shortcuts, plus a destructive delete at the bottom.

Icon Button Trigger

A compact size="icon" ghost button (⋮) as the trigger — a common pattern for per-row action menus in lists and tables.

Notification Settings

A bell icon trigger that opens a menu mixing variant="switch" channel toggles with standard checkbox activity options in separate groups.

Share with Export Sub-menu

A "Share" button trigger offering a copy link item alongside an "Export as" MenuSub with format choices (PDF, PNG, SVG, CSV).