The DropDownMenu component provides a dropdown menu interface for displaying actions, options, and navigation items. It's commonly used for action menus, settings panels, and any interface that needs a compact menu of options.
import { DropDownMenu } from '@dashflowx/core'export default function DropDownMenuExample() {const dropdownItems = [{ type: 'label', title: 'Actions' },{ type: 'item', title: 'Edit', shortcut: '⌘E' },{ type: 'item', title: 'Copy', shortcut: '⌘C' },{ type: 'seperator' },{ type: 'item', title: 'Delete', shortcut: '⌘⌫' }];return (<DropDownMenuactionButton="Open Menu"dropdownItems={dropdownItems}/>)}
Preview:
| Prop | Type | Default | Description |
|---|---|---|---|
actionButton | string | 'Open Menu' | The text for the trigger button |
dropdownItems | Array | [] | Array of dropdown menu items |
className | string | '' | Additional CSS classes for the container |
interface DropdownItem {type: 'label' | 'seperator' | 'group';title?: string | JSX.Element;shortcut?: string | JSX.Element;children?: DropdownItemChild[];}interface DropdownItemChild {type: 'item' | 'subMenu';title: string | JSX.Element;shortcut?: string | JSX.Element;subChildren?: DropdownSubChild[];}interface DropdownSubChild {title: string | JSX.Element;}
const basicItems = [{ type: 'label', title: 'Actions' },{ type: 'item', title: 'Edit', shortcut: '⌘E' },{ type: 'item', title: 'Copy', shortcut: '⌘C' },{ type: 'seperator' },{ type: 'item', title: 'Delete', shortcut: '⌘⌫' }];<DropDownMenuactionButton="Actions"dropdownItems={basicItems}/>
Preview:
const fileItems = [{ type: 'label', title: 'File' },{ type: 'item', title: 'New', shortcut: '⌘N' },{ type: 'item', title: 'Open', shortcut: '⌘O' },{ type: 'item', title: 'Save', shortcut: '⌘S' },{ type: 'seperator' },{ type: 'item', title: 'Export', shortcut: '⌘E' },{ type: 'item', title: 'Print', shortcut: '⌘P' }];<DropDownMenuactionButton="File"dropdownItems={fileItems}/>
Preview:
const userItems = [{ type: 'label', title: 'Account' },{ type: 'item', title: 'Profile', shortcut: '⌘P' },{ type: 'item', title: 'Settings', shortcut: '⌘,' },{ type: 'seperator' },{ type: 'item', title: 'Help', shortcut: '⌘?' },{ type: 'seperator' },{ type: 'item', title: 'Sign Out', shortcut: '⌘Q' }];<DropDownMenuactionButton="👤 User"dropdownItems={userItems}/>
Preview:
const groupedItems = [{type: 'group',title: 'Edit',children: [{ type: 'item', title: 'Undo', shortcut: '⌘Z' },{ type: 'item', title: 'Redo', shortcut: '⌘Y' },{ type: 'seperator' },{ type: 'item', title: 'Cut', shortcut: '⌘X' },{ type: 'item', title: 'Copy', shortcut: '⌘C' },{ type: 'item', title: 'Paste', shortcut: '⌘V' }]},{type: 'group',title: 'View',children: [{ type: 'item', title: 'Zoom In', shortcut: '⌘+' },{ type: 'item', title: 'Zoom Out', shortcut: '⌘-' },{ type: 'item', title: 'Reset Zoom', shortcut: '⌘0' }]}];<DropDownMenuactionButton="Options"dropdownItems={groupedItems}/>
Preview:
<DropDownMenuactionButton="Custom Menu"dropdownItems={basicItems}className="border-2 border-blue-500 rounded-xl"/>
Preview:
const actionItems = [{ type: 'label', title: 'Actions' },{ type: 'item', title: 'Edit', shortcut: '⌘E' },{ type: 'item', title: 'Duplicate', shortcut: '⌘D' },{ type: 'item', title: 'Move', shortcut: '⌘M' },{ type: 'seperator' },{ type: 'item', title: 'Archive', shortcut: '⌘A' },{ type: 'item', title: 'Delete', shortcut: '⌘⌫' }];<DropDownMenuactionButton="⚙️ Actions"dropdownItems={actionItems}/>
const settingsItems = [{ type: 'label', title: 'Settings' },{ type: 'item', title: 'Preferences', shortcut: '⌘,' },{ type: 'item', title: 'Keyboard Shortcuts', shortcut: '⌘/' },{ type: 'seperator' },{ type: 'item', title: 'Theme', shortcut: '⌘T' },{ type: 'item', title: 'Language', shortcut: '⌘L' },{ type: 'seperator' },{ type: 'item', title: 'About', shortcut: '⌘I' }];<DropDownMenuactionButton="⚙️ Settings"dropdownItems={settingsItems}/>
const navItems = [{ type: 'label', title: 'Navigation' },{ type: 'item', title: 'Dashboard', shortcut: '⌘1' },{ type: 'item', title: 'Projects', shortcut: '⌘2' },{ type: 'item', title: 'Tasks', shortcut: '⌘3' },{ type: 'item', title: 'Calendar', shortcut: '⌘4' },{ type: 'seperator' },{ type: 'item', title: 'Search', shortcut: '⌘K' },{ type: 'item', title: 'Notifications', shortcut: '⌘N' }];<DropDownMenuactionButton="🧭 Navigate"dropdownItems={navItems}/>
const filterItems = [{ type: 'label', title: 'Filter By' },{ type: 'item', title: 'All Items', shortcut: '⌘A' },{ type: 'item', title: 'Recent', shortcut: '⌘R' },{ type: 'item', title: 'Favorites', shortcut: '⌘F' },{ type: 'seperator' },{ type: 'item', title: 'By Date', shortcut: '⌘D' },{ type: 'item', title: 'By Type', shortcut: '⌘T' },{ type: 'item', title: 'By Status', shortcut: '⌘S' },{ type: 'seperator' },{ type: 'item', title: 'Clear Filters', shortcut: '⌘⌫' }];<DropDownMenuactionButton="🔍 Filter"dropdownItems={filterItems}/>
const exportItems = [{ type: 'label', title: 'Export' },{ type: 'item', title: 'PDF', shortcut: '⌘P' },{ type: 'item', title: 'Excel', shortcut: '⌘E' },{ type: 'item', title: 'CSV', shortcut: '⌘C' },{ type: 'seperator' },{ type: 'item', title: 'Print', shortcut: '⌘⌘P' },{ type: 'item', title: 'Email', shortcut: '⌘M' },{ type: 'seperator' },{ type: 'item', title: 'Share Link', shortcut: '⌘L' }];<DropDownMenuactionButton="📤 Export"dropdownItems={exportItems}/>
Use clear and descriptive labels for menu items.
// ✅ Good - Clear labelsconst items = [{ type: 'label', title: 'File Operations' },{ type: 'item', title: 'Save Document', shortcut: '⌘S' },{ type: 'item', title: 'Export as PDF', shortcut: '⌘E' }];// ❌ Avoid - Unclear labelsconst items = [{ type: 'label', title: 'File' },{ type: 'item', title: 'Save', shortcut: '⌘S' },{ type: 'item', title: 'Export', shortcut: '⌘E' }];
Group related menu items together with separators.
// ✅ Good - Logical groupingconst items = [{ type: 'label', title: 'Edit' },{ type: 'item', title: 'Cut', shortcut: '⌘X' },{ type: 'item', title: 'Copy', shortcut: '⌘C' },{ type: 'item', title: 'Paste', shortcut: '⌘V' },{ type: 'seperator' },{ type: 'item', title: 'Delete', shortcut: '⌘⌫' }];
Use consistent keyboard shortcuts across your application.
// ✅ Good - Consistent shortcutsconst items = [{ type: 'item', title: 'Copy', shortcut: '⌘C' },{ type: 'item', title: 'Paste', shortcut: '⌘V' },{ type: 'item', title: 'Cut', shortcut: '⌘X' }];
Avoid too many nested submenus.
// ✅ Good - Reasonable depthconst items = [{type: 'group',title: 'Format',children: [{ type: 'item', title: 'Bold', shortcut: '⌘B' },{ type: 'item', title: 'Italic', shortcut: '⌘I' }]}];// ❌ Avoid - Too deep nestingconst items = [{type: 'group',title: 'Format',children: [{type: 'subMenu',title: 'Text',children: [{type: 'subMenu',title: 'Style',children: [{ type: 'item', title: 'Bold', shortcut: '⌘B' }]}]}]}];
Show only relevant actions for the current context.
// ✅ Good - Contextual actionsconst getContextMenuItems = (context: string) => {switch (context) {case 'file':return fileItems;case 'text':return textItems;case 'image':return imageItems;default:return basicItems;}};
You can customize the dropdown menu appearance using CSS classes:
<DropDownMenuactionButton="Custom Styled"dropdownItems={items}className="border-2 border-purple-500 rounded-xl"/>
Use different themes for different contexts:
// Light theme<DropDownMenuactionButton="Light Theme"dropdownItems={items}className="bg-white border-gray-200"/>// Dark theme<DropDownMenuactionButton="Dark Theme"dropdownItems={items}className="bg-gray-900 border-gray-700 text-white"/>
Use different sizes for different emphasis levels:
// Small dropdown<DropDownMenuactionButton="Small"dropdownItems={items}className="w-40"/>// Large dropdown<DropDownMenuactionButton="Large"dropdownItems={items}className="w-80"/>
Load menu items dynamically based on context:
const [menuItems, setMenuItems] = useState([]);useEffect(() => {// Load menu items based on current contextconst contextItems = getMenuItemsForContext(currentContext);setMenuItems(contextItems);}, [currentContext]);
Handle menu item actions:
const handleMenuAction = (action: string) => {switch (action) {case 'copy':copyToClipboard();break;case 'paste':pasteFromClipboard();break;case 'delete':deleteItem();break;default:console.log('Unknown action:', action);}};
Show/hide menu items based on conditions:
const getConditionalMenuItems = (hasSelection: boolean, isEditable: boolean) => {const items = [];if (hasSelection) {items.push({ type: 'item', title: 'Copy', shortcut: '⌘C' });}if (isEditable) {items.push({ type: 'item', title: 'Paste', shortcut: '⌘V' });}return items;};
Implement keyboard navigation for accessibility:
const handleKeyDown = (event: KeyboardEvent) => {switch (event.key) {case 'ArrowDown':// Navigate to next itembreak;case 'ArrowUp':// Navigate to previous itembreak;case 'Enter':// Activate current itembreak;case 'Escape':// Close menubreak;}};
- ContextMenu: For right-click menus
- Menu: For general menus
- Popover: For popup content
- Button: For trigger buttons
- Tooltip: For menu item tooltips
For the complete API reference and advanced usage patterns, see the DropDownMenu API documentation.
