Combo Box

A combo box helps users select an item from a large list of options.

Current accessibility issues

In late 2022, we found some combo box usability issues when we were testing with people who use screen readers and alternative input devices. For more information, see the issue on GitHub.

Maturity level - ready for production

View the React component implementation details and all variants in Storybook.


Component examples

Default


Guidance

When to use the combo box component

  • More than 15 options. Use a combo box when there are more than 15 choices in a drop-down list. With so many options, users may find it difficult to navigate with scrolling only.

  • Limited space. Use a combo box for presenting options when screen real estate is limited.

When to consider something else

  • Limited choices. When the number of options is small, you can continue to use a select or radio element.

Usability guidance

  • Use option strings familiar to users. The combo box filters by matching strings. Include option text that includes familiar strings or spellings (for example, if using the combobox with a state list, include the postal abbreviation in the option text: District of Columbia (DC)).

  • Make sure to test. Test select menus thoroughly with members of your target audience. Several usability experts suggest they should be the “UI of last resort.” Many users find them confusing and difficult to use.

  • Avoid dependent options. Avoid making options in one select menu change based on the input to another. Users often don’t understand how choosing an item in one impacts another.

  • Use a good default. When most users will (or should) pick a particular option, make it the default: <option selected="selected">Default</option>

  • Avoid auto-submission. Don’t use JavaScript to automatically submit the form (or do anything else) when an option is selected. Offer a “submit” button at the end of the form instead. Users often change their choices multiple times. Auto-submission is also less accessible.


Accessibility

  • Known assistive technology issues. Testing with people using assistive technology revealed usability concerns that require additional investigation. At this time, consider using a Select component instead of a Combo box. More research and testing is planned to better understand and address these accessibility issues. If you would like to contribute to improving this component, please join our community and share your feedback.

  • Customize form controls accessibly. If you customize this component, ensure that it continues to meet the accessibility requirements that apply to all form controls.

  • Always use a label. Make sure your select element has a label. Don’t replace it with the default menu option (for example, removing the “State” label and just having the menu read “Select a state” by default).

  • Avoid auto-submission. Don’t use JavaScript to automatically submit the form (or do anything else) when an option is selected. Auto-submission disrupts screen readers because they select each option as they read them.

Using the combo box component

  • Properties. The following properties modify component functionality. These properties can be set or adjusted at any time before or after initialization in order to have an effect.
Property Element Description
data-filter .usa-combo-box The combo box will use this regular expression to filter the combo box options. You are declaring a case insensitive match over the entire option text, which means ^ and $ are added automatically. You can specify the inputted query with ``. You can also declare a custom query filter as a data property as well, which can be used in the custom filter `(data-number-filter="[0-9]"` and then using `data-filter=".*")`. The default filter is `.*.*`, which is a simple “find anywhere within the option” text..
  • Initialization properties. The following properties update the component during initialization. These properties must be set before the component is initialized in order to have an effect.
Property Element Description
required select The combo box component will be required in terms of native form validation.
disabled select The combo box component will be disabled / read-only. You can re-enable it by executing the enable procedure on the component.
data-placeholder .usa-combo-box To update the placeholder text of the combo box, use the data-placeholder attribute. We recommend using a label or hint instead of a placeholder.
data-default-value .usa-combo-box The combo box will set this value as the default selection if it is found within the select options.
  • Procedures. The following static procedures update the component after initialization. These are in addition to the primary methods referenced in the JS customization documentation.
Property Element Description
enable .usa-combo-box The combo box component will be enabled.
disable .usa-combo-box The combo box component will be disabled / read-only.

External References

For usage and accessibility guidelines please refer to the USWDS.