Skip to main content

Starwind UI v1.12 is now available!

Dropdown

Installation

Usage

A common use case is a standard navigation menu dropdown, where all items are likely links. Here is an example making use of the as prop on DropdownItem.

Hover Open

The dropdown can be configured to open on hover in addition to click.

Placement Options

You can position the dropdown menu in different ways by customizing the side and align properties.

With Icons

You can add icons to dropdown items for better visual cues.

API Reference

The root component that serves as a container for all dropdown-related components. It manages the state of the dropdown and handles keyboard interactions.

PropTypeDefault
openOnHoverbooleanfalse
closeDelaynumber200
classstring-
<Dropdown openOnHover closeDelay={300}>
<!-- Dropdown components -->
</Dropdown>

Additional Notes:

  • openOnHover: When enabled, the dropdown will open on hover in addition to click
  • closeDelay: Time in milliseconds to wait before closing when hover open is enabled

The button that opens the dropdown menu when clicked.

PropTypeDefault
asChildbooleanfalse
classstring-
<DropdownTrigger asChild>
<Button>Open</Button>
</DropdownTrigger>

Additional Notes:

  • asChild: When enabled, renders the child element instead of a button

The container for dropdown menu content. This component renders the dropdown menu with animation effects.

PropTypeDefault
side"top" | "bottom""bottom"
align"start" | "center" | "end""start"
sideOffsetnumber4
animationDurationnumber150
classstring-
<DropdownContent align="center" sideOffset={8}>
<!-- Dropdown items -->
</DropdownContent>

Additional Notes:

  • side: Side of the dropdown relative to the trigger
  • align: Alignment of the dropdown relative to the trigger
  • sideOffset: Offset distance in pixels from the trigger
  • animationDuration: Open and close animation duration in milliseconds

A component for creating interactive items within the dropdown menu.

PropTypeDefault
asHTMLTag"div"
insetbooleanfalse
disabledbooleanfalse
classstring-
<DropdownItem as="a" href="#">Menu Item</DropdownItem>

Additional Notes:

  • as: HTML element to render the item as (e.g., “a”, “button”)
  • inset: Whether the item has left padding for alignment with items that have icons

A component for rendering a non-interactive label within the dropdown menu.

PropTypeDefault
insetbooleanfalse
classstring-
<DropdownLabel>Section Title</DropdownLabel>

Additional Notes:

  • inset: Whether the label has left padding for alignment with items that have icons

A component for creating a visual separator between dropdown menu items.

PropTypeDefault
classstring-
<DropdownSeparator />

Changelog

v1.2.2

  • use class:list to remove potential “undefined” on DropdownTrigger

v1.2.1

  • Removed debug logging statements

v1.2.0

  • style and focus state updates

v1.1.0

  • Add a data-slot attribute to all components to enable global styling updates

v1.0.3

  • Only return focus to the dropdown trigger on dropdown close if the keyboard was involved (not for clicks or pointer events)
  • Fix exit animation

v1.0.2

  • Fix race condition when using hover dropdown caused by entering the DropdownTrigger while it’s closing
  • Add ability to pass additional classes to DropdownTrigger when using asChild
  • Remove unnecessary role="button" on DropdownTrigger

v1.0.1

  • Fix dropdown hover bug on mobile - change from mouse events to pointer events and ensure hover events do not fire for touch devices
  • Allow scrolling on touch devices without closing the dropdown menu by using pointerdown event only for mouse and using click event otherwise
  • Remove unused “name” prop from Dropdown.astro

v1.0.0

  • Initial component release with starwind v1.5.0