Menu

Menu

Menu item + dropdown menu. 2 types × 3 states.

Installation

$ npx uix-ui@latest add menu

This copies the file into components/ui/menu.tsx in your project. npx shadcn@latest add @uix/menu works too.

Usage

menu.tsx
import { Menu, MenuItem, MenuSeparator } from "@/components/ui/menu";

<Menu style={{ width: 240, maxWidth: "100%" }} aria-label="Order actions">
  <MenuItem icon={<Copy />} shortcut="⌘C">Copy order number</MenuItem>
  <MenuItem icon={<Search />}>Find similar</MenuItem>
  <MenuItem checked={grid} onClick={() => setGrid(!grid)}>Show as grid</MenuItem>
  <MenuSeparator />
  <MenuItem type="destructive">Cancel order</MenuItem>
</Menu>

Props

PropTypeDefaultDescription
typedefault | destructive"default"
iconReact.ReactNode–Icon before the label.
leadingAvatarReact.ReactNode–Avatar before the label.
shortcutReact.ReactNode–Hint at the end, for example ⌘S.
checkedboolean–Turns the item into a checkbox item and sets its state.

Everything else is passed to the root element, so className, aria-* and event handlers work as usual.

Dependencies

Installed for you by the CLI.

  • class-variance-authority
  • clsx
  • tailwind-merge
  • lib/utils.ts
  • components/ui/icons.tsx
This file exports 3 parts: Menu, MenuItem, MenuSeparator. Use only the ones you need.
esc

↑↓ to navigate · ↵ to select · esc to close