---
title: Dropdown Component
description: "A modern, accessible dropdown component for STX applications."
---
# Dropdown
A modern, accessible dropdown component for STX applications.
## Features
- 🎯 Fully accessible (WAI-ARIA compliant)
- 🌐 Keyboard navigation support
- 🎨 Customizable styling
- 📱 Mobile-friendly
- 🎯 TypeScript support
- 🎈 Floating UI integration
- 🔄 Auto-positioning
## Install
::: code-group
```sh [npm]
npm install @stacksjs/components
```
```sh [bun]
bun install @stacksjs/components
# bun add @stacksjs/components
# bun i @stacksjs/components
```
```sh [pnpm]
pnpm add @stacksjs/components
# pnpm i @stacksjs/components
```
```sh [yarn]
yarn add @stacksjs/components
# yarn i -d @stacksjs/components
```
:::
## Usage
The dropdown component is composed of several sub-components that work together to create a fully functional and accessible dropdown:
```html
Options
Account settings
Documentation
Invite a friend
```
## API Reference
### Dropdown
The root component that wraps all dropdown elements.
#### Props
- `as` - (string) The element to render as (default: 'div')
- `static` - (boolean) Whether the dropdown should always be rendered
### DropdownButton
The button that toggles the dropdown menu.
#### Props
- `as` - (string) The element to render as (default: 'button')
- `disabled` - (boolean) Whether the button is disabled
### DropdownItems
The container for dropdown menu items.
#### Props
- `as` - (string) The element to render as (default: 'div')
- `static` - (boolean) Whether the items should always be rendered
- `unmount` - (boolean) Whether to unmount the items when closed
### DropdownItem
Individual menu items within the dropdown.
#### Props
- `disabled` - (boolean) Whether the item is disabled
- `as` - (string) The element to render as (default: 'div')
#### Slot Props
The DropdownItem component exposes the following slot props:
- `active` - (boolean) Whether the item is currently active (focused)
- `disabled` - (boolean) Whether the item is disabled
- `close` - (function) Method to close the dropdown
## Styling
The dropdown components can be styled using standard CSS classes. Each component accepts standard HTML attributes including `class` and `style`.
For dynamic styling based on state, use the slot props provided by DropdownItem:
```html
{{ item.name }}
```
## Accessibility
The dropdown component follows WAI-ARIA guidelines and includes the following features:
- Proper ARIA attributes (aria-expanded, aria-haspopup)
- Keyboard navigation support
- Enter/Space to open/close
- Arrow keys for navigation
- Escape to close
- Focus management and focus trap
- Screen reader announcements
## TypeScript Support
The dropdown component includes full TypeScript support:
```ts
import type { DropdownItemProps } from '@stacksjs/components'
import { ref } from '@stacksjs/stx'
interface MenuItem {
name: string
href: string
disabled?: boolean
}
const items = ref