Stylable Select Element has emerged. This element, inspired by the traditional <select>
but with enhanced flexibility and customizability, allows developers to create button-triggered dropdowns with unique appearances and behaviors. Paired with <datalist>
and including <option>
and <optgroup>
for structuring choices, the Stylable Select Element presents a modern, adaptable, and accessible solution for web controls.
Right now, many websites have their own type of ‘combobox’, but they’re all a bit different. We often see a mix of <input>
fields and <datalist>
elements trying to do the job, but it’s not quite perfect. By creating a standard <combobox>
, we’re aiming to simplify things.
Further highlighting the need for such a solution, a recent Twitter poll run by the Open UI Community Group underscored the widespread demand for a standardized combobox
This proposal for <combobox>
leverages the strengths of the Stylable Select Element and <datalist>
, offering developers a versatile control that is intuitive for users and accessible to all. By establishing such a standard, we strive to bridge the gap between design requirements and the necessity for performant, reliable, and universally accessible web controls.
This document aims to provide a complete view of combo-box utilisation across the web to inform a potential proposal within Open UI. The goal of this document is to propose a very basic anatomy to simplify the initial shipment of <combobox>
(or some other name) in the web platform. It will heavily build upon stylable select
but provide a better accessible and extensible solution than that of an input
bound with datalist
.
<combobox>
<input type="text"/>
<button><selectedoption></selectedoption></button>
<datalist>
<option>Create a merge commit</option>
<option>Squash and merge</option>
<option>Rebase and merge</option>
</datalist>
</combobox>
<combobox>
: The root container that encapsulates the entire combobox
structure. It provides context for the interaction between the input
and the datalist
.<input type=text>
: This is where the user can type input. It acts as the trigger to display the datalist. In addition to the commonly used text type, other supported input types that could be effectively utilized within the combobox including, search for query inputs, email for email addresses, url for web addresses, and tel for telephone numbers, each tailored to optimize user interaction and data entry specific to its context.datalist
.The <combobox>
doesn’t need much to get started. Here’s how you can set it up with the basics:
<combobox>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</combobox>
When an author uses it like this, the combobox creates the parts they need: an input to drop down the list, a place showing your selected option, and the datalist
itself.
To showcase the selected option within a combobox
, you can include a <selectedoption>
element. This allows you to present the chosen value separately from the input
element,
<combobox>
<input type="text" placeholder="Select or type an item...">
<button><selectedoption></selectedoption></button>
<datalist>
<option>Apple</option>
<option>Banana</option>
<!-- Group of options with a legend -->
<optgroup>
<legend>Citrus Fruits</legend>
<option>Orange</option>
<option>Lemon</option>
</optgroup>
<!-- Another group of options with a legend -->
<optgroup>
<legend>Berries</legend>
<option>Strawberry</option>
<option>Blueberry</option>
</optgroup>
</datalist>
</combobox>
filter
attributeSection titled Introducing%20filter%20attributeThe filter
bool attribute enhances the <combobox>
by dynamically narrowing down choices to match user input, making selection faster and more intuitive.
<combobox filter>
<input type="text" placeholder="Select fruit">
<datalist>
<option>Apple</option>
<option>Apricot</option>
<option>Banana</option>
<!-- ... -->
</datalist>
</combobox>
Here’s how the filter
attribute simplifies finding and selecting options in a combobox
:
For discussion and suggestions on the naming of the filter
attribute, please see Issue #932.
search
attributeSection titled Introducing%20search%20attributeThe search
attribute adds smart search features to <combobox>
. It lets users find options in different ways:
Attribute values:
<select>
definition here.<combobox search>
<input type="text" placeholder="Select fruit">
<datalist>
<option>Apple</option>
<option>Apricot</option>
<option>Banana</option>
<!-- ... -->
</datalist>
</combobox>
Join the conversation on the naming and values of the search
attribute in Issue #931.
multiple
attributeSection titled Future%3A%20Introduction%20of%20multiple%20attributeThe multiple
attribute will be specified in detail in a forthcoming update.
Details regarding keyboard interaction for the combobox will follow the W3C ARIA Authoring Practices for combobox patterns. For further development and discussions, please see the filed issue.
combobox
element: Issue #930<combobox>
Section titled Explored%20Anatomy%20Options%20for%20%3Ccombobox%3E<input type="text" list="browsers" />
<datalist id="browsers">
<option>firefox</option>
<option>Chrome</option>
</datalist>
Pros:
Cons:
<datalist>
:<datalist>
approach falls short.<datalist>
, the appearance and behavior can be inconsistent across different browsers.<select combobox>
<input type=text>
<datalist>
<option>One</option>
<option>Two</option>
</datalist>
</select>
Pros:
<select>
Cons:
combobox
) to modify the behavior of <select>
.