Mục lục tham khảo

Thành phần

Dropdown Menu

Dropdown menu on Base UI Menu: paper popup, 1px ink rule, ink-fill highlight, hairline separators, checkbox, radio and submenu rows.

Nội dung tham khảo viết bằng tiếng Anh; mục “Vietnamese” có ví dụ tiếng Việt.

Xem trước

Install

bash

npx shadcn add @eloquent/dropdown-menu

Usage

tsx

import { Button } from "@/components/ui/button";
import {
  DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel,
  DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";

<DropdownMenu>
  <DropdownMenuTrigger render={<Button variant="outline" />}>Account</DropdownMenuTrigger>
  <DropdownMenuContent>
    <DropdownMenuGroup>
      <DropdownMenuLabel>My account</DropdownMenuLabel>
      <DropdownMenuItem>Profile<DropdownMenuShortcut>⇧P</DropdownMenuShortcut></DropdownMenuItem>
      <DropdownMenuItem>Settings</DropdownMenuItem>
    </DropdownMenuGroup>
    <DropdownMenuSeparator />
    <DropdownMenuItem variant="destructive">Sign out</DropdownMenuItem>
  </DropdownMenuContent>
</DropdownMenu>

Put DropdownMenuLabel inside a DropdownMenuGroup. The submenu parts are DropdownMenuSub, DropdownMenuSubTrigger and DropdownMenuSubContent.

States

Checkbox items
Radio items
Destructive and disabled
StateTreatment
OpenPaper popup, 1px ink rule, no shadow
HighlightedInk fill, paper text; it is the menu's focus indicator, so the keyboard and the pointer both move it
Disabledhalftone text, cursor-not-allowed; tint-1 when highlighted
CheckedInk check icon (checkbox), filled ink dot (radio)
DestructiveInk ✕ icon before the label; never red
Submenu opentint-1 band on its row

Keyboard

KeyAction
Enter / Space / ArrowDownOn the trigger, open with the first row highlighted
ArrowDown / ArrowUpMove the highlight; it wraps
Home / EndFirst or last row
A letterJump to the next row starting with it
Enter / SpaceActivate the row; checkbox and radio rows keep the menu open
ArrowRightOpen a submenu
ArrowLeftClose a submenu and return to its row
EscClose; focus returns to the trigger

Vietnamese

Ink adaptation

Upstream shadcn's shadow, radius, colour tokens and animation are removed. Rows are Barlow at 44px high, labels are tracked capitals and separators are hairlines. The inventory suggests a tint-1 highlight; the ink fill is used so the keyboard position stays clear (the same reading as Select). Built on Base UI Menu.