Skip to main content

Starwind UI v1.5.0 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.

<Dropdown>
{/* DropdownTrigger and DropdownContent */}
</Dropdown>
PropTypeDefaultDescription
openOnHoverbooleanfalseWhen true, the dropdown will open on hover in addition to click
closeDelaynumber200Time in milliseconds to wait before closing when hover open is enabled

The component accepts all standard HTML attributes for <div> elements.

The button that opens the dropdown menu when clicked.

<DropdownTrigger asChild>
<Button>Open</Button>
</DropdownTrigger>
PropTypeDefaultDescription
asChildbooleanfalseWhen true, the component will render its child element instead of a button component

The component accepts all standard HTML attributes for <button> elements.

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

<DropdownContent>
{/* DropdownItem, DropdownLabel, DropdownSeparator components */}
</DropdownContent>
PropTypeDefaultDescription
side"top" | "bottom""bottom"Side of the dropdown
align"start" | "center" | "end""start"Alignment of the dropdown
sideOffsetnumber4Offset distance in pixels
animationDurationnumber150Open and close animation duration in milliseconds

The component accepts all standard HTML attributes for <div> elements.

A component for creating interactive items within the dropdown menu.

<DropdownItem>Menu Item</DropdownItem>
PropTypeDefaultDescription
asHTMLTag"div"HTML element to render the item as (e.g., “a”, “button”, etc.)
insetbooleanfalseWhether the item is inset (has left padding)
disabledbooleanfalseWhether the item is disabled

The component accepts all standard HTML attributes for the specified element.

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

<DropdownLabel>Section Title</DropdownLabel>
PropTypeDefaultDescription
insetbooleanfalseWhether the label is inset (has left padding)

The component accepts all standard HTML attributes for <div> elements.

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

<DropdownSeparator />

The component accepts all standard HTML attributes for <div> elements.

Changelog

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