Dropdown Submenu
Navigation
Overlay
Multi-level dropdown with nested submenus for complex menu structures.
Preview
Open the menu, then hover or press Right arrow on an item to open its submenu
Props
Component API reference
DropdownSubmenu
| Prop | Type | Default | Description |
|---|---|---|---|
items | MenuItem[] | defaultItems | Menu items to display |
onItemClick | (item) => void | — | Callback when a menu item is clicked |
onSubmenuItemClick | (parentId, item) => void | — | Callback when a submenu item is clicked |
trigger | ReactNode | 'Options' | Content of the trigger button |
defaultOpen | boolean | — | Open state on first render |
open | boolean | — | Controlled open state |
onOpenChange | (open: boolean) => void | — | Called when the menu opens or closes |
className | string | — | Additional CSS classes for the menu panel |
MenuItem Types
MenuItemWithSubmenu
{ id: string, icon: LucideIcon, label: string, hasSubmenu: true, submenuItems: SubMenuItem[] }
MenuItemSimple
{ id: string, icon: LucideIcon, label: string, hasSubmenu?: false, shortcut?: string[] }
MenuItemSeparator
{ type: 'separator' }
SubMenuItem
{ id: string, icon?: LucideIcon, label: string, checked?: boolean }
Usage
Import and implementation examples
import { DropdownSubmenu } from '@/components/ui/dropdown-submenu'import { Eye, Settings, Grid3X3, List } from 'lucide-react'
// Basic usage: a button that opens the menu<DropdownSubmenu trigger="View options" />
// Custom menu itemsconst customItems = [ { id: 'view', icon: Eye, label: 'View', hasSubmenu: true, submenuItems: [ { id: 'grid', icon: Grid3X3, label: 'Grid', checked: true }, { id: 'list', icon: List, label: 'List' } ] }, { type: 'separator' }, { id: 'settings', icon: Settings, label: 'Settings', shortcut: ['⌘', ','] }]
<DropdownSubmenu items={customItems} onItemClick={(item) => console.log('Item clicked:', item)} onSubmenuItemClick={(parentId, item) => { console.log('Submenu item clicked:', parentId, item) }}/>Features
Built-in functionality
- Nested menus: View, Sort, and Filter submenus
- Hover expansion: Submenus open on hover or Right arrow
- Check marks: Checked submenu items use role="menuitemcheckbox"
- Icon support: Icons for visual clarity
- Keyboard shortcuts: Display shortcut hints
- Smooth transitions: Color transitions on highlight
- Customizable: Custom items and colors
Accessibility
Accessibility considerations
ARIA Attributes
Built on Radix Dropdown Menu (Sub, SubTrigger, SubContent)Uses role="menu" for menu containersrole="menuitem" for menu itemsaria-haspopup for the trigger and submenu triggersaria-expanded for open stateKeyboard Navigation
| Key | Action |
|---|---|
| Enter/Space/Arrow Down | Open the menu from the trigger |
| Arrow Down | Move to next item |
| Arrow Up | Move to previous item |
| Arrow Right | Open submenu |
| Arrow Left | Close submenu |
| Letter keys | Jump to the item that starts with the letter |
| Enter | Select item |
| Escape | Close menu and return focus to the trigger |
Notes
- Focus stays within the open menu
- Submenu closes when the pointer moves to another item
- Click outside closes the menu