Combo box
A combo box helps users select an item from a large list of options.
This component requires the following JavaScript plugins:
Example
Mobile
320pxMobile Lg
480pxTablet
640pxDesktop
1024px- No results found
Component API
Root
-
x-comboboxCustom Alpine directive that marks the Combobox Root.
Label
-
x-combobox:labelCustom Alpine directive that marks the Combobox Label.
-
idType:
stringUsed to link the Combobox Label to the Combobox List via
aria-labelledby. -
forType:
stringLinks the Combobox Label to the Combobox Input.
By default, this value should match the
idon theselectelement. When Javascript loads, this value will be updated to match theidof the Combobox Input.
Values
-
x-combobox:valuesCustom Alpine directive that marks the Combobox Values.
-
hiddenType:
boolean
Default:trueAttribute is applied when JavaScript is loaded to hide the initial
<select>element.Automatically handled with JavaScript.
Input
-
x-combobox:inputCustom Alpine directive that marks the Combobox Input.
-
idType:
stringUsed to link the Combobox Input to the Combobox Label via
for.Automatically handled with JavaScript.
-
roleValue:
'combobox'Automatically handled with JavaScript.
-
aria-expandedType:
boolean
Default:falseAccessibility attribute that communicates whether the Combobox List is expanded or collapsed.
Automatically handled with JavaScript.
-
aria-activedescendantType:
stringAccessibility attribute that communicates which, if any, Combobox Item is currently focused.
Automatically handled with JavaScript.
-
aria-controlsType:
stringAccessibility attribute that communicates that the Combobox Input controls the state of the Combobox List and visibility of Combobox Items.
Automatically handled with JavaScript.
-
aria-ownsType:
stringAccessibility attribute establishes the contextual relationship between the Combobox Input and the Combobox List
Automatically handled with JavaScript.
List
-
x-combobox:listCustom Alpine directive that marks the Combobox List.
-
roleType:
string
Value:'listbox'Automatically handled with JavaScript.
-
aria-labelledbyType:
stringAccessibility attribute that links the Combobox List to the Combobox Label via
id.Automatically handled with JavaScript.
-
tabindexType:
number
Value:-1Prevents users from tabbing to this element.
Automatically handled with JavaScript.
Item
-
x-combobox:itemCustom Alpine directive that marks the Combobox Item.
-
idType:
stringUsed to link the Combobox Item to the Combobox Input via
aria-activedescendant.Automatically handled with JavaScript.
-
roleValue:
'option'Automatically handled with JavaScript.
-
aria-selectedType:
boolean
Default:falseAccessibility attribute the communicates the selected state of the Combobox Item.
Automatically handled with JavaScript.
-
data-activeType:
boolean
Default:falseAttribute used to style the the Combobox Item element when hovered or focused. Defaults to
false, set totruewhen an item is hovers or focused.Automatically handled with JavaScript.
-
tabindexType:
number
Default:-1Prevents users from tabbing to this element. Defaults to
-1, set to0when item it hovered or focused.Automatically handled with JavaScript.
Toggle Button
-
x-combobox:toggleCustom Alpine directive that marks the Combobox Toggle Button.
-
aria-labelType:
stringAutomatically handled with JavaScript.
-
tabindexType:
number
Value:-1Prevents users from tabbing to this element.
Automatically handled with JavaScript.
Clear Button
-
x-combobox:clearCustom Alpine directive that marks the Combobox Clear Button.
-
aria-labelType:
stringAutomatically handled with JavaScript.
-
tabindexType:
number
Value:-1Prevents users from tabbing to this element.
Automatically handled with JavaScript.
Keyboard Interactions
-
Down Arrow
When focus is on an Combobox Input, opens the Combobox List and moves focus on the currently selected that Combobox Item. Otherwise, moves focus to the first Combobox Item.
When focus is on an Combobox Item, moves focus to the previous focusable element.
When focus is on the first Combobox Item in a Combobox List, moves focus to the Combobox Input.
-
Up Arrow
When focus is on an Combobox Input, opens the Combobox List and moves focus on the currently selected that Combobox Item. Otherwise, moves to the last Combobox Item.
When focus is on an Combobox Item, moves focus to the next focusable element.
When focus is on the last Combobox Item in a Combobox List, focus moves to the Combobox Input.
-
Enter
When focus is on an Combobox Item, selects the current value and sets the cursor at the end of the selected value in the Combobox Input.
-
Escape
When the Combobox List is open, closes the Combobox List and moves focus to the Combobox Input.
Progressive Enhancement
Because this component heavily relies on Javascript, in environments where Javascript isn’t present or hasn’t yet loaded, this component falls back to the native <select> element. When Javascript is loaded, the <select> element will be hidden and all options will be passed to the Combobox component.
This ensures that users will always be able to interact with a functional component regardless of their connectivity or browser settings.