Choice and comboboxes
A search field for one known choice, or native checkboxes when several independent choices are needed.
Try a combobox
View markup
<div class="ex-combobox" data-combobox>
<label class="ex-label" for="spec-topic">Find a topic</label>
<div class="ex-combobox-control"><input type="text" class="ex-input" id="spec-topic"
autocomplete="off" placeholder="Try nature" data-combobox-input>
<button type="button" class="ex-combobox-toggle" aria-label="Show topic choices" data-combobox-toggle>
<span class="ex-icon ex-icon--chevron-down" aria-hidden="true"></span></button></div>
<div class="ex-combobox-panel" data-combobox-panel hidden>
<ul class="ex-combobox-list" id="spec-options" aria-label="Topics" data-combobox-list></ul></div>
<p class="spec-status" data-combobox-status></p>
<button type="button" class="ex-button ex-button--secondary" data-combobox-retry hidden>Try again</button>
<input type="hidden" data-combobox-value>
</div>Usage and implementation
Full example
Use and alternatives
Prefer a native select for a short fixed list. Use the optional combobox when filtering materially helps. For several independent choices, the input composition uses searched native checkboxes; it does not pretend to be a single-select listbox.
Anatomy
Keep the visible label, input, expanded state, controlled listbox, active option and help/error relationship connected. Stable option IDs belong to one instance. Each multiple-choice group has a legend, selected count and visible selected values even when its search hides a selected item.
States and recovery
Provide empty query, results, no matches, loading and recoverable failure. Committed value and current typed query are separate; typing alone does not silently commit. A changed query supersedes older responses. Clear and reset have explicit scope.
Semantics and focus
Keep DOM focus on the combobox input and expose the active option through aria-activedescendant. Use the documented arrow/Enter/Escape model and native text editing. Check pointer selection as well as keyboard. Checkbox Space toggles one value; search does not discard hidden selections.
Responsive and preferences
Options and labels wrap without covering the input. Keep the shared select chevron inset; use logical placement for RTL. Check long options, enlarged text, short viewports, forced colours and actual touch/assistive technology.
API and ownership
createCombobox(root, { options, loadOptions, onCommit, locale }) owns the bounded choice interaction. The adopter owns option identity, data loading permissions, committed-value persistence and disposal. Native multiple-choice models filterTopics, toggleTopic and validateTopics are example-domain helpers, not a remote multi-select protocol.
Security and data
Render labels as text. If options come from a private service, authorize suggestions and results before returning them; do not leak names or counts. The fixture contains fictional choices and no remote provider. Request cancellation alone does not reverse a server operation.
Acceptance
Test pointer and keyboard commit, Escape, clear, no-results recovery, composition input, a stale response after a newer query and two isolated instances. Verify hidden selected checkboxes remain counted and recoverable. Browser/AT and product data-boundary acceptance are still required.
