Comboboxes allows the user to select one item out of a set of predefined options while also allowing text entry - it combines a dropdown with a search. Text entry is used to filter the list of options. It utilises the autocomplete mechanism.
Use when
The user has to select from a large predefined set, where search is needed to find the right option.
The user has to select from a predefined set, but more options can also be added manually.
The possible alternatives should be displayed to guide users towards the right one.
Screen real estate is limited.
It is not vital to see all the options at first sight.
The functionality for this component, i.e. the script, is not provided. The documentation has a demo functionality that you can draw inspiration from in your work.
Design
Single selection
See the filtering data mechanism when the data set is visible before filtering, or autocomplete for common search behaviour.
As soon as the user has started typing in the text field, an "x" icon is shown to remove the typed text and revert suggestions to those shown for an empty search string.
When the combobox is closed, it shows the selected option (if any).
You need to be able to navigate in the dropdown box with the keyboard (in the example is used: 'Arrow Down', 'Arrow Up', 'Page Up', 'Page Down', 'End', 'Home', 'Esc', and for select 'Enter').
<divclass="row"><divclass="col-sm-6"><divclass="form-group"><labelfor="comboboxInputaA">Single selection</label><divclass="combobox-wrapper"><divrole="combobox"id="comboboxA"class="combobox"aria-expanded="false"aria-owns="comboboxListA"aria-haspopup="listbox"aria-multiselectable="false"><divclass="combobox-input"><spanclass="combobox-suggestion"option-selected=""></span><inputtype="text"id="comboboxInputaA"placeholder="Enter selection"value=""spellcheck="false"aria-controls="comboboxListA"aria-autocomplete="list"aria-activedescendant=""></div></div><spanclass="spinner spinner-xs"></span><buttontype="button"id="comboboxClearButtonA"class="clear-btn"aria-label="Delete selection in input"><spanclass="close"></span></button><buttontype="button"id="comboboxButtonA"class="combobox-btn"aria-label="Open country list"><spanclass="vismaicon vismaicon-autocomplete"></span></button><divclass="combobox-dropdown"><ulrole="listbox"id="comboboxListA"class="combobox-list"aria-labelledby="comboboxLabelA"aria-multiselectable="false"></ul></div></div></div></div></div>
Multiple selection
For the multiple selection the selected option is shown as a pill in the textbox, and after a selection, the combobox remains open.
<divclass="combobox-wrapper"style="max-width: 320px;"><labelfor="comboboxInputaE"id="comboboxLabelE"class="combobox-label hidden"aria-label="Select one from the list">Multiple selection</label><divrole="combobox"id="comboboxE"class="combobox"aria-expanded="false"aria-owns="comboboxListE"aria-haspopup="listbox"aria-multiselectable="false"><divclass="combobox-input"><spanclass="combobox-suggestion"option-selected=""></span><inputtype="text"id="comboboxInputaE"placeholder="Enter selection"value=""spellcheck="false"aria-controls="comboboxListE"aria-autocomplete="list"aria-activedescendant=""autofocus></div></div><spanclass="spinner spinner-xs"></span><buttontype="button"id="comboboxClearButtonE"class="clear-btn"aria-label="Delete selection in input"><spanclass="close"></span></button><buttontype="button"id="comboboxButtonE"class="combobox-btn"data-toggle="listbox"aria-label="Open country list"><spanclass="vismaicon vismaicon-autocomplete"></span></button><divclass="combobox-dropdown"><ulrole="listbox"id="comboboxListE"class="combobox-list"aria-labelledby="comboboxLabelE"aria-multiselectable="true"></ul></div></div>
Combobox with header and footer sections in the dropdown
By adding a wrapper with .combobox-dropdown-header or .combobox-dropdown-footer class inside the .combobox-dropdown will create a header or footer zone, for additional controls.
<divclass="combobox-wrapper"><labelfor="comboboxInputaA2"id="comboboxLabelA2"class="combobox-label hidden"aria-label="Select one from the list">Single selection</label><divrole="combobox"id="comboboxA2"class="combobox"aria-expanded="false"aria-owns="comboboxListA2"aria-haspopup="listbox"aria-multiselectable="false"><divclass="combobox-input"><spanclass="combobox-suggestion"option-selected=""></span><inputtype="text"id="comboboxInputaA2"placeholder="Enter selection"value=""spellcheck="false"aria-controls="comboboxListA2"aria-autocomplete="list"aria-activedescendant=""></div></div><spanclass="spinner spinner-xs"></span><buttontype="button"id="comboboxClearButtonA2"class="clear-btn"aria-label="Delete selection in input"><spanclass="close"></span></button><buttontype="button"id="comboboxButtonA2"class="combobox-btn"aria-label="Open country list"><spanclass="vismaicon vismaicon-autocomplete"></span></button><divclass="combobox-dropdown"><divclass="combobox-dropdown-header"><buttontype="button"class="btn">New</button><hr></div><ulrole="listbox"id="comboboxListA2"class="combobox-list"aria-labelledby="comboboxLabelA2"aria-multiselectable="false"></ul><divclass="combobox-dropdown-footer"><navaria-label="Page navigation"><ulclass="pagination"><li><buttonclass="go2first btn mb-0"disabled=""aria-label="go-to-first">Go to first page</button></li><li><buttonclass="prev btn mb-0"disabled=""aria-label="Previous">Previous page</button></li><li><a>1</a></li><liclass="of"><span>of</span></li><li><a>8</a></li><li><buttonclass="next btn mb-0"aria-label="Next">Next page</button></li><li><buttonclass="go2last btn mb-0"aria-label="go-to-last">Go to lat page</button></li></ul></nav></div></div></div>
Disabled
For a propper disabled state for the combobox follow the code snippet below (it is recommended to add a disabled attribute to the input as well).
<divclass="combobox-wrapper"><labelfor="comboboxInputaC"id="comboboxLabelC"class="combobox-label hidden"aria-label="Select one from the list">Single selection - disabled</label><divrole="combobox"id="comboboxC"class="combobox disabled"aria-expanded="false"aria-owns="comboboxListC"aria-haspopup="listbox"aria-multiselectable="false"><divclass="combobox-input"><spanclass="combobox-suggestion"option-selected=""></span><inputtype="text"id="comboboxInputaC"placeholder="Enter selection"disabledvalue=""spellcheck="false"aria-controls="comboboxListA"aria-autocomplete="list"aria-activedescendant=""></div></div><spanclass="spinner spinner-xs"></span><buttontype="button"id="comboboxClearButtonC"class="clear-btn"aria-label="Delete selection in input"><spanclass="close"></span></button><buttontype="button"id="comboboxButtonC"class="combobox-btn"data-toggle="listbox"tabindex="-1"aria-disabled="true"aria-label="Open country list"><spanclass="vismaicon vismaicon-autocomplete"></span></button></div>
Combobox with error - validation
For error (on validation) on the combobox you need to add .has-error class as in the code snippet below.
<divclass="combobox-wrapper"><labelfor="comboboxInputaD"id="comboboxLabelD"class="combobox-label hidden"aria-label="Select one from the list">Single selection with error</label><divrole="combobox"id="comboboxD"class="combobox has-error"aria-expanded="false"aria-owns="comboboxListD"aria-haspopup="listbox"aria-multiselectable="false"><divclass="combobox-input"><spanclass="combobox-suggestion"option-selected=""></span><inputtype="text"id="comboboxInputaD"placeholder="Enter selection"value=""spellcheck="false"aria-controls="comboboxListA"aria-autocomplete="list"aria-activedescendant=""></div></div><spanclass="spinner spinner-xs"></span><buttontype="button"id="comboboxClearButtonD"class="clear-btn"aria-label="Delete selection in input"><spanclass="close"></span></button><buttontype="button"id="comboboxButtonD"class="combobox-btn"data-toggle="listbox"aria-label="Open country list"><spanclass="vismaicon vismaicon-autocomplete"></span></button><divclass="combobox-dropdown"></div></div>
Combogrid
Combogrid allows the user to select one item out of a set of predefined options. Is similar to combobox, but contains more information in the form of more than one column and are presented as a grid instead of a list. Combogrids also allow text entry to search from a very long list of options or to add items that are not present in the list.
<labelfor="comboboxInputaT"id="comboboxLabelT"class="combobox-label hidden"aria-label="Select one from the list">Filter within table</label><divclass="combobox-wrapper"style="max-width: 320px;"><divrole="combobox"id="combogridT"class="combobox"aria-expanded="false"aria-owns="comboboxTableT"aria-haspopup="listbox"aria-multiselectable="false"><divclass="combobox-input"><spanclass="combobox-suggestion"option-selected=""></span><inputtype="text"id="comboboxInputaT"placeholder="Enter selection"value=""spellcheck="false"aria-controls="comboboxTableT"aria-autocomplete="list"aria-activedescendant=""autofocus></div></div><spanclass="spinner spinner-xs"></span><buttontype="button"id="comboboxClearButtonT"class="clear-btn"aria-label="Delete selection in input"><spanclass="close"></span></button><buttontype="button"id="comboboxButtonT"class="combobox-btn"data-toggle="listbox"aria-label="Open country list"><spanclass="vismaicon vismaicon-autocomplete"></span></button><divclass="combobox-dropdown"><divclass="combobox-dropdown-header"><buttontype="button"class="btn">New</button></div><divclass="combobox-table"><tablerole="table"id="comboboxTableT"class="table table-active"><thead><tr><th>ID</th><th>Name</th><th>Address</th><th>City</th><th>Country</th></tr></thead><tbody></tbody></table></div></div></div>