Combobox

lightning:combobox

A widget that provides an input field that is readonly, accompanied with a dropdown list of selectable options.

For Aura components only. For LWC development, use lightning-combobox.

For Use In

Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline

lightning:combobox is an input element that enables single selection from a list of options. The result of the selection is stored as the value of the input. Multiple selection is currently not supported. To support multiple selection, use lightning:dualListbox instead.

This component implements styling from combobox in the Lightning Design System.

This example creates a list of options during init, with a default selection that's specified with the value attribute. The options attribute specifies the name of an array of items for the dropdown list.

In your client-side controller, define an array of options and assign it to the statusOptions attribute. Each option corresponds to a list item on the dropdown list. Define the content of each option by specifying a value property and a label property. The label value is displayed for the item in the rendered dropdown list, while the value property's value is stored when the item is selected.

Define an optional description property to add a line of descriptive text for each option. The descriptive text displays below the label of the list item. When adding descriptions, specify a description for each item in a list. If some items are missing descriptions, the text of the items can be misaligned.

Selecting an option triggers the onchange event, which calls the handleChange client-side controller. To check which option has been clicked, use event.getParam("value"). Calling cmp.find("mycombobox").get("v.value"); returns the currently selected option.

Client-side input validation is available for this component. You can require the user to make a selection by setting required="true". An error message is automatically displayed when an item is not selected and required="true".

To check the validity states of an input, use the validity attribute, which is based on the ValidityState object. You can access the validity states in your client-side controller. This validity attribute returns an object with boolean properties.

You can override the default message by providing your own value for messageWhenValueMissing.

To programmatically display error messages on invalid fields, use the reportValidity() method. For custom validity error messages, display the message using setCustomValidity() and reportValidity(). For more information, see the lightning:input documentation.

Special characters like " must be escaped. For example, you want to display "New".

When using single quotes in your value, escape the quote with a double slash instead of a single slash.

lightning:combobox doesn't currently support autocomplete or typeahead. The autocomplete attribute is reserved for internal use.

In Lightning Experience, a lightning:combobox dropdown list that's opened overlays the record edit page or modal, the global header, and record form footer when scrolling.

On mobile devices, lightning:combobox has the following limitations.

  • The dropdown menu doesn't scroll correctly when there isn't enough room to display the complete list of options.
  • The mobile viewport doesn't display the dropdown menu correctly especially if the component is placed near the bottom of the page.

We recommend using the lightning:select component on mobile instead.

You must provide a text label for accessibility to make the information available to assistive technology. The label attribute creates an HTML label element for your input component. To hide a label from view and make it available to assistive technology, use the label-hidden variant.

This component uses button elements for select-only comboboxes to comply with the Lightning Design System combobox blueprint.

When an option label is too long to fit in a single line, the label wraps and continues in a new line. If a long word in an option label isn't fully visible, scroll horizontally on the dropdown list to reveal the whole word.