ComboBox is the combination of a Textfield and an associated Dropdown that allows the user to filter a list when selecting an option. ComboBox allows users to type the full option, type part of the option and narrow the results, or select an option from the list.

Props

Name
Type
Default
accessibilityClearButtonLabel
Required
string
-

Label to describe the clear button's purpose.

id
Required
string
-

Unique id to identify each ComboBox. Used for accessibility purposes.

label
Required
string
-

Provide a label to identify the ComboBox field.

noResultText
Required
string
-

The text shown when the input value returns no matches

options
Required
Array<{| label: string, value: string, subtext: string |}>
-

The data for each selection option. See subtext variant to learn more

disabled
boolean
false

When disabled, ComboBox looks inactive and cannot be interacted with. If tags are passed, they will appear disabled as well and cannot be removed. See tags variant to learn more.

errorMessage
string
-

Provide feedback when an error on selection occurs. See error message variant.

helperText
string
-

Provides additional information about how to select a ComboBox option.

inputValue
string
-

The user input in ComboBox for controlled components. See controlled ComboBox variant to learn more.

labelDisplay
"visible"|"hidden"
"visible"

Whether the label should be visible or not. If hidden, the label is still available for screen reader users, but does not appear visually. See the label visibility variant for more info.

onBlur
({ event: SyntheticFocusEvent<HTMLInputElement> | SyntheticEvent<HTMLInputElement> , value: string }) => void
-

Callback when you focus outside the component

onChange
({ event: SyntheticInputEvent<>, value: string }) => void
-

Callback when user types into the control input field

onClear
() => void
-

Callback when user clicks on clear button

onFocus
({ event: SyntheticFocusEvent<>, value: string }) => void
-

Callback when you focus on the component

onKeyDown
({ event: SyntheticKeyboardEvent<HTMLTextAreaElement>, value: string }) => void
-

Callback for key stroke events. See tags variant to learn more.

onSelect
({ event: SyntheticInputEvent<>, value: string }) => void
-

Callback when an item is selected

placeholder
string
-

Specify a short description that suggests the expected input for the field

ref
React.Ref<"input">
-

Forward the ref to the underlying component container element. See focus management variant to learn more

selectedOption
{| label: string, value: string, subtext: string |}
-

The selected option in ComboBox for controlled components. See controlled ComboBox variant to learn more.

size
"md" | "lg"
"md"

Defines the height of ComboBox: md: 40px, lg: 48px. Width is defined by parent component.

tags
Array<Element<typeof Tag>>
-

List of tags to display in the component. See tags variant to learn more.

Usage guidelines

When to Use
  • Presenting users with a long list of options (typically 10 or more) that can be filtered by typing in the text field.
When Not to Use
  • For shorter lists of items where filtering is not needed, typically under 10 items.

Best practices

Do

Use ComboBox to allow the user to edit or copy the textfield input values to select and/or narrow down from a given list of options.

Don't

Use ComboBox for a simple list of items. Use SelectList instead for the added native mobile functionality.

Accessibility

Labels

ComboBox requires both label and accessibilityClearButtonLabel. By default, the label is visible above TextField. However, if the form items are labelled by content elsewhere on the page, or a more complex label is needed, the labelDisplay prop can be used to visually hide the label. In this case, it is still available to screen reader users, but will not appear visually on the screen.

In the example below, the "Discover this week's top searched trends across all categories" text is acting as a heading, so instead of repeating another label, we visually hide the label. When a user focuses on the ComboBox, a screen reader will announce "Choose a category to display top search trends, Select category".

Discover this week's top searched trends across all categories

Wanna learn how trends work? Read additional information

Keyboard interaction

  • Hitting Enter or Space key on the ComboBox's trigger opens the options list
  • Once an item is selected, hitting Enter or Space on the clear button clears the selection and returns focus to the input textfield
  • Escape key closes the options list, while moving focus back on the ComboBox's trigger
  • Arrow keys are used to navigate items within the options list
  • Enter key selects an item within the options list
  • Tab or Shift + Tab close the options list and move focus accordingly

Localization

Be sure to localize the helperText, errorMessage, noResultText, label, placeholder, and accessibilityClearButtonLabel props. options and value should be localized for those cases that can be translated. Note that localization can lengthen text by 20 to 30 percent.

Variants

Controlled vs Uncontrolled

ComboBox can be used as a controlled or an uncontrolled component. An uncontrolled ComboBox stores its own state internally and updates it based on the user input. On the other side, a controlled ComboBox's state is managed by a parent component. The parent component's state passes new values through props to the controlled component which notifies changes through event callbacks.

Uncontrolled ComboBox

An uncontrolled ComboBox should be used for basic cases where no default value or tags are required. Don't pass inputValue or selectedOptions props to keep the component uncontrolled. By passing inputValue to ComboBox, the component fully manages its internal state: any value different from null and undefined makes Combobox controlled.

Controlled ComboBox

A controlled ComboBox is required if a selected value is set, as shown in the first example. In the second example, values are set programatically. Controlled Comboboxes with tags are also controlled components. A controlled ComboBox requires three value props: options, inputValue, and selectedOptions. ComboBox is notified of changes via the onChange, onSelect, onBlur, onFocus, onKeyDown, and onClear props. All values displayed by ComboBox at any time are controlled externally. To clear inputValue, set the value to an empty string inputValue = "", null or undefined values turn ComboBox into an uncontrolled component.

Estimated tax to be collected in CA - California will be calculated at checkout

Tags

Include Tag elements in the input using the tags prop.

Note that the ComboBox component doesn't internally manage tags; therefore, it must be a controlled component. A controlled ComboBox requires three value props: options, inputValue, and tags.

To use ComboBox with tags, it's recommended to create new tags on enter key presses, to remove them on backspaces when the cursor is in the beginning of the field and to filter out empty tags. These best practices are shown in the following example.

Ref

To control focus or position and anchor components to ComboBox, use ref as shown in the examples below.

Focus management

With subtext

Display subtext under each selection option

Error message

SelectList
If users need to select from a short, simple list (without needing sections, subtext details, or the ability to filter the list), use SelectList.

Dropdown
Dropdown is an element constructed using Popover as its container. Use Dropdown to display a list of actions or options in a Popover.

Fieldset
Use Fieldset to group related form items.