Skip to main content

Dropdown

A Dropdown is an interactive overlay menu anchored to a trigger element. It is built on top of the Popover component and is designed for action menus, navigation lists, and nested submenus.

Key Characteristics

  • Composable: Build menus declaratively using Dropdown.Menu, Dropdown.Section, Dropdown.Item, Dropdown.Divider, Dropdown.Header, and Dropdown.Footer.
  • Nestable: Create nested submenus with isNested - opens on hover with a caret indicator.
  • Polymorphic Items: Render items as any element (div, a, Link, etc.) using the as prop.
  • Accessible: Full keyboard navigation, focus management, and proper ARIA attributes built in.

Import

There are 7 dropdown-related components:

  • Dropdown: The main dropdown component.
  • DropdownTrigger: The element that toggles the dropdown.
  • DropdownMenu: The container for dropdown content.
  • DropdownItem: A clickable menu item.
  • DropdownSection: A group of items with an optional title.
  • DropdownDivider: A visual separator between sections.
  • DropdownHeader / DropdownFooter: Non-clickable top/bottom slots.
import {
Dropdown,
DropdownTrigger,
DropdownMenu,
DropdownItem,
DropdownSection,
DropdownDivider,
} from '@andrejground/lab';

Compound pattern is also supported:

  • Dropdown.Trigger
  • Dropdown.Menu
  • Dropdown.Item
  • Dropdown.Section
  • Dropdown.Divider
  • Dropdown.Header
  • Dropdown.Footer

Usage

Sections

Use Dropdown.Section to group items with titles, and Dropdown.Divider to visually separate groups.

Nested

Use isNested to create submenus. Nested dropdowns open on hover (and/or click) and display a caret indicator.

Keyboard navigation is fully supported between parent and child menus. Use Enter to open a nested menu, and Esc to close it.

Disabled Items

Use the disabled prop on Dropdown.Item to prevent interaction.

Polymorphic Items

Use the as prop to render items as different elements - links, anchors, or any other component.

Controlled

Open: false