Cómo funciona
No portal and no position: fixed: the panel hangs under a relative root, so it stays right inside scaled containers, scroll areas and dialogs, but an ancestor's overflow: hidden clips it and it never flips. The panel exists only while open: a 20px-radius card that scales from 0.94 and drops 6px into place from the trigger's corner, its rows following 14ms apart; closing plays a faster exit before unmounting. Focus really moves into the items, so the highlight pill is :focus and mouse and keyboard share it.
Úsalo para
- “More actions” on table rows and order cards: tuck 3 to 7 less common actions into one button.
- Secondary toolbar actions and “click to run” choices such as export or sort options.
- A “⋯” menu in a card corner (an icon as trigger, aria-label in triggerProps).
Busca otra opción cuando
- Picking a value that stays selected, such as a form field: use a select or multi-select, which are listbox or combobox, not menu.
- An ancestor with overflow: hidden that the panel would exceed: it gets clipped, so use a portal-based solution.
- More than 8 to 10 items or nested submenus: use a drawer, a command palette or a separate page.
- The main action on mobile: use a bottom sheet, which is easier to reach with a thumb.
Uso
import { DropdownMenu } from './DropdownMenu.jsx'
const items = [
{ key: 'link', label: 'Copy link', icon: <LinkIcon />, shortcut: '⌘L' },
{ key: 'invite', label: 'Invite people', icon: <UserPlusIcon />, shortcut: '⌘I' },
{ key: 'pdf', label: 'Export as PDF', disabled: true },
{ type: 'separator' },
{ key: 'stop', label: 'Stop sharing', icon: <BlockIcon />, danger: true },
]
export function ShareMenu({ doc }) {
return (
<DropdownMenu
label="Share"
placement="bottom-end"
items={items}
onSelect={(key) => {
if (key === 'link') navigator.clipboard.writeText(doc.url)
if (key === 'stop') confirmStopSharing(doc)
}}
/>
)
}
// Icon-only trigger: content goes in trigger, the accessible name in triggerProps
// <DropdownMenu trigger={<MoreIcon />} triggerProps={{ 'aria-label': 'More actions' }} items={items} onSelect={handle} />Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
items | DropdownMenuItem[] | — | Menu items: { key, label, icon?, shortcut?, danger?, disabled?, textValue? }. shortcut is shown as a small muted chip. { type: 'separator' } is a divider. |
onSelect | (key) => void | — | Called when an item is chosen; the menu then closes and focus returns to the trigger. |
trigger | ReactNode | — | Custom trigger content, such as a “⋯” icon. When set, the label and arrow are hidden and the button becomes a round, transparent icon button. The outer element is still the component's own <button>; do not nest another. |
label | ReactNode | 'More' | Text of the default pill trigger, followed by an arrow that flips when open. |
placement | 'bottom-start' | 'bottom-end' | 'top-start' | 'top-end' | 'bottom-start' | Panel position relative to the trigger. It does not flip automatically; choose a direction near container edges. |
open | boolean | — | Controlled open state, used with onOpenChange. |
defaultOpen | boolean | false | Initial open state when uncontrolled; it does not take focus. |
onOpenChange | (open) => void | — | Called when the open state changes. |
disabled | boolean | false | Disables the trigger; an open menu closes. |
triggerProps | ButtonHTMLAttributes | — | Attributes passed to the trigger button, such as aria-label and className. |
...rest | HTMLAttributes<HTMLDivElement> | — | Other attributes, such as className and style, go to the root. Use --ds-menu-z to change the panel's layer (default 30). |
Accesibilidad
- Follows the WAI-ARIA Menu Button pattern: the trigger has aria-haspopup="menu", aria-expanded and aria-controls; the panel is role="menu" labelled by the trigger; items are role="menuitem" and dividers role="separator".
- On the trigger, Enter, Space and Down open and focus the first item, Up opens and focuses the last; inside, Up and Down wrap (skipping disabled items), Home and End jump to the ends, and typing jumps by first letter.
- Esc closes and returns focus to the trigger without closing an outer dialog; Tab closes and moves on; clicking outside or moving focus out closes it.
- After choosing, focus returns to the trigger; disabled items use aria-disabled, so they are read but cannot be chosen.
- The highlight pill is the focus, with an extra 2px inset outline for keyboard focus; rows are 38px high, and at least 44px on touch screens.
- With reduced motion, entering only fades without scaling or row stagger, and closing unmounts at once.
Movimiento
The panel enters in 220ms ease-out, scaling from 0.94 and dropping 6px from the trigger's corner; rows follow 14ms apart, each moving 4px. It exits in 140ms ease-in. The trigger turns ink and its arrow flips in 240ms; the highlight pill has no transition so it follows the mouse at once.
Añádelo a tu proyecto
Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.
DropdownMenu.jsxdropdown-menu.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.
Reglas de diseño que sigue
Plantillas que lo incluyen
- Plantilla Next.js de dashboard
- Plantilla Next.js de tienda online
- Plantilla Next.js de reservas
- Plantilla Next.js de landing page
- Plantilla Next.js de chat con IA
- Plantilla Next.js de blog
- Plantilla Next.js de página de evento
- Plantilla Next.js de portafolio
- Plantilla Next.js de documentación
- Plantilla Next.js SaaS

