Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Dropdown Menu

FreeNew

The menu behind a “…” button: icons, shortcuts, submenus, checkbox and radio items, and a delete item that confirms in place.

Installation

pnpm dlx shadcn@latest add @viewport/dropdown-menu

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above.

dropdown-menu-demo.tsx
"use client";

import { useState } from "react";
import { Archive, Copy, Ellipsis, FileText, FolderInput, Pencil, Share2, Trash2 } from "lucide-react";
import {
  DropdownMenu,
  DropdownMenuCheckboxItem,
  DropdownMenuConfirmItem,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuLabel,
  DropdownMenuRadioGroup,
  DropdownMenuRadioItem,
  DropdownMenuSeparator,
  DropdownMenuSub,
  DropdownMenuSubContent,
  DropdownMenuSubTrigger,
  DropdownMenuTrigger,
} from "@/components/viewport/dropdown-menu";

const folders = ["Proposals", "Contracts", "Archive 2025"];

export default function DropdownMenuDemo() {
  const [pinned, setPinned] = useState(true);
  const [access, setAccess] = useState("team");
  const [deleted, setDeleted] = useState(false);

  if (deleted) {
    return (
      <div className="flex w-full max-w-sm items-center justify-between gap-3 rounded-2xl border border-dashed border-border px-4 py-3">
        <p role="status" className="text-sm text-muted-foreground">
          Q3 proposal.pdf was deleted.
        </p>
        <button type="button" onClick={() => setDeleted(false)} className="rounded-sm text-sm font-medium underline-offset-4 outline-none hover:underline focus-visible:ring-2 focus-visible:ring-ring">
          Undo
        </button>
      </div>
    );
  }

  return (
    <div className="flex w-full max-w-sm items-center gap-3 rounded-2xl border border-border bg-card px-4 py-3">
      <span className="grid size-9 shrink-0 place-items-center rounded-lg bg-foreground/[0.06] text-muted-foreground">
        <FileText className="size-4" aria-hidden />
      </span>
      <div className="min-w-0 flex-1">
        <p className="truncate text-sm font-medium">Q3 proposal.pdf</p>
        <p className="text-xs text-muted-foreground">
          2.4 MB · {access === "team" ? "Shared with team" : access === "link" ? "Anyone with the link" : "Only you"}
          {pinned ? " · Pinned" : ""}
        </p>
      </div>
      <DropdownMenu>
        <DropdownMenuTrigger
          aria-label="Actions for Q3 proposal.pdf"
          className="grid size-8 shrink-0 place-items-center rounded-md text-muted-foreground outline-none transition-colors hover:bg-foreground/[0.06] hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring data-[state=open]:bg-foreground/[0.06] data-[state=open]:text-foreground"
        >
          <Ellipsis className="size-4" aria-hidden />
        </DropdownMenuTrigger>
        <DropdownMenuContent className="w-56">
          <DropdownMenuItem icon={<Pencil aria-hidden />} shortcut="⌘R">
            Rename
          </DropdownMenuItem>
          <DropdownMenuItem icon={<Copy aria-hidden />} shortcut="⌘D">
            Duplicate
          </DropdownMenuItem>
          <DropdownMenuSub>
            <DropdownMenuSubTrigger icon={<FolderInput aria-hidden />}>Move to</DropdownMenuSubTrigger>
            <DropdownMenuSubContent>
              {folders.map((folder) => (
                <DropdownMenuItem key={folder}>{folder}</DropdownMenuItem>
              ))}
            </DropdownMenuSubContent>
          </DropdownMenuSub>
          <DropdownMenuSub>
            <DropdownMenuSubTrigger icon={<Share2 aria-hidden />}>Share</DropdownMenuSubTrigger>
            <DropdownMenuSubContent>
              <DropdownMenuLabel>Who can open this</DropdownMenuLabel>
              <DropdownMenuRadioGroup value={access} onValueChange={setAccess}>
                <DropdownMenuRadioItem value="private">Only you</DropdownMenuRadioItem>
                <DropdownMenuRadioItem value="team">Your team</DropdownMenuRadioItem>
                <DropdownMenuRadioItem value="link">Anyone with the link</DropdownMenuRadioItem>
              </DropdownMenuRadioGroup>
            </DropdownMenuSubContent>
          </DropdownMenuSub>
          <DropdownMenuSeparator />
          <DropdownMenuCheckboxItem checked={pinned} onCheckedChange={setPinned}>
            Pinned to top
          </DropdownMenuCheckboxItem>
          <DropdownMenuItem icon={<Archive aria-hidden />}>Archive</DropdownMenuItem>
          <DropdownMenuSeparator />
          <DropdownMenuConfirmItem icon={<Trash2 aria-hidden />} onConfirm={() => setDeleted(true)}>
            Delete
          </DropdownMenuConfirmItem>
        </DropdownMenuContent>
      </DropdownMenu>
    </div>
  );
}

Props

<DropdownMenuItem>

PropTypeDefault
iconReact.ReactNode

An icon shown before the label.

—
shortcutstring

A keyboard shortcut shown at the end of the row, e.g. `⌘D`. Display only.

—
variant"default" | "destructive"

`destructive` colors the row for actions that cannot be undone.

"default"

<DropdownMenuConfirmItem>

PropTypeDefault
iconReact.ReactNode—
confirmLabelstring

The label after the first press.

"Press again to confirm"
onConfirm*() => void

Runs on the second press. The menu then closes.

—

<DropdownMenuSubTrigger>

PropTypeDefault
iconReact.ReactNode—

Accessibility

  • Built on Radix Dropdown Menu: arrow keys, typeahead, Home and End, Escape closes and returns focus.
  • The confirm item announces that a second press is needed and disarms when focus leaves it.
  • Flips and scrolls to stay inside the viewport.
  • No scale animation under reduced motion.