Dropdown Field
Dropdown Field Component
The Dropdown Field component provides a complete form field for selecting options from a dropdown menu with built-in label, validation, search functionality, and error handling.
Example
Required
- Electronics
- Clothing
- Home & Garden
- Sports
- Books
Select a product category
<div style="max-width:400px"><div class="w-full"><div class="space-y-1 wrapper group skin-form
}"><div class="flex justify-between items-center mx-2 "><div class="flex items-center space-x-2"><label class="text-body font-semi-bold" for="category">Category</label><span class="text-sm font-light soft" aria-hidden="true">Required</span></div></div><div class="input-field-wrapper"><div class="skin-form dropdown-wrapper group w-full" aria-invalid="false" aria-describedby="category-helper"><input type="hidden" required="" name="category" value=""/><div class="dropdown"><div class="wrapper" role="combobox" aria-expanded="false" aria-haspopup="listbox" aria-owns="dropdown-list-category" aria-controls="dropdown-list-category"><button id="dropdown-trigger-category" class="dropdown-summary interactive" role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-controls="dropdown-list-category" aria-labelledby="dropdown-label-category" aria-autocomplete="none" type="button" aria-required="true"><div class="dropdown-summary-content"><svg class="dropdown-icon" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" focusable="false"><path fill-rule="evenodd" d="M10 9a3 3 0 100-6 3 3 0 000 6zm-7 9a7 7 0 1114 0H3z" clip-rule="evenodd"></path></svg><span id="selected-value-dropdown-trigger-category" class="text-body">Select a category</span><svg class="dropdown-icon chevron" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" focusable="false"><path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg></div></button></div><div class="dropdown-content-wrapper"><ul id="dropdown-list-category" class="dropdown-list" role="listbox" aria-labelledby="dropdown-label-category" tabindex="-1"><li role="option" id="dropdown-list-category-option-1" class="text-body interactive " aria-selected="false" tabindex="-1">Electronics</li><li role="option" id="dropdown-list-category-option-2" class="text-body interactive " aria-selected="false" tabindex="-1">Clothing</li><li role="option" id="dropdown-list-category-option-3" class="text-body interactive " aria-selected="false" tabindex="-1">Home & Garden</li><li role="option" id="dropdown-list-category-option-4" class="text-body interactive " aria-selected="false" tabindex="-1">Sports</li><li role="option" id="dropdown-list-category-option-5" class="text-body interactive " aria-selected="false" tabindex="-1">Books</li></ul></div></div></div></div><div class="input-helper-wrapper"><p class="text-sm soft ml-2" id="category-helper">Select a product category</p></div></div></div></div><div style="max-width:400px"><div class="w-full"><div class="space-y-1 wrapper group skin-form
}"><div class="flex justify-between items-center mx-2 "><div class="flex items-center space-x-2"><label class="text-body font-semi-bold" for="category">Category</label><span class="text-sm font-light soft" aria-hidden="true">Required</span></div></div><div class="input-field-wrapper"><div class="skin-form dropdown-wrapper group w-full" aria-invalid="false" aria-describedby="category-helper"><input type="hidden" required="" name="category" value=""/><div class="dropdown"><div class="wrapper" role="combobox" aria-expanded="false" aria-haspopup="listbox" aria-owns="dropdown-list-category" aria-controls="dropdown-list-category"><button id="dropdown-trigger-category" class="dropdown-summary interactive" role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-controls="dropdown-list-category" aria-labelledby="dropdown-label-category" aria-autocomplete="none" type="button" aria-required="true"><div class="dropdown-summary-content"><svg class="dropdown-icon" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" focusable="false"><path fill-rule="evenodd" d="M10 9a3 3 0 100-6 3 3 0 000 6zm-7 9a7 7 0 1114 0H3z" clip-rule="evenodd"></path></svg><span id="selected-value-dropdown-trigger-category" class="text-body">Select a category</span><svg class="dropdown-icon chevron" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" focusable="false"><path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg></div></button></div><div class="dropdown-content-wrapper"><ul id="dropdown-list-category" class="dropdown-list" role="listbox" aria-labelledby="dropdown-label-category" tabindex="-1"><li role="option" id="dropdown-list-category-option-1" class="text-body interactive " aria-selected="false" tabindex="-1">Electronics</li><li role="option" id="dropdown-list-category-option-2" class="text-body interactive " aria-selected="false" tabindex="-1">Clothing</li><li role="option" id="dropdown-list-category-option-3" class="text-body interactive " aria-selected="false" tabindex="-1">Home & Garden</li><li role="option" id="dropdown-list-category-option-4" class="text-body interactive " aria-selected="false" tabindex="-1">Sports</li><li role="option" id="dropdown-list-category-option-5" class="text-body interactive " aria-selected="false" tabindex="-1">Books</li></ul></div></div></div></div><div class="input-helper-wrapper"><p class="text-sm soft ml-2" id="category-helper">Select a product category</p></div></div></div></div>Optional
- United States
- United Kingdom
- Canada
- Australia
- Germany
- France
- Japan
- Brazil
- India
<div style="max-width:400px;margin-top:20px"><div class="w-full"><div class="space-y-1 wrapper group skin-form
}"><div class="flex justify-between items-center mx-2 "><div class="flex items-center space-x-2"><label class="text-body font-semi-bold" for="country">Country</label><span class="text-sm font-light soft" aria-hidden="true">Optional</span></div></div><div class="input-field-wrapper"><div class="skin-form dropdown-wrapper group w-full" aria-invalid="false"><input type="hidden" name="country" value=""/><div class="dropdown"><div class="wrapper" role="combobox" aria-expanded="false" aria-haspopup="listbox" aria-owns="dropdown-list-country" aria-controls="dropdown-list-country"><button id="dropdown-trigger-country" class="dropdown-summary interactive" aria-haspopup="listbox" aria-expanded="false" aria-controls="dropdown-list-country" aria-labelledby="dropdown-label-country selected-value-dropdown-trigger-country" type="button"><div class="dropdown-summary-content"><svg class="dropdown-icon" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" focusable="false"><path fill-rule="evenodd" d="M10 9a3 3 0 100-6 3 3 0 000 6zm-7 9a7 7 0 1114 0H3z" clip-rule="evenodd"></path></svg><span id="selected-value-dropdown-trigger-country" class="text-body">Select your country</span><svg class="dropdown-icon chevron" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" focusable="false"><path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg></div></button></div><div class="dropdown-content-wrapper"><div class="dropdown-search-wrapper wrapper"><div class="search-input-wrapper"><svg class="dropdown-search-icon" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"><path fill-rule="evenodd" d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z" clip-rule="evenodd"></path></svg><input id="dropdown-search-country" class="dropdown-search-input text-body placeholder:soft" placeholder="Search for a country" type="search" autoComplete="off" value=""/></div></div><ul id="dropdown-list-country" class="dropdown-list" role="listbox" aria-labelledby="dropdown-label-country" tabindex="-1"><li role="option" id="dropdown-list-country-option-1" class="text-body interactive " aria-selected="false" tabindex="-1">United States</li><li role="option" id="dropdown-list-country-option-2" class="text-body interactive " aria-selected="false" tabindex="-1">United Kingdom</li><li role="option" id="dropdown-list-country-option-3" class="text-body interactive " aria-selected="false" tabindex="-1">Canada</li><li role="option" id="dropdown-list-country-option-4" class="text-body interactive " aria-selected="false" tabindex="-1">Australia</li><li role="option" id="dropdown-list-country-option-5" class="text-body interactive " aria-selected="false" tabindex="-1">Germany</li><li role="option" id="dropdown-list-country-option-6" class="text-body interactive " aria-selected="false" tabindex="-1">France</li><li role="option" id="dropdown-list-country-option-7" class="text-body interactive " aria-selected="false" tabindex="-1">Japan</li><li role="option" id="dropdown-list-country-option-8" class="text-body interactive " aria-selected="false" tabindex="-1">Brazil</li><li role="option" id="dropdown-list-country-option-9" class="text-body interactive " aria-selected="false" tabindex="-1">India</li></ul></div></div></div></div><div class="input-helper-wrapper"></div></div></div></div><div style="max-width:400px;margin-top:20px"><div class="w-full"><div class="space-y-1 wrapper group skin-form
}"><div class="flex justify-between items-center mx-2 "><div class="flex items-center space-x-2"><label class="text-body font-semi-bold" for="country">Country</label><span class="text-sm font-light soft" aria-hidden="true">Optional</span></div></div><div class="input-field-wrapper"><div class="skin-form dropdown-wrapper group w-full" aria-invalid="false"><input type="hidden" name="country" value=""/><div class="dropdown"><div class="wrapper" role="combobox" aria-expanded="false" aria-haspopup="listbox" aria-owns="dropdown-list-country" aria-controls="dropdown-list-country"><button id="dropdown-trigger-country" class="dropdown-summary interactive" aria-haspopup="listbox" aria-expanded="false" aria-controls="dropdown-list-country" aria-labelledby="dropdown-label-country selected-value-dropdown-trigger-country" type="button"><div class="dropdown-summary-content"><svg class="dropdown-icon" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" focusable="false"><path fill-rule="evenodd" d="M10 9a3 3 0 100-6 3 3 0 000 6zm-7 9a7 7 0 1114 0H3z" clip-rule="evenodd"></path></svg><span id="selected-value-dropdown-trigger-country" class="text-body">Select your country</span><svg class="dropdown-icon chevron" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" focusable="false"><path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg></div></button></div><div class="dropdown-content-wrapper"><div class="dropdown-search-wrapper wrapper"><div class="search-input-wrapper"><svg class="dropdown-search-icon" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"><path fill-rule="evenodd" d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z" clip-rule="evenodd"></path></svg><input id="dropdown-search-country" class="dropdown-search-input text-body placeholder:soft" placeholder="Search for a country" type="search" autoComplete="off" value=""/></div></div><ul id="dropdown-list-country" class="dropdown-list" role="listbox" aria-labelledby="dropdown-label-country" tabindex="-1"><li role="option" id="dropdown-list-country-option-1" class="text-body interactive " aria-selected="false" tabindex="-1">United States</li><li role="option" id="dropdown-list-country-option-2" class="text-body interactive " aria-selected="false" tabindex="-1">United Kingdom</li><li role="option" id="dropdown-list-country-option-3" class="text-body interactive " aria-selected="false" tabindex="-1">Canada</li><li role="option" id="dropdown-list-country-option-4" class="text-body interactive " aria-selected="false" tabindex="-1">Australia</li><li role="option" id="dropdown-list-country-option-5" class="text-body interactive " aria-selected="false" tabindex="-1">Germany</li><li role="option" id="dropdown-list-country-option-6" class="text-body interactive " aria-selected="false" tabindex="-1">France</li><li role="option" id="dropdown-list-country-option-7" class="text-body interactive " aria-selected="false" tabindex="-1">Japan</li><li role="option" id="dropdown-list-country-option-8" class="text-body interactive " aria-selected="false" tabindex="-1">Brazil</li><li role="option" id="dropdown-list-country-option-9" class="text-body interactive " aria-selected="false" tabindex="-1">India</li></ul></div></div></div></div><div class="input-helper-wrapper"></div></div></div></div>Required
- Alabama
- Alaska
- Arizona
- Arkansas
- California
Please select a state
<div style="max-width:400px;margin-top:20px"><div class="w-full"><div class="space-y-1 wrapper group skin-form
}"><div class="flex justify-between items-center mx-2 "><div class="flex items-center space-x-2"><label class="text-body font-semi-bold" for="dropdown-error">State/Province</label><span class="text-sm font-light soft" aria-hidden="true">Required</span></div></div><div class="input-field-wrapper"><div class="skin-form dropdown-wrapper group w-full" aria-invalid="true"><input type="hidden" required="" name="dropdown-error" value=""/><div class="dropdown"><div class="wrapper" role="combobox" aria-expanded="false" aria-haspopup="listbox" aria-owns="dropdown-list-dropdown-error" aria-controls="dropdown-list-dropdown-error"><button id="dropdown-trigger-dropdown-error" class="dropdown-summary interactive" role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-controls="dropdown-list-dropdown-error" aria-labelledby="dropdown-label-dropdown-error" aria-autocomplete="none" type="button" aria-required="true"><div class="dropdown-summary-content"><svg class="dropdown-icon" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" focusable="false"><path fill-rule="evenodd" d="M10 9a3 3 0 100-6 3 3 0 000 6zm-7 9a7 7 0 1114 0H3z" clip-rule="evenodd"></path></svg><span id="selected-value-dropdown-trigger-dropdown-error" class="text-body">Select your state</span><svg class="dropdown-icon chevron" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" focusable="false"><path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg></div></button></div><div class="dropdown-content-wrapper"><ul id="dropdown-list-dropdown-error" class="dropdown-list" role="listbox" aria-labelledby="dropdown-label-dropdown-error" tabindex="-1"><li role="option" id="dropdown-list-dropdown-error-option-1" class="text-body interactive " aria-selected="false" tabindex="-1">Alabama</li><li role="option" id="dropdown-list-dropdown-error-option-2" class="text-body interactive " aria-selected="false" tabindex="-1">Alaska</li><li role="option" id="dropdown-list-dropdown-error-option-3" class="text-body interactive " aria-selected="false" tabindex="-1">Arizona</li><li role="option" id="dropdown-list-dropdown-error-option-4" class="text-body interactive " aria-selected="false" tabindex="-1">Arkansas</li><li role="option" id="dropdown-list-dropdown-error-option-5" class="text-body interactive " aria-selected="false" tabindex="-1">California</li></ul></div></div></div></div><div class="input-helper-wrapper"><div class="alert skin-error"><div><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 256 256" fill="currentColor" class="h-6 w-6" aria-hidden="true"><path d="M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm0,192a88,88,0,1,1,88-88A88.1,88.1,0,0,1,128,216Zm-8-80V80a8,8,0,0,1,16,0v56a8,8,0,0,1-16,0Zm20,36a12,12,0,1,1-12-12A12,12,0,0,1,140,172Z"></path></svg></div><p class="flex items-center text-left" aria-live="polite">Please select a state</p></div></div></div></div></div><div style="max-width:400px;margin-top:20px"><div class="w-full"><div class="space-y-1 wrapper group skin-form
}"><div class="flex justify-between items-center mx-2 "><div class="flex items-center space-x-2"><label class="text-body font-semi-bold" for="dropdown-error">State/Province</label><span class="text-sm font-light soft" aria-hidden="true">Required</span></div></div><div class="input-field-wrapper"><div class="skin-form dropdown-wrapper group w-full" aria-invalid="true"><input type="hidden" required="" name="dropdown-error" value=""/><div class="dropdown"><div class="wrapper" role="combobox" aria-expanded="false" aria-haspopup="listbox" aria-owns="dropdown-list-dropdown-error" aria-controls="dropdown-list-dropdown-error"><button id="dropdown-trigger-dropdown-error" class="dropdown-summary interactive" role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-controls="dropdown-list-dropdown-error" aria-labelledby="dropdown-label-dropdown-error" aria-autocomplete="none" type="button" aria-required="true"><div class="dropdown-summary-content"><svg class="dropdown-icon" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" focusable="false"><path fill-rule="evenodd" d="M10 9a3 3 0 100-6 3 3 0 000 6zm-7 9a7 7 0 1114 0H3z" clip-rule="evenodd"></path></svg><span id="selected-value-dropdown-trigger-dropdown-error" class="text-body">Select your state</span><svg class="dropdown-icon chevron" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" focusable="false"><path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg></div></button></div><div class="dropdown-content-wrapper"><ul id="dropdown-list-dropdown-error" class="dropdown-list" role="listbox" aria-labelledby="dropdown-label-dropdown-error" tabindex="-1"><li role="option" id="dropdown-list-dropdown-error-option-1" class="text-body interactive " aria-selected="false" tabindex="-1">Alabama</li><li role="option" id="dropdown-list-dropdown-error-option-2" class="text-body interactive " aria-selected="false" tabindex="-1">Alaska</li><li role="option" id="dropdown-list-dropdown-error-option-3" class="text-body interactive " aria-selected="false" tabindex="-1">Arizona</li><li role="option" id="dropdown-list-dropdown-error-option-4" class="text-body interactive " aria-selected="false" tabindex="-1">Arkansas</li><li role="option" id="dropdown-list-dropdown-error-option-5" class="text-body interactive " aria-selected="false" tabindex="-1">California</li></ul></div></div></div></div><div class="input-helper-wrapper"><div class="alert skin-error"><div><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 256 256" fill="currentColor" class="h-6 w-6" aria-hidden="true"><path d="M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm0,192a88,88,0,1,1,88-88A88.1,88.1,0,0,1,128,216Zm-8-80V80a8,8,0,0,1,16,0v56a8,8,0,0,1-16,0Zm20,36a12,12,0,1,1-12-12A12,12,0,0,1,140,172Z"></path></svg></div><p class="flex items-center text-left" aria-live="polite">Please select a state</p></div></div></div></div></div>Usage
import DropdownField from "@altitude/ui/react/components/fields/dropdown-field";
export default function ProfileForm() { const [country, setCountry] = React.useState("");
const handleCountryChange = (e) => { setCountry(e.target.value); };
return ( <form> {/* Uncontrolled dropdown */} <DropdownField id="gender" name="gender" label="Gender" options={["Male", "Female", "Non-binary", "Prefer not to say"]} placeholder="Select your gender" required={false} />
{/* Controlled dropdown with search */} <DropdownField id="country" name="country" label="Country" options={[ "United States", "United Kingdom", "Canada", "Australia", "Germany", ]} enableSearch={true} searchPlaceholder="Search for a country" placeholder="Select your country" value={country} onChange={handleCountryChange} required={true} />
{/* More form fields */} <button type="submit">Save Profile</button> </form> );}Props
| Prop | Type | Required | Description |
|---|---|---|---|
| id | string | No | HTML ID for the field |
| name | string | No | HTML name attribute for the field |
| label | string | No | Label text for the field |
| helperText | string | No | Helper text displayed below the field |
| errorMessage | string | No | Error message displayed when aria-invalid is true |
| placeholder | string | No | Placeholder text for the dropdown |
| required | boolean | No | Whether the field is required (default: false) |
| aria-invalid | boolean | No | Whether the field has an error (default: false) |
| disabled | boolean | No | Whether the field is disabled (default: false) |
| options | string[] | No | Array of option strings to display in the dropdown |
| enableSearch | boolean | No | Enable search functionality in the dropdown (default: false) |
| noOptionsMessage | string | No | Message to display when no options are available (default: “No options available”) |
| searchPlaceholder | string | No | Placeholder text for the search input (default: “Search…“) |
| value | string | No | Current selected value (for controlled component) |
| onChange | function | No | Callback when selection changes (e) => void |
Implementation Details
The Dropdown Field component combines a field wrapper and a dropdown component:
- Uses
FieldWrapperto handle labels, error states, and helper text - Uses the base
DropdownUI component from the dropdown directory - Supports both standard and searchable dropdown patterns
- Automatically handles validation states and error messaging
- Can be used as both controlled and uncontrolled component