We use cookies to ensure you get the best experience on our website. Read our privacy policy

Skip to main content

Directory

Dropdown Component

The Dropdown component creates interactive menus that expand and collapse with smooth animations. It’s perfect for navigation menus, settings panels, and any interface that needs to show and hide content on demand.

  • Check Circle

    Smooth Animations: Polished expand/collapse transitions

  • Check Circle

    Flexible Content: Supports both simple lists and custom content

  • Check Circle

    Click Outside: Optional automatic closing when clicking outside

  • Check Circle

    Keyboard Support: Full keyboard navigation and accessibility

  • Check Circle

    Customizable: Multiple styling and behavior options

Create a simple dropdown menu with a list of items:

<Dropdown
items={[
{ label: "Docs", href: "/docs/" },
{ label: "Blog", href: "/blog/" },
{ label: "Home", href: "/" }
]}
>
Menu
</Dropdown>

The dropdown maintains selection state and supports pre-selected values and disabled options.

<Dropdown
items={[
{ label: 'Default Option', value: '1', active: true },
{ label: 'Disabled Option', value: '2', disabled: true },
{ label: 'Regular Option', value: '3' },
]}
>
With States
</Dropdown>

The dropdown can be displayed as an overlay or menu inline with the trigger button.

<Dropdown overlay={false} class="mb-8" items={[{ label: 'Profile' }, { label: 'Settings' }, { label: 'Logout' }]}>
Menu
</Dropdown>

The component emits custom events for selection changes:

Waiting for events to be emitted… (Click on the menu to see the events)
// Listen for selection changes
document.querySelector('dropdown-wrapper')
.addEventListener(DropdownEventNames.Selected, (event) => {
const { dropdownId, active } = event.detail;
// Handle selection change
});
Dropdown Props Extends <div> HTMLElement
Prop Type Default Description
buttonProps ButtonProps Props for the trigger button
clickOutsideToClose boolean true Close dropdown when clicking outside
contentClass string Additional classes for dropdown content
itemProps ButtonProps Props applied to each menu item
items Array<Item> [] List of dropdown menu items
open boolean false Control initial open state
overlay boolean true Display as floating menu
preferOnScreen boolean true Shows the dropdown above the trigger button if it would extend beyond the viewport
showIcon boolean true Show/hide the chevron icon
showLines boolean false Show vertical lines for visual hierarchy
interface Item {
label?: string;
href?: string;
id?: string;
disabled?: boolean;
active?: boolean;
}
  • Enter/Space to toggle
  • Tab for focus management
  • Escape to close
  • aria-expanded state
  • aria-controls relationships
  • Proper focus management
User menus
Settings panels
Language selectors
Category filters
Share buttons
Export options
Bulk operations
Filter controls

Limited Time Launch Sale

Build professional dropdown menus with our pre-built component. Get the AstroJS starter template now and create engaging user interfaces instantly.

GET 60% OFF!
North Star Themes Logo

Subscribe to our newsletter

Get the latest AstroJS tips and tricks right to your inbox

Email: [email protected]

© 2025 North Star Themes

Web Kit Provided By North Star Themes