GitHub
Core
Glass
Brutal
Humanist

Dropdown

Dropdowns allow users to select a single option from a list. They support search, floating labels, and six leading item types — icons, avatars, brand logos, country flags, images, and plain text.

Dropdown Playground
Preview
Code
Controls
Size:
Small
Default
Large
Type:
Default
Prefixed
Inline
Leading Item:
None
Icon
Avatar
Brand
Image
Country
Search:
Floating Label:
Disabled:

Installation

You can add the dropdown component to your project manually:

1

Install the following dependencies:

npm install class-variance-authority clsx tailwind-merge @phosphor-icons/react @floating-ui/react @react-aria/focus @react-aria/button @react-aria/interactions
2

Copy and paste the following code into your project.

Loading source code...
3

Update the import paths to match your project setup.

Update the import aliases (e.g. @/components, @/utils) in the copied files to match your project's path configuration.

Basic Usage

import { Dropdown } from '@versaui/ui/components/Dropdown';

const options = [
  { value: 'apple', label: 'Apple' },
  { value: 'banana', label: 'Banana' },
  { value: 'cherry', label: 'Cherry' },
];

<Dropdown
  options={options}
  placeholder="Select fruit"
  onChange={(value, option) => console.log(option.label)}
/>

Three layout types are available:

// Default — floating label with full input
<Dropdown options={options} label="Category" />

// Prefixed Label — label shown as prefix
<Dropdown type="prefixedLabel" label="Country" options={countries} />

// Inline — compact inline style
<Dropdown type="inline" options={options} />

Size Variants

<Dropdown size="small" options={options} />
<Dropdown size="default" options={options} />
<Dropdown size="large" options={options} />

Leading Item Types

Options can include various leading item types for richer selection UIs:

// Icons
const options = [
  { value: 'settings', label: 'Settings', leadingType: 'icon', leadingItem: <GearIcon /> },
];

// Avatars
const options = [
  { value: 'user1', label: 'Adam Smith', leadingType: 'avatar', leadingItem: <Avatar size="xxs" type="image" person="adam-smith" /> },
];

// Country Flags
const options = [
  { value: 'us', label: 'United States', leadingType: 'country', leadingItem: <CountryFlag country="us" size="medium" /> },
];

// Brand Icons
const options = [
  { value: 'github', label: 'GitHub', leadingType: 'brand', leadingItem: <BrandIcon platform="github" size={16} /> },
];

Controlled Usage

const [selected, setSelected] = useState<string>();

<Dropdown
  options={options}
  value={selected}
  onChange={(value) => setSelected(value)}
/>
interface DropdownOption {
  value: string;                    // Unique option value
  label: string;                    // Display label
  leadingType?: 'none' | 'icon' | 'avatar' | 'brand' | 'country' | 'image';
  leadingItem?: ReactNode;          // Leading element (icon, avatar, etc.)
  disabled?: boolean;               // Disabled state
}

Accessibility

  • Uses role="listbox" with proper aria-expanded and aria-activedescendant
  • Keyboard navigation: arrow keys, Enter to select, Escape to close
  • Search input is automatically focused when opened
  • Selected option announced to screen readers
PropTypeDefaultDescription
optionsDropdownOption[]Required. Array of selectable options.
size'small' | 'default' | 'large''default'Dropdown size variant.
type'default' | 'prefixedLabel' | 'inline''default'Visual layout type.
valuestringControlled selected value.
defaultValuestringInitial value for uncontrolled usage.
placeholderstring'Select...'Placeholder text.
labelstring'Label'Label text (visible in default and prefixedLabel types).
disabledbooleanfalsePrevents interaction.
showSearchbooleantrueShow search input in menu.
searchPlaceholderstring'Search'Placeholder for the search input.
floatingLabelbooleantrueUse floating label animation.
fullWidthbooleanfalseExpand to fill container width.
menuMaxHeightnumber | string300Maximum height of the dropdown menu.
onChange(value: string, option: DropdownOption) => voidCalled when selection changes.
classNamestring''Additional CSS classes.
PropTypeDefaultDescription
sizeDropdownInputSize'default'Input size.
typeDropdownInputType'default'Input layout type.
labelstring'Label'Label text.
placeholderstring'Select'Placeholder text.
valuestringDisplay value.
isOpenbooleanWhether dropdown is open.
disabledbooleanDisabled state.
floatingLabelbooleantrueUse floating label.
PropTypeDefaultDescription
sizeMenuSize'default'Menu size.
showSearchbooleantrueShow search input.
searchPlaceholderstring'Search'Search placeholder text.
maxHeightnumber | stringMaximum menu height.
PropTypeDefaultDescription
sizeMenuItemSize'default'Item size.
leadingItemMenuItemLeadingType'none'Leading item type (icon, avatar, etc.).
selectedbooleanSelected state.
disabledbooleanDisabled state.

On this page