Select

Selects allow you to choose items from a menu of predefined options.

Selects allow you to choose items from a menu of predefined options.

Option 1 Option 2 Option 3

Use the label attribute to give the select an accessible label. For labels that contain HTML, use the label slot instead.

Option 1 Option 2 Option 3

Add descriptive help text to a select with the help-text attribute. For help texts that contain HTML, use the help-text slot instead.

Option 1 Option 2 Option 3

Use the placeholder attribute to add a placeholder.

Option 1 Option 2 Option 3

Use the required attribute to specify the input is a required field when using within a form.

Option 1 Option 2 Option 3

Use the disabled attribute to disable a select.

Option 1 Option 2 Option 3

Use the error-text attribute to customize the error message shown. Read more about error validation here .

Option 1 Option 2 Option 3

Use the clearable attribute to make the control clearable. The clear button only appears when an option is selected.

Option 1 Option 2 Option 3

To allow multiple options to be selected, use the multiple attribute. It’s a good practice to use clearable when this option is enabled. To set multiple values at once, set value to a space-delimited list of values.

Option 1 Option 2 Option 3 Option 4 Option 5 Option 6

Use <sl-divider> to group listbox items visually. You can also use <small> to provide labels, but they won’t be announced by most assistive devices.

Section 1 Option 1 Option 2 Option 3 Section 2 Option 4 Option 5 Option 6

The preferred placement of the select’s listbox can be set with the placement attribute. Note that the actual position may vary to ensure the panel remains in the viewport. Valid placements are top and bottom.

Option 1 Option 2 Option 3

You can listen for the ods-input event to determine when a value is select. To see other input events check out the events below . You can also see how selects are used in forms by checking out the form section .

Option 1 Option 2 Option 3
import '@ods/components/web.select';

Note: You only need to import a web component once in your code, as it registers itself globally when defined, allowing you to use it anywhere within your application without needing to re-import it each time you want to use the component.

Slots

NameDescription
(default)The listbox options. Must be `<ods-option>` elements. You can use `<ods-divider>` to group items visually.
labelThe input's label. Alternatively, you can use the `label` attribute.
prefixUsed to prepend a presentational icon or similar element to the combobox.
clear-iconAn icon to use in lieu of the default clear icon.
expand-iconThe icon to show when the control is expanded and collapsed. Rotates on open and close.
help-textText that describes how to use the input. Alternatively, you can use the `help-text` attribute.

Properties

Please note, both DOM properties and HTML attributes are shown in the table below. Unless otherwise specified, the property and attribute names are identical.

Property/AttributeReflectsTypeDefault
name
string''
value
string | string[]''
defaultValue
string | string[]''
placeholder
string''
multiple
booleanfalse
maxOptionsVisible
max-options-visible
number3
disabled
booleanfalse
clearable
booleanfalse
open
booleanfalse
hoist
booleanfalse
filled
booleanfalse
pill
booleanfalse
label
string''
placement
'top' | 'bottom''bottom'
helpText
help-text
string''
errorText
error-text
string''
form
string''
required
booleanfalse
getTag
(option: OdsOption, index: number) => TemplateResult | string | HTMLElement
validity
validationMessage

Events

React EventDescriptionEvent Detail
ods-changeEmitted when the control's value changes.--
ods-clearEmitted when the control's value is cleared.--
ods-inputEmitted when the control receives input.--
ods-focusEmitted when the control gains focus.--
ods-blurEmitted when the control loses focus.--
ods-showEmitted when the select's menu opens.--
ods-after-showEmitted after the select's menu opens and all animations are complete.--
ods-hideEmitted when the select's menu closes.--
ods-after-hideEmitted after the select's menu closes and all animations are complete.--
ods-invalidEmitted when the form control has been checked for validity and its constraints aren't satisfied.--

Methods

NameDescriptionArguments
show()Shows the listbox.--
hide()Hides the listbox.--
checkValidity()Checks for validity but does not show a validation message. Returns `true` when valid and `false` when invalid.--
getForm()Gets the associated form, if one exists.--
reportValidity()Checks for validity and shows the browser's validation message if the control is invalid.--
setCustomValidity()Sets a custom validation message. Pass an empty string to restore validity.--
focus()Sets focus on the control.--
blur()Removes focus from the control.--

Parts

NameDescription
form-controlThe form control that wraps the label, input, and help text.
form-control-labelThe label's wrapper.
form-control-inputThe select's wrapper.
form-control-help-textThe help text's wrapper.
form-control-error-textThe error text's wrapper.
comboboxThe container the wraps the prefix, combobox, clear icon, and expand button.
prefixThe container that wraps the prefix slot.
display-inputThe element that displays the selected option's label, an `<input>` element.
listboxThe listbox container where options are slotted.
tagsThe container that houses option tags when `multiselect` is used.
tagThe individual tags that represent each multiselect option.
tag__baseThe tag's base part.
tag__contentThe tag's content part.
tag__remove-buttonThe tag's remove button.
tag__remove-button__baseThe tag's remove button base part.
clear-buttonThe clear button.
expand-iconThe container that wraps the expand icon.

Dependencies

This component automatically imports the following dependencies.

  • ods-icon
  • ods-icon-button
  • ods-popup
  • ods-tag

Search