Docs
Dropdown Menu
Dropdown Menu

A flexible dropdown menu component with smooth animations, smart positioning, and customizable styling.

9 views
0 downloads
Loading...

Overview

The Dropdown Menu component provides a compound component pattern for creating interactive dropdown menus with smooth animations, keyboard navigation, and smart positioning. It automatically adjusts placement based on available screen space and supports multiple alignment options.

Installation

pnpm dlx shadcn@latest add https://deltacomponents.dev/r/dropdown-menu.json

Usage

1"use client"
2
3import * as React from "react"
4import { LogOut, Settings, User } from "lucide-react"
5
6import {
7 Dropdown,
8 DropdownContent,
9 DropdownItem,
10 DropdownSeparator,
11 DropdownTrigger,
12} from "@/components/dropdown-menu"
13
14export function UserMenu() {
15 return (
16 <Dropdown>
17 <DropdownTrigger>
18 <button className="p-2 rounded-md border">
19 <User className="h-4 w-4" />
20 </button>
21 </DropdownTrigger>
22 <DropdownContent align="end">
23 <DropdownItem>
24 <Settings className="h-4 w-4 mr-2" />
25 Settings
26 </DropdownItem>
27 <DropdownSeparator />
28 <DropdownItem destructive>
29 <LogOut className="h-4 w-4 mr-2" />
30 Log out
31 </DropdownItem>
32 </DropdownContent>
33 </Dropdown>
34 )
35}

API Reference

The root container component that provides context for all dropdown subcomponents.

NameTypeDefaultDescription
childrenReactNode-The dropdown trigger and content components
classNamestring-Additional CSS classes for the dropdown container

The trigger element that opens/closes the dropdown when clicked.

NameTypeDefaultDescription
childrenReactNode-The trigger content (button, avatar, etc.)
classNamestring-Additional CSS classes for the trigger

The content container that appears when the dropdown is open.

NameTypeDefaultDescription
childrenReactNode-The dropdown items and separators
classNamestring-Additional CSS classes for the content
align"start" | "center" | "end""start"Horizontal alignment relative to trigger
side"left" | "right""left"Which side to align from
placement"top" | "bottom" | "auto""auto"Vertical placement relative to trigger
sideOffsetnumber1Distance from trigger in pixels

Individual clickable items within the dropdown.

NameTypeDefaultDescription
childrenReactNode-The item content
classNamestring-Additional CSS classes for the item
onClick() => void-Callback when item is clicked
disabledbooleanfalseWhether the item is disabled
destructivebooleanfalseWhether to style as destructive action

A visual separator between dropdown items.

NameTypeDefaultDescription
classNamestring-Additional CSS classes for the separator

Features

Smart Positioning

The dropdown automatically adjusts its position based on available screen space when placement="auto" is used.

Keyboard Navigation

  • Escape: Closes the dropdown
  • Tab: Normal tab navigation
  • Click outside: Closes the dropdown

Animations

Smooth spring-based animations using Framer Motion with proper transform origins based on positioning.

Accessibility

  • Proper ARIA attributes
  • Keyboard navigation support
  • Focus management
  • Screen reader friendly

Examples

Different Alignments

1// Align to start (left/right edge)
2<DropdownContent align="start">
3 {/* items */}
4</DropdownContent>
5
6// Center alignment
7<DropdownContent align="center">
8 {/* items */}
9</DropdownContent>
10
11// Align to end (opposite edge)
12<DropdownContent align="end">
13 {/* items */}
14</DropdownContent>

Custom Positioning

1// Position above trigger
2<DropdownContent placement="top" sideOffset={12}>
3 {/* items */}
4</DropdownContent>
5
6// Position below with custom offset
7<DropdownContent placement="bottom" sideOffset={4}>
8 {/* items */}
9</DropdownContent>

With Icons and States

1<DropdownContent>
2 <DropdownItem>
3 <User className="h-4 w-4 mr-2" />
4 Profile
5 </DropdownItem>
6 <DropdownItem disabled>
7 <Settings className="h-4 w-4 mr-2" />
8 Settings (disabled)
9 </DropdownItem>
10 <DropdownSeparator />
11 <DropdownItem destructive>
12 <LogOut className="h-4 w-4 mr-2" />
13 Delete Account
14 </DropdownItem>
15</DropdownContent>

Profile Dropdown

A more complex example with user profile information:

Loading...

Auto-Positioning

Demonstrates the smart positioning feature where dropdowns automatically adjust their placement based on available screen space:

Loading...