Components / Dropdown Menu
Dropdown Menu
A square, monospaced menu for contextual actions and settings. Keep frequent actions visible; put related, secondary choices behind a clearly named trigger.
Storybook runs locally or as a separate build; no hosted Storybook is configured. Source and setup links match the install revision.
Actions and export
Try Rename or Duplicate and read the result. Export groups less-frequent formats in a submenu. Delete is unavailable to non-owners. Use Arrow keys, type a label, or press Escape to return to the trigger.
No action yet.
"use client";
import { Button } from "@/components/ui/yads-button";
import { useState } from "react";
import {
DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem,
Installation
pnpm dlx [email protected] add biehlio/yet-another-design-system/dropdown-menu#e7b31d0e0c9d8b24d53e97ca38b3b68d345e9f40Documentation samples use basic Tailwind utilities for layout. Install each YADS component imported by the sample.
Run in a project configured for shadcn. This installs yads-dropdown-menu.tsx, its scoped CSS, Radix Dropdown Menu, Radix Slot, lucide-react and JetBrains Mono. Import from @/components/ui/yads-dropdown-menu (adjust your alias). No Tailwind, global theme stylesheet, Button or other YADS primitive is required.
Each Copy sample includes a complete React module, even while collapsed. Examples style a native trigger inline; use a client boundary in React Server Component apps.
Checkbox and radio preferences
Line numbers independently toggles the editor preview. Density is a mutually exclusive radio choice. The checkbox prevents the select event’s default closing behavior so you can adjust several settings; radio selection closes the menu.
Line numbers on; comfortable spacing.
"use client";
import { Button } from "@/components/ui/yads-button";
import { useState } from "react";
import {
DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuCheckboxItem,
Customization and portal themes
Content and SubContent accept className and style. Set the five --yads-menu-* color variables on each content surface; a trigger’s custom CSS variables do not cross a portal. This palette overrides both light and dark defaults. Keep foreground and highlight contrast readable.
"use client";
import { Button } from "@/components/ui/yads-button";
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem } from "@/components/ui/yads-dropdown-menu";
export default function Example() {
The nearest data-theme="light|dark", .light or .dark ancestor of the trigger determines the menu and portaled submenu theme. A nearer light scope overrides a dark document. With no explicit theme, the system preference is used. Changes while open are observed. No global theme provider is needed.
Content automatically portals to the document body. For a submenu, wrap SubContent in DropdownMenuPortal as shown. Radix handles collision-aware positioning. Use sideOffset, align and collisionPadding for placement; both surfaces constrain height and scroll on small screens.
Accessibility
- Use a semantic button with a clear name. Trigger defaults to a native button; with
asChild, supply one focusable button that forwards props and ref. Triggers are intentionally unstyled. - Enter, Space or ArrowDown opens the menu. ArrowUp/Down moves between enabled items; Home/End reaches the first/last; typing searches labels. Disabled items are skipped. ArrowRight/Left enters/leaves a submenu (reversed in RTL).
- Escape dismisses and restores trigger focus; then Tab continues through the page. While open, Radix prevents Tab: use Arrow keys to move between menu items. Radix supplies menu roles, roving focus, checked states and focus restoration; do not replace these with click-only elements.
- Use onSelect for actions (keyboard and pointer), onCheckedChange for checkboxes and onValueChange on RadioGroup. Labels and separators organize choices, not interactive content. Shortcut only displays a hint; it does not register a keyboard shortcut.
- Use a select for choosing a form value, not this action menu. Keep long forms, dialogs and nested interactive controls out of items.
API reference
All existing exports retain Radix props and events; rendered parts forward refs, className and native attributes. Root, Portal, Group, Sub and RadioGroup follow their Radix counterparts. These are the commonly used defaults; see the Radix reference for the full API.
| Part | Props / defaults | Use |
|---|---|---|
| DropdownMenu | open / defaultOpen, onOpenChange; modal=true; dir | Controlled or uncontrolled root. Closed by default. |
| DropdownMenuTrigger | asChild=false; disabled | Native button, unstyled. Name with visible text or aria-label. |
| DropdownMenuContent | side=bottom; align=center; sideOffset=4; loop=false | Automatic portal, focus management and collision avoidance. onCloseAutoFocus / onEscapeKeyDown / onInteractOutside. |
| DropdownMenuItem | disabled=false; inset=false; textValue; onSelect | Action; preventDefault on select to keep open. asChild for semantic links. |
| DropdownMenuCheckboxItem | checked=false | true | indeterminate; onCheckedChange | Independent state with check indicator. disabled supported. |
| DropdownMenuRadioGroup / RadioItem | value / onValueChange; item value (required) | Mutually exclusive selection; disabled supported on items. |
| DropdownMenuSub / SubTrigger / SubContent | open / defaultOpen / onOpenChange; trigger inset=false | Nested choices; SubContent shares scoped styles and trigger theme. Use Portal to escape clipping. |
| DropdownMenuLabel / Group / Separator | Label inset=false; Group aria-label or aria-labelledby | Noninteractive organization. Group related items under a meaningful name. |
| DropdownMenuPortal | container=document.body; forceMount | Explicit portal for submenu; Content already includes one. |
| DropdownMenuShortcut | Native span attributes | Display-only shortcut hint; implement the actual binding yourself. |