Combobox
A combobox component that combines a text input with a dropdown list of options.
Code
<Combobox
id="country"
label="Select a country"
options={[
{ id: 'us', label: 'United States' },
{ id: 'ca', label: 'Canada' },
{ id: 'mx', label: 'Mexico' },
{ id: 'uk', label: 'United Kingdom' },
{ id: 'fr', label: 'France' }
]}
required={true}
autocomplete={true}
/>
Props
Name | Type | Required | Description |
---|---|---|---|
id |
string | No | Unique identifier for the combobox. Auto-generated if not provided |
name |
string | No | Name attribute for the input. Defaults to id if not provided |
label |
string | Yes | Label text for the combobox |
options |
Option[] | Yes | Array of options available for selection |
value |
string | No |
Initial value for the combobox input
Default: ""
|
required |
boolean | No |
Whether the combobox is required
Default: false
|
disabled |
boolean | No |
Whether the combobox is disabled
Default: false
|
autocomplete |
boolean | No |
Whether to enable autocomplete functionality
Default: false
|
Option Props
Name | Type | Required | Description |
---|---|---|---|
id |
string | Yes | Unique identifier for the option |
label |
string | Yes | Display text for the option |
Usage
✅ Do’s
- Use for large lists of options that need filtering
- Provide clear, descriptive labels
❌ Don’t’s
- Don’t use for simple yes/no choices (use radio buttons instead)
- Don’t use for very small lists (use select instead)
Accessibility
Keyboard Navigation
- Tab key moves focus to the combobox
- Typing in the input filters options automatically
- Arrow Down opens the dropdown and navigates to the next option
- Arrow Up navigates to the previous option
- Enter selects the currently focused option
- Escape closes the dropdown
- Options list automatically collapses when focus moves outside
Screen Reader Support
- The combobox interface context is announced to screen readers
- Uses
role="combobox"
for the input - Uses
role="listbox"
for the options container - Uses
role="option"
for individual options aria-expanded
indicates dropdown statearia-controls
associates the input with the listboxaria-selected
indicates the selected option