Actions
Menu
Row actions and dropdown menus with 36px items, 16px icons and optional shortcuts.
react-aria-components
Preview
"use client";
import { Download, List, MoreHorizontal, Send, Trash2, Zap } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Menu, MenuItem, MenuSeparator, MenuTrigger } from "@/components/ui/menu";
export default function Example() {
return (
<MenuTrigger>
<Button trailingIcon={<MoreHorizontal />}>Actions</Button>
<Menu onAction={(key) => console.log(key)}>
<MenuItem id="list" icon={<List />} shortcut="L">Add to list</MenuItem>
<MenuItem id="sequence" icon={<Send />} shortcut="S">Start sequence</MenuItem>
<MenuItem id="enrich" icon={<Zap />} shortcut="E">Enrich</MenuItem>
<MenuItem id="export" icon={<Download />} shortcut="⌘E">Export</MenuItem>
<MenuSeparator />
<MenuItem id="delete" icon={<Trash2 />} danger>Delete</MenuItem>
</Menu>
</MenuTrigger>
);
}Installation
Components are copied into your project — no runtime package.
Install the following dependencies:
terminalnpm install react-aria-componentsCreate a
menu.tsxfile and paste the following code into it.src/components/ui/menu.tsx"use client"; import type { ReactNode } from "react"; import { Menu as AriaMenu, MenuItem as AriaMenuItem, type MenuItemProps as AriaMenuItemProps, type MenuProps as AriaMenuProps, MenuTrigger, Popover, Separator, } from "react-aria-components"; import { cx } from "@/utils/cx"; import { Kbd } from "./kbd"; export { MenuTrigger }; export function Menu<T extends object>({ className, ...props }: Omit<AriaMenuProps<T>, "className"> & { className?: string }) { return ( <Popover placement="bottom end" offset={6} className="min-w-48 rounded-md bg-surface p-1 shadow-popover outline-none"> <AriaMenu {...props} className={cx("outline-none", className)} /> </Popover> ); } export interface MenuItemProps extends Omit<AriaMenuItemProps, "children" | "className"> { icon?: ReactNode; shortcut?: string; danger?: boolean; children: ReactNode; className?: string; } /** 36px items, radius 8, 16px icon, optional shortcut. */ export function MenuItem({ icon, shortcut, danger, children, className, ...props }: MenuItemProps) { const textValue = props.textValue ?? (typeof children === "string" ? children : undefined); return ( <AriaMenuItem {...props} textValue={textValue} className={cx( "flex h-9 cursor-default items-center gap-2.5 rounded-sm px-2.5 text-base outline-none [&_svg]:size-4 [&_svg]:shrink-0", danger ? "text-error-text data-focused:bg-error-soft [&_svg]:text-error" : "text-fg data-focused:bg-muted [&_svg]:text-fg-secondary", "data-disabled:text-fg-disabled", className, )} > {icon} <span className="flex-1">{children}</span> {shortcut && <Kbd className="border-0 bg-transparent">{shortcut}</Kbd>} </AriaMenuItem> ); } export function MenuSeparator() { return <Separator className="mx-1 my-1 border-t border-line" />; }Create a
kbd.tsxfile and paste the following code into it.src/components/ui/kbd.tsximport { cx } from "@/utils/cx"; /** Marks keyboard shortcuts. */ export function Kbd({ className, children }: { className?: string; children: React.ReactNode }) { return ( <kbd className={cx( "inline-flex h-5 min-w-5 items-center justify-center rounded-[6px] border border-line bg-surface px-1.5 font-sans text-xs font-medium text-fg-muted", className, )} > {children} </kbd> ); }Add the theme tokens and the
cxhelper from Installation if you haven’t yet, then update the import paths to match your project setup.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| icon | ReactNode | — | MenuItem: leading icon. |
| shortcut | string | — | MenuItem: keyboard hint shown on the right. |
| danger | boolean | — | MenuItem: destructive styling. |
| onAction | (key: Key) => void | — | Menu: called with the item id. |