# DropdownMenu

> A menu of actions or options that opens from a trigger button, with full keyboard navigation, submenus and real DOM focus on every item.

- Package: `fancy-ui-react` (React 18/19 + Tailwind CSS v4)
- Category: Navigation
- Tags: menu, dropdown, actions, compound, submenu, accessibility
- Types: `DropdownMenuProps`, `DropdownMenuTriggerProps`, `DropdownMenuContentProps`, `DropdownMenuItemProps`, `DropdownMenuSeparatorProps`, `DropdownMenuLabelProps`, `DropdownMenuSubProps`, `DropdownMenuSubTriggerProps`, `DropdownMenuSubContentProps`, `MenuContext`, `MenuCloseOptions`, `SubContext`, `DropdownMenuRootContext`
- Docs: https://fancy-ui.rama.app/docs/components/dropdown-menu
- Source: https://github.com/RamaHerbin/fancy-ui/tree/main/react/src/components/dropdown-menu

## Import

```tsx
import { DropdownMenu } from 'fancy-ui-react';
```

Setup (once per project): `npm install fancy-ui-react`, then put these lines in your main CSS file (the stylesheet import goes right after `@import "tailwindcss";`):

```css
@import "tailwindcss";
@import "fancy-ui-react/tailwind.css";
```

and import the component styles once in the app entry: `import "fancy-ui-react/styles.css";`. Full guide: https://fancy-ui.rama.app/llms.txt

The names below are the ones to write in React; when one differs from the Svelte name, the Svelte name follows in parentheses. `class` becomes `className`, a callback takes the name the React port declares (`onclick` becomes `onClick`), snippets become `ReactNode` props (render functions when they take arguments) and the default snippet is `children`. Divergences: https://github.com/RamaHerbin/fancy-ui/tree/main/react#divergences-from-the-svelte-api

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `open` | `boolean` | `false` | Whether the menu is open. Bindable |
| `onOpenChange` | `(open: boolean) => void` | — | Called whenever the menu opens or closes, however it happened |
| `side` | `"top" \| "bottom" \| "left" \| "right"` | `"bottom"` | Side of the trigger to place the menu on. Flips when it would overflow |
| `align` | `"start" \| "center" \| "end"` | `"start"` | Alignment along the trigger's cross axis |
| `offset` | `number` | `4` | Gap in pixels between the trigger and the menu |
| `loop` | `boolean` | `true` | Whether arrow-key navigation wraps at the ends |
| `sound` | `boolean` | `false` | Plays open and close on the trigger and submenus, and select on an item — one cue per interaction — once the user has enabled sound |

## Node props

| Prop | Description |
| --- | --- |
| `children` | The DropdownMenuTrigger and DropdownMenuContent |

## Example

```tsx
import {
	DropdownMenu,
	DropdownMenuContent,
	DropdownMenuItem,
	DropdownMenuSeparator,
	DropdownMenuTrigger,
} from "fancy-ui-react";

export function DropdownMenuExample() {
	return (
		<DropdownMenu sound>
			<DropdownMenuTrigger>Options</DropdownMenuTrigger>
			<DropdownMenuContent>
				<DropdownMenuItem onSelect={() => console.log("rename")}>Rename</DropdownMenuItem>
				<DropdownMenuItem onSelect={() => console.log("duplicate")}>Duplicate</DropdownMenuItem>
				<DropdownMenuItem onSelect={() => console.log("share")}>Share…</DropdownMenuItem>
				<DropdownMenuSeparator />
				<DropdownMenuItem variant="destructive" onSelect={() => console.log("delete")}>
					Delete
				</DropdownMenuItem>
			</DropdownMenuContent>
		</DropdownMenu>
	);
}
```
