Select

Ready

The select component allows users to make single or multiple selections from a pre-defined list of options.

Props

NameDefaultDescription
defaultValue: string | string[]Initial value of the select, only when it is uncontrolled.
value: string | string[]Value of the select. If undefined, the component will be uncontrolled and the value will be managed internally by the component.
label: stringText to be placed above the select.
name: stringName attribute of the input element. This attribute will allow users to find the component's value during the submit event. In this event, the component's value will always be a regular string, for both single and multiple selection modes, been in the first one a single option value and in the multiple variant more than one option value, separated by commas.
options: Option[] | OptionGroup[]An array of objects representing the selectable options. Each object has the following properties depending on whether it is a regular option or a group:
Option:
  • Label: string: Label of the option to be shown in the select's listbox.
  • Value: string: Value of the option. It should be unique and not an empty string, which is reserved to the empty option added by optional prop.
  • Icon: string | SVGSVGElement: Element used as the icon that will be placed before the option label. It can be a url of an image or an inline SVG. If the url option is the chosen one, take into account that the component's color styling tokens will not be applied to the image.
OptionGroup:
  • Label: string: Label of the group to be shown in the select's listbox.
  • Options: Option[]: List of the grouped options.
helperText: stringHelper text to be placed above the select.
placeholder: stringText to be put as placeholder of the select.
searchable: booleanfalseIf true, enables search functionality.
multiple: booleanfalseIf true, the select component will support multiple selected options. In that case, value will be an array of strings with each selected option value.
disabled: booleanfalseIf true, the component will be disabled.
optional: booleanfalseIf true, the select will be optional, showing '(Optional)' next to the label and adding a default first option with an empty string as value and the placeholder (if defined) as its label. Otherwise, the field will be considered required and an error will be passed as a parameter to the OnBlur and onChange functions if an option wasn't selected.
onChange: functionThis function will be called when the user selects an option. An object including the new value (or values) and the error (if the value selected is not valid) will be passed to this function. An example of this object is:{ value: value, error: error }. If there is no error, error will not be defined.
onBlur: functionThis function will be called when the select loses the focus. An object including the value (or values) and the error (if the value selected is not valid) will be passed to this function. An example of this object is: { value: value, error: error }. If there is no error, error will not be defined.
error: stringIf it is a defined value and also a truthy string, the component will change its appearance, showing the error below the select component. If the defined value is an empty string, it will reserve a space below the component for a future error, but it would not change its look. In case of being undefined or null, both the appearance and the space for the error message would not be modified.
margin: string | objectSize of the margin to be applied to the component ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge'). You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different margin sizes.
size: string'medium'Size of the component ('small' | 'medium' | 'large' | 'fillParent').
tabIndex: number0Value of the tabindex attribute.
ref: objectReference to the component.

Examples

Controlled

Uncontrolled

Error handling

Grouped options

Icons