Dropdown Submenu

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

PropTypeDefaultDescription
itemsMenuItem[]defaultItemsMenu items to display
onItemClick(item) => void—Callback when a menu item is clicked
onSubmenuItemClick(parentId, item) => void—Callback when a submenu item is clicked
triggerReactNode'Options'Content of the trigger button
defaultOpenboolean—Open state on first render
openboolean—Controlled open state
onOpenChange(open: boolean) => void—Called when the menu opens or closes
classNamestring—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 items
const 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 state

Keyboard Navigation

KeyAction
Enter/Space/Arrow DownOpen the menu from the trigger
Arrow DownMove to next item
Arrow UpMove to previous item
Arrow RightOpen submenu
Arrow LeftClose submenu
Letter keysJump to the item that starts with the letter
EnterSelect item
EscapeClose 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