Dropdown menu
Actions with icons, shortcuts and groups.
Installation
Run the CLI
Run
pnpm dlx asta-ui@latest initonce, then this. The file lands incomponents/astabyte/, installsradix-ui@base-ui/reactand the colour tokens go into your CSS. This is the Radix build. Drop --radix for Base UI.This is the Base UI build, the default. Want Radix? Add --radix.$ pnpm dlx asta-ui@latest add dropdown-menu --radixOr install the package
Don’t want the file? Import from
asta-uiasta-ui/baseand update withpnpm update asta-ui. Add the stylesheet once. More.$ pnpm add asta-ui radix-ui @base-ui/reactimport { DropdownMenu } from "asta-ui";import { DropdownMenu } from "asta-ui/base";Or copy it by hand
Install
radix-ui@base-ui/react, then copy these files. Keep the paths, or fix the@/imports. Then add the tokens fromglobals.css."use client"; import { DropdownMenu as Menu } from "radix-ui"; import type { ReactNode } from "react"; import { buttonClass, type ButtonVariant } from "@/components/kit/button"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); export interface MenuItem { label: string; icon?: ReactNode; /** Shown on the right, e.g. "⌘D". Display only. */ shortcut?: string; danger?: boolean; disabled?: boolean; onSelect?: () => void; } export interface MenuGroup { label?: string; items: MenuItem[]; } export interface DropdownMenuProps { /** Trigger content. */ children: ReactNode; groups: MenuGroup[]; align?: "start" | "end"; variant?: ButtonVariant; className?: string; /** Accessible name for the trigger when its content is only an icon. */ label?: string; } const KEYFRAMES = `@keyframes kit-menu-in { from { opacity: 0; transform: scale(.96) } } @keyframes kit-menu-out { to { opacity: 0; transform: scale(.97) } }`; /** * An action menu on Radix Dropdown Menu. It scales in from the trigger (the origin follows the side it * opened on) and flips when there is no room. Arrow keys, Home/End, type-ahead, Escape and focus return * come from Radix. */ export function DropdownMenu({ children, groups, align = "start", variant = "outline", className, label }: DropdownMenuProps) { return ( <Menu.Root modal={false}> <Menu.Trigger aria-label={label} className={cx(buttonClass({ variant }), "group/trigger data-[state=open]:bg-paper-2", className)}> {children} <svg viewBox="0 0 24 24" className="-mr-1 h-3.5 w-3.5 text-mute transition-transform duration-300 ease-[cubic-bezier(.16,1,.3,1)] group-data-[state=open]/trigger:rotate-180" fill="none" stroke="currentColor" strokeWidth="2.55" strokeLinecap="round" strokeLinejoin="round" aria-hidden > <path d="m6 9.5 6 6 6-6" /> </svg> </Menu.Trigger> <Menu.Portal> <Menu.Content align={align} sideOffset={6} collisionPadding={8} className={cx( "z-50 min-w-[232px] rounded-xl bg-paper p-1.5 outline-none", "shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_10%,transparent),0_12px_32px_-12px_rgb(0_0_0/0.28),0_4px_10px_-6px_rgb(0_0_0/0.12)]", "origin-[var(--radix-dropdown-menu-content-transform-origin)]", "data-[state=open]:animate-[kit-menu-in_.2s_cubic-bezier(.16,1,.3,1)_both] data-[state=closed]:animate-[kit-menu-out_.12s_cubic-bezier(.16,1,.3,1)_both] motion-reduce:!animate-none", )} > <style href="asta-dropdown-menu" precedence="asta">{KEYFRAMES}</style> {groups.map((g, gi) => ( <Menu.Group key={gi}> {gi > 0 && <Menu.Separator className="mx-1 my-1.5 h-px bg-[color-mix(in_srgb,var(--color-ink)_8%,transparent)]" />} {g.label && <Menu.Label className="px-2.5 pb-1 pt-1.5 text-[11px] font-medium uppercase tracking-wider text-mute">{g.label}</Menu.Label>} {g.items.map((it) => ( <Menu.Item key={it.label} disabled={it.disabled} onSelect={it.onSelect} className={cx( "group/item flex h-9 w-full cursor-pointer select-none items-center gap-2.5 rounded-[10px] px-2.5 text-[13.5px] outline-none transition-colors duration-150", "data-[disabled]:cursor-not-allowed data-[disabled]:opacity-40", it.danger ? "text-ink data-[highlighted]:bg-paper-2" : "text-ink data-[highlighted]:bg-paper-2", )} > {it.icon && ( <span className={cx("inline-flex h-4 w-4 shrink-0 [&_svg]:h-4 [&_svg]:w-4", !it.danger && "text-mute group-data-[highlighted]/item:text-ink")}> {it.icon} </span> )} <span className="flex-1 truncate">{it.label}</span> {it.shortcut && <kbd className="font-sans text-[11.5px] tracking-wide text-mute">{it.shortcut}</kbd>} </Menu.Item> ))} </Menu.Group> ))} </Menu.Content> </Menu.Portal> </Menu.Root> ); } export default DropdownMenu;"use client"; import { Menu } from "@base-ui/react/menu"; import type { ReactNode } from "react"; import { buttonClass, type ButtonVariant } from "@/components/kit/base/button"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); export interface MenuItem { label: string; icon?: ReactNode; /** Shown on the right, e.g. "⌘D". Display only. */ shortcut?: string; danger?: boolean; disabled?: boolean; onSelect?: () => void; } export interface MenuGroup { label?: string; items: MenuItem[]; } export interface DropdownMenuProps { /** Trigger content. */ children: ReactNode; groups: MenuGroup[]; align?: "start" | "end"; variant?: ButtonVariant; className?: string; /** Accessible name for the trigger when its content is only an icon. */ label?: string; } /** * An action menu on Base UI Menu. It scales in from the trigger (the origin follows the side it * opened on) and flips when there is no room. Arrow keys, Home/End, type-ahead, Escape and focus return * come from Base UI. */ export function DropdownMenu({ children, groups, align = "start", variant = "outline", className, label }: DropdownMenuProps) { return ( <Menu.Root modal={false}> <Menu.Trigger aria-label={label} className={cx(buttonClass({ variant }), "group/trigger data-[popup-open]:bg-paper-2", className)}> {children} <svg viewBox="0 0 24 24" className="-mr-1 h-3.5 w-3.5 text-mute transition-transform duration-300 ease-[cubic-bezier(.16,1,.3,1)] group-data-[popup-open]/trigger:rotate-180" fill="none" stroke="currentColor" strokeWidth="2.55" strokeLinecap="round" strokeLinejoin="round" aria-hidden > <path d="m6 9.5 6 6 6-6" /> </svg> </Menu.Trigger> <Menu.Portal> <Menu.Positioner align={align} sideOffset={6} collisionPadding={8} className="z-50 outline-none"> <Menu.Popup className={cx( "min-w-[232px] rounded-xl bg-paper p-1.5 outline-none", "shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_10%,transparent),0_12px_32px_-12px_rgb(0_0_0/0.28),0_4px_10px_-6px_rgb(0_0_0/0.12)]", "origin-[var(--transform-origin)] transition-[opacity,transform] duration-200 ease-[cubic-bezier(.16,1,.3,1)]", "data-[starting-style]:scale-[.96] data-[starting-style]:opacity-0 data-[ending-style]:scale-[.97] data-[ending-style]:opacity-0 data-[ending-style]:duration-[120ms] data-[ending-style]:ease-[cubic-bezier(.16,1,.3,1)] motion-reduce:!transition-none", )} > {groups.map((g, gi) => ( <Menu.Group key={gi}> {gi > 0 && <Menu.Separator className="mx-1 my-1.5 h-px bg-[color-mix(in_srgb,var(--color-ink)_8%,transparent)]" />} {g.label && <Menu.GroupLabel className="px-2.5 pb-1 pt-1.5 text-[11px] font-medium uppercase tracking-wider text-mute">{g.label}</Menu.GroupLabel>} {g.items.map((it) => ( <Menu.Item key={it.label} disabled={it.disabled} onClick={it.onSelect} className={cx( "group/item flex h-9 w-full cursor-pointer select-none items-center gap-2.5 rounded-[10px] px-2.5 text-[13.5px] outline-none transition-colors duration-150", "data-[disabled]:cursor-not-allowed data-[disabled]:opacity-40", it.danger ? "text-ink data-[highlighted]:bg-paper-2" : "text-ink data-[highlighted]:bg-paper-2", )} > {it.icon && ( <span className={cx("inline-flex h-4 w-4 shrink-0 [&_svg]:h-4 [&_svg]:w-4", !it.danger && "text-mute group-data-[highlighted]/item:text-ink")}> {it.icon} </span> )} <span className="flex-1 truncate">{it.label}</span> {it.shortcut && <kbd className="font-sans text-[11.5px] tracking-wide text-mute">{it.shortcut}</kbd>} </Menu.Item> ))} </Menu.Group> ))} </Menu.Popup> </Menu.Positioner> </Menu.Portal> </Menu.Root> ); } export default DropdownMenu;Or ask your AI agent
Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.
Add the Astabyte UI Dropdown menu component to my project. Actions with icons, shortcuts and groups. It includes: items, shortcuts, groups, keys. Install it (Radix build): ```sh pnpm dlx asta-ui@latest add dropdown-menu --radix ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/dropdown-menu.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import { DropdownMenu } from "@/components/astabyte/dropdown-menu"; ``` Usage example and props: https://ui.astabyte.com/dropdown-menu Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour (interactive pieces are built on Radix primitives from the radix-ui package). - Stay on Radix: install other Astabyte UI components with `--radix` so the project uses one primitive library. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]Add the Astabyte UI Dropdown menu component to my project. Actions with icons, shortcuts and groups. It includes: items, shortcuts, groups, keys. Install it (Base UI build): ```sh pnpm dlx asta-ui@latest add dropdown-menu ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/base/dropdown-menu.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import { DropdownMenu } from "@/components/astabyte/dropdown-menu"; ``` Usage example and props: https://ui.astabyte.com/dropdown-menu Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour (interactive pieces are built on Base UI primitives from the @base-ui/react package). - Stay on Base UI: install other Astabyte UI components without `--radix` so the project uses one primitive library. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]Or use plain HTML + CSS
Not on React? Use it from Django, Rails, Laravel, Go
html/template, htmx or a static page. Loadasta.cssandasta.jsonce (thehead.htmltab), then paste the markup. Theui.astabyte.com/cdnlink is temporary: pin a version from jsDelivr for production. More in HTML + CSS.<!-- Needs asta.js: toggles data-open/aria-expanded, positions the panel, keyboard nav, submenus and aria-checked. --> <div style="display:flex;flex-wrap:wrap;gap:12px;align-items:center"> <div class="asta-dropdown" data-asta-dropdown> <button type="button" class="asta-btn asta-btn-outline asta-dropdown-trigger" data-asta-dropdown-trigger aria-haspopup="menu" aria-expanded="false" id="ex-dd-one-trigger" aria-controls="ex-dd-one">View<svg class="asta-dropdown-chevron" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m4 6 4 4 4-4"/></svg></button> <div role="menu" popover="manual" tabindex="-1" data-asta-mpanel id="ex-dd-one" aria-labelledby="ex-dd-one-trigger" class="asta-float asta-dropdown-panel"> <div role="presentation" class="asta-menu-label">Layout</div> <button type="button" role="menuitemradio" tabindex="-1" aria-checked="true" data-group="layout" data-value="grid" class="asta-menu-item"><span class="asta-menu-radio"><span></span></span><span class="asta-menu-item-text">Grid</span><input type="hidden" name="layout" value="grid"></button> <button type="button" role="menuitemradio" tabindex="-1" aria-checked="false" data-group="layout" data-value="list" class="asta-menu-item"><span class="asta-menu-radio"><span></span></span><span class="asta-menu-item-text">List</span><input type="hidden" name="layout" value="list" disabled></button> <div role="separator" class="asta-menu-separator"></div> <button type="button" role="menuitemcheckbox" tabindex="-1" aria-checked="false" data-keep-open data-value="hidden" class="asta-menu-item"><span class="asta-menu-check"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m4 8.5 2.5 2.5L12 5.5"/></svg></span><span class="asta-menu-item-text">Show hidden files</span><input type="hidden" name="show" value="hidden" disabled></button> <button type="button" role="menuitemcheckbox" tabindex="-1" aria-checked="true" data-keep-open data-value="sizes" class="asta-menu-item"><span class="asta-menu-check"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m4 8.5 2.5 2.5L12 5.5"/></svg></span><span class="asta-menu-item-text">Show sizes</span><input type="hidden" name="show" value="sizes"></button> <div role="separator" class="asta-menu-separator"></div> <div class="asta-dropdown-sub" data-asta-menu-sub> <button type="button" role="menuitem" tabindex="-1" aria-haspopup="menu" aria-expanded="false" class="asta-menu-item asta-dropdown-sub-trigger"><span class="asta-menu-item-icon"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M3 13V8M8 13V3M13 13V6"/></svg></span><span class="asta-menu-item-text">Sort by</span><svg class="asta-dropdown-sub-chevron" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 4 4 4-4 4"/></svg></button> <div role="menu" popover="manual" tabindex="-1" data-asta-mpanel aria-label="Sort by" class="asta-float asta-dropdown-panel asta-dropdown-sub-panel"> <button type="button" role="menuitemradio" tabindex="-1" aria-checked="true" data-group="sort" data-value="name" class="asta-menu-item"><span class="asta-menu-radio"><span></span></span><span class="asta-menu-item-text">Name</span></button> <button type="button" role="menuitemradio" tabindex="-1" aria-checked="false" data-group="sort" data-value="date" class="asta-menu-item"><span class="asta-menu-radio"><span></span></span><span class="asta-menu-item-text">Date</span></button> <button type="button" role="menuitemradio" tabindex="-1" aria-checked="false" data-group="sort" data-value="size" class="asta-menu-item"><span class="asta-menu-radio"><span></span></span><span class="asta-menu-item-text">Size</span></button> </div> </div> </div> </div> <div class="asta-dropdown" data-asta-dropdown data-align="end"> <button type="button" class="asta-btn asta-btn-ghost asta-btn-icon asta-dropdown-trigger" data-asta-dropdown-trigger aria-haspopup="menu" aria-expanded="false" id="ex-dd-two-trigger" aria-controls="ex-dd-two" aria-label="Settings"><span class="asta-dropdown-icon"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M8 5.5a2.5 2.5 0 1 0 0 5 2.5 2.5 0 0 0 0-5zM8 1.5v2M8 12.5v2M1.5 8h2M12.5 8h2M3.4 3.4l1.4 1.4M11.2 11.2l1.4 1.4M3.4 12.6l1.4-1.4M11.2 4.8l1.4-1.4"/></svg></span></button> <div role="menu" popover="manual" tabindex="-1" data-asta-mpanel id="ex-dd-two" aria-labelledby="ex-dd-two-trigger" class="asta-float asta-dropdown-panel"> <button type="button" role="menuitem" tabindex="-1" class="asta-menu-item"><span class="asta-menu-item-icon"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M8 8a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5zM3 13.5c.8-2.3 2.7-3.5 5-3.5s4.2 1.2 5 3.5"/></svg></span><span class="asta-menu-item-text">Profile</span></button> <button type="button" role="menuitem" tabindex="-1" class="asta-menu-item asta-menu-item-danger"><span class="asta-menu-item-icon"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M6 2.5H3v11h3M10 5l3 3-3 3M13 8H6"/></svg></span><span class="asta-menu-item-text">Sign out</span></button> </div> </div> </div>
Usage
The demo above, as code.
"use client";
import { useState } from "react";
import { DropdownMenu } from "@/components/astabyte/dropdown-menu";
const icon = (d: string) => (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.25" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
<path d={d} />
</svg>
);
export default function DropdownMenuDemo() {
const [last, setLast] = useState("Nothing yet");
const pick = (label: string) => () => setLast(label);
return (
<div className="relative flex min-h-[420px] w-full flex-col items-center justify-start gap-4 p-6 pt-16 sm:p-10 sm:pt-20">
<div className="flex flex-wrap items-center justify-center gap-3">
<DropdownMenu
groups={[
{
items: [
{ label: "Edit", icon: icon("M4.5 19.5 5 16 15.5 5.5a2.1 2.1 0 0 1 3 3L8 19ZM13.5 7.5l3 3"), shortcut: "⌘E", onSelect: pick("Edit") },
{ label: "Duplicate", icon: icon("M10.5 8.5h7a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2h-7a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2ZM15.5 8.5V6.5a2 2 0 0 0-2-2h-7a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h2"), shortcut: "⌘D", onSelect: pick("Duplicate") },
{ label: "Share", icon: icon("M8 9.5H6.5A1.5 1.5 0 0 0 5 11v8a1.5 1.5 0 0 0 1.5 1.5h11A1.5 1.5 0 0 0 19 19v-8a1.5 1.5 0 0 0-1.5-1.5H16M12 14V3.5M8.5 7 12 3.5 15.5 7"), onSelect: pick("Share") },
],
},
{
label: "Move",
items: [
{ label: "Archive", icon: icon("M4 4.5h16a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1h-16a1 1 0 0 1-1-1v-2a1 1 0 0 1 1-1ZM5 8.5v10A1.5 1.5 0 0 0 6.5 20h11a1.5 1.5 0 0 0 1.5-1.5v-10M10 12h4"), shortcut: "⌘A", onSelect: pick("Archive") },
{ label: "Move to folder", icon: icon("M3.5 7A1.5 1.5 0 0 1 5 5.5h4.5l2 2.5H19a1.5 1.5 0 0 1 1.5 1.5v8A1.5 1.5 0 0 1 19 19H5a1.5 1.5 0 0 1-1.5-1.5Z"), disabled: true },
],
},
{ items: [{ label: "Delete", icon: icon("M4 7h16M9.5 7V4.5h5V7M6 7l1 13h10l1-13M10 11v5.5M14 11v5.5"), shortcut: "⌫", danger: true, onSelect: pick("Delete") }] },
]}
>
Options
</DropdownMenu>
<DropdownMenu
align="end"
variant="ghost"
label="More"
groups={[
{
label: "Sort by",
items: [
{ label: "Newest", onSelect: pick("Sort: Newest") },
{ label: "Oldest", onSelect: pick("Sort: Oldest") },
{ label: "Name", onSelect: pick("Sort: Name") },
],
},
]}
>
Sort
</DropdownMenu>
</div>
<p className="text-[13px] text-mute" aria-live="polite">
Selected: <span className="text-ink">{last}</span>
</p>
<p className="mt-auto text-[12px] text-mute">Try the keyboard: ↓ to open, type a letter to jump, Esc to close.</p>
</div>
);
}