Skip to content

Dropdown

The DropdownMenu component provides a versatile and accessible way to present a list of actions or navigation links to the user in a compact, popover-like menu. It’s ideal for user profiles, settings, or contextual actions where space is limited.

Add the DropdownMenu component and its sub-components to your project using the OrbitUI CLI:

Terminal window
npx orbitkit@latest add dropdown

Import the DropdownMenu component along with its sub-components: DropdownMenuContent, DropdownMenuLabel, DropdownMenuGroup, DropdownMenuItem, and DropdownMenuSeparator.

Place your trigger element (e.g., a Button) directly inside the DropdownMenu component and add the data-trigger attribute to it. The DropdownMenuContent will house the actual menu items.

Organize your menu items using DropdownMenuGroup for logical grouping, DropdownMenuLabel for group titles, and DropdownMenuSeparator for visual dividers. Individual actions or links should be DropdownMenuItems.

The DropdownMenu system consists of several components, each with its own set of props:

The DropdownMenu component serves as the main wrapper for the dropdown menu system. It manages the menu’s open/closed state.

This component primarily acts as a container and does not accept explicit props. Its functionality is driven by a client-side JavaScript initialization script.

The DropdownMenuContent component contains the actual items of the dropdown menu. It controls the menu’s positioning relative to its trigger, size, and appearance.

The DropdownMenuContent component accepts the following props:

PropTypeDefault
sidetop, bottom, left, rightbottom
alignmentstart, center, endstart
sideOffsetnumber2
arrowbooleanfalse
  • side: Defines the primary position of the tooltip relative to the element that triggers it.
  • alignment: Defines how the tooltip is aligned horizontally or vertically in relation to the triggering element.
  • sideOffset: The distance in pixels between the trigger and the tooltip content.
  • arrow: a small arrow pointing to the trigger will be rendered on the tooltip.

This component accepts all the standard HTML attributes that a <div> element would.

The DropdownMenuLabel component is used to provide a non-interactive label or heading within the dropdown menu, typically used to title groups of items.

This component accepts all the standard HTML attributes that a <div> element would.

The DropdownMenuGroup component is used to semantically group related DropdownMenuItems together within the dropdown content.

This component accepts all the standard HTML attributes that a <div> element would.

The DropdownMenuItem component represents an individual, interactive item within the dropdown menu. It can act as a button or a link.

PropTypeDefault
asHTMLTagdiv
disabledbooleanfalse
  • as: Allows the component to be rendered as a different HTML tag. Useful for rendering an item as an <a> tag for navigation links or a <button> for actions, inheriting appropriate semantic behavior.
  • disabled: If true, the menu item will be visually styled as disabled and will not be interactive. Its tabindex will be set to -1.

This component accepts all the standard HTML attributes relevant to the tag it renders (as prop), such as href for <a> tags or onClick for <div> or <button> elements.

The DropdownMenuSeparator component renders a visual line to separate groups of menu items, enhancing readability and organization. This component accepts all the standard HTML attributes that a <div> element would.