Skip to main content

Dropdown Menu

StorybookView in Storybook

Explore interactive examples and all component variations in our Storybook.

The DropdownMenu component displays a menu of actions or options that appears when triggered. Built on Radix UI primitives, it supports keyboard navigation, submenus, checkboxes, radio groups, and keyboard shortcuts.

Basic Usage

Properties

PropertyTypeDescription
openbooleanThe controlled open state of the dropdown menu.
defaultOpenbooleanThe open state when initially rendered.
onOpenChange(open: boolean) => voidEvent handler called when the open state changes.
modalbooleanThe modality of the dropdown menu. Default: true.
PropertyTypeDescription
asChildbooleanChange the default rendered element for the one passed as a child.
childrenReact.ReactNodeThe element that will trigger the dropdown menu.
PropertyTypeDescription
classNamestringAdditional CSS classes for custom styling.
sideOffsetnumberThe distance in pixels from the trigger. Default: 4.
align"start" | "center" | "end"The preferred alignment against the trigger.
side"top" | "right" | "bottom" | "left"The preferred side of the trigger to render against.
PropertyTypeDescription
insetbooleanWhether the item should have an inset appearance.
disabledbooleanWhether the item is disabled.
onSelect(event: Event) => voidEvent handler called when the item is selected.
classNamestringAdditional CSS classes for custom styling.
PropertyTypeDescription
checkedboolean | "indeterminate"The controlled checked state of the item.
onCheckedChange(checked: boolean) => voidEvent handler called when the checked state changes.
disabledbooleanWhether the item is disabled.
classNamestringAdditional CSS classes for custom styling.
PropertyTypeDescription
valuestringThe controlled value of the radio group.
onValueChange(value: string) => voidEvent handler called when the value changes.
PropertyTypeDescription
valuestringThe unique value of the item.
disabledbooleanWhether the item is disabled.
classNamestringAdditional CSS classes for custom styling.
PropertyTypeDescription
insetbooleanWhether the label should have an inset appearance.
classNamestringAdditional CSS classes for custom styling.
PropertyTypeDescription
classNamestringAdditional CSS classes for custom styling.
PropertyTypeDescription
classNamestringAdditional CSS classes for custom styling.
childrenReact.ReactNodeThe shortcut text (e.g., "⌘K").

Accessibility

The DropdownMenu component includes comprehensive accessibility features:

  • Keyboard Navigation - Arrow keys, Enter, Escape, and Tab support
  • Focus Management - Proper focus handling and restoration
  • Screen Reader Support - ARIA attributes and roles for assistive technologies
  • Type-ahead - Users can type to navigate to menu items
  • Roving Tabindex - Only one menu item is tabbable at a time

Common Use Cases

The DropdownMenu component is perfect for:

  • Context Menus - Right-click or action menus for items
  • Navigation Menus - User account menus, settings, help
  • Action Menus - File operations, editing actions, bulk operations
  • Filter Menus - View options, sorting, filtering controls
  • Settings Panels - Theme selection, preferences, configurations
  • Quick Actions - Frequently used commands and shortcuts

Best Practices

  1. Logical Grouping - Group related items together with separators
  2. Clear Labels - Use descriptive text that clearly indicates the action
  3. Consistent Icons - Use icons consistently throughout the menu
  4. Keyboard Shortcuts - Include shortcuts for frequently used actions
  5. Appropriate Width - Set reasonable width to accommodate content
  6. Loading States - Show loading indicators for async operations
  7. Error Handling - Disable items that aren't currently available
  8. Mobile Considerations - Ensure touch targets are appropriately sized