Skip to content

CdsSelect

A select opens a dropdown list and lets you pick one or several values from a known set: a country, a status, a category. The field is built on CdsTextInput, so the label, the description, the messages, validation and the states work exactly as in a text field.

Storybook GitLab Figma
Test coverage: 64% — partial coverage
API in specs
127 / 127 props, events, slots and exposed members with a test
Test cases
80 unit · 10 browser · 1 planned
Known bugs
11 pinned by an it.fails test
Code coverage
64.1% lines · 61.4% branches measured in v4.0.0-alpha.13
A11y (axe)
5 recommendations in 18 stories measured in v4.0.0-alpha.11

For two or three options take CdsRadioGroup — the options are visible right away. If the list is long and the user searches by typing, use CdsAutocomplete, and if values outside the list are allowed — CdsCombobox.

Anatomy ​

The first diagram shows the frame of the component: the label, the description, the field and the messages block. The second one shows how the field itself is built: the zone of the selected values, the clear button and the menu indicator; the inner and outer icon zones are the same as in CdsTextInput.

Variations ​

List items ​

The list is set by the items prop — an array of strings or of objects with the same interface as in CdsList. While no value is selected, the field shows the placeholder.

Your own data fields ​

When the objects come from the server as they are, use item-title and item-value to say which fields the title and the value are taken from. return-object puts the whole object into v-model instead of just the value.

Grouping ​

Split a long list into meaningful blocks: an item with type: 'subheader' adds a subheader, one with type: 'divider' — a divider. Such items cannot be selected.

Multiple selection ​

The multiple prop allows selecting several values: the items get checkboxes and the field lists the selection separated by commas. ellipsis keeps the listing on a single line and cuts the rest off with an ellipsis.

Selecting all the values ​

The is-select-all prop adds a "select all" entry as the first item of the list (works together with multiple). The true value uses the default caption, a string sets your own.

Chips ​

The chips prop shows the selected values as CdsTag tags, closable-chips adds a cross to them — a value is removed right in the field, without opening the menu.

Native list ​

The native-select prop replaces the custom menu with a native <select>: on mobile devices the system list is more familiar. Filtering, virtual scrolling and the menu slots do not work in this mode.

Tuning the list ​

The list-props prop passes any props through to the inner CdsList — in the example bgColor paints the background of the menu, and slim removes the inner paddings of the menu so that the list fills it entirely. item-color sets the color of the selected items (color is taken by default). In the same way menu-props configures the inner CdsMenu, and menu-height limits the height of the menu.

Slots ​

The select gives up every part of the menu and the field for replacement. The slots of the field itself are the same as in CdsTextInput.

Slot nameDescription
itemThe whole list item; receives item, index and props
selectionThe selected value in the field
chipThe chip of a selected value (with chips)
prepend-item / append-itemContent before and after the list
no-dataMenu content when the list is empty
subheader / dividerGroup subheader and divider
menu-header / menu-footerMenu header and footer; receive search and filteredItems

The item slot overrides the rendering of an item completely. Be sure to pass props into CdsListItem — the selection handler lives in them. In the example every country shows its flag and capital.

The selection slot is your own display of what is selected in the field: the first two countries are shown as tags, the rest are folded into a counter.

The prepend-item and append-item slots add your own entries to the start and the end of the list. In the example the start holds "Select all countries" with a checkbox, and the end — "Load more" with a simulated fetch through loading.

The menu-header and menu-footer slots add content to the header and the footer of the menu — a search field and a confirmation button, for example. Both slots receive search (written into v-model:search, it filters the list) and filteredItems.

Guidelines ​

Scenarios ​

Submitting a form ​

The select takes part in CdsForm validation on a par with text fields: rules will not let the form through without a chosen subject. Give optional fields a default value — that way the form is filled in faster.

Dependent lists ​

The list of cities depends on the chosen country: while there is no country the second select is turned off through disabled, and while the options are loading it shows loading. When the country changes the chosen city is reset — otherwise a non-existent pair would stay in the form.

Picking assignees ​

The combination of multiple, chips and closable-chips shows the chosen people as tags and removes them by the cross right in the field. The item slot adds an avatar and a role — that way it is easier to find the right person in a long list.

Sorting the results ​

A compact select controls the order of a list: hide-messages removes the bottom block, aria-label replaces the hidden label for screen readers. The choice is applied at once — an "Apply" button is not needed.

API ​

Props

NameTypeDefaultDescription
activeboolean | undefined—Active state of the field
activeColorstring | undefined—Color of the component in its active state
appendIconIconValue | undefined—Icon in the append slot, after the content
appendInnerIconIconValue | undefined—Icon in the inner append slot, after the content of the field
autocompletestring | undefined—Helps to influence browser suggestions. The suppress value changes the name attribute of the fields, and off relies on the browser to stop suggesting values on its own. Any other value is passed to the built-in autocomplete of the corresponding element.
autofocusboolean | undefined—Enables autofocus
baseColorstring | undefined—Color of the component in its inactive state
bgColorstring | undefined—Background color of the component
centerAffixboolean | undefined—Vertically center the appendInner, prependInner, clearIcon and label elements.
chipsboolean | undefined—Shows the selected values as removable chips (CdsTag).
clearableboolean | undefined—Shows the clear button
clearIconIconValue | undefined'remove'Icon of the clear button
closableChipsboolean | undefined—Adds a remove button to the chips (relevant together with chips).
closeTextstring | undefined'$cds.close'Text for screen readers describing the close action of the menu.
colorstring | undefined—Component color
counterstring | number | boolean | undefined—Character counter. Accepts a boolean, a number or a string
counterValuenumber | ((value: any) => number) | undefined—Custom counter value. Either a number or a function computing it from the current value
customFilterFilterFunction | undefined—Your own value filtering function. Receives the value, the search query and the item, returns a match or -1
customKeyFilterFilterKeyFunctions | undefined—Separate filtering functions for specific item keys — an object of the form { key: function }
descriptionstring | undefined—Description of the component, shown under the label
disabledboolean | null | undefinednullDisabled state
eagerboolean | undefined—Renders the menu content upfront, without waiting for the first opening.
ellipsisboolean | undefined—In multiple mode keeps the selected values on a single line with an ellipsis
errorboolean | undefined—Error state
errorMessagesstring | readonly string[] | null | undefined[]Puts the component into the error state and passes custom error messages. They are merged with any checks defined in the rules prop. This field does not trigger validation.
filterKeysFilterKeys | undefined—Item keys the search runs over. By default filtering goes by the item title
filterModeFilterMode | undefined'intersection'How the results of customKeyFilter and of the general filtering are combined: by intersection, by union or by replacement
focusedboolean | undefined—Controls the focus state of the component. When true, the component is considered focused and may apply the corresponding styles or behavior.
hideDetailsboolean | "auto" | undefined—Hides the details block (messages and hints). With the 'auto' value the block is hidden when there are no messages
hideMessagesboolean | undefined—Hide the messages under the input
hideNoDataboolean | undefined—Hides the menu and the "no data" placeholder when the item list is empty.
hideSelectedboolean | undefined—Hides the already selected items from the menu list.
hintstring | undefined—Hint text shown under the input
iconColorstring | boolean | undefined—Icon color. Accepts a boolean or a color string
idstring | undefined—Unique identifier of the component
isSelectAllstring | boolean | undefinedfalseAdds a "select all" entry as the first item of the list (for multiple only). true uses the default $cds.selectAll caption, a string sets your own caption.
itemChildrenSelectItemKeyfalseObject field that holds the child items, or a function that returns them
itemColorstring | undefined—Color of the selected items in the menu list. color is used by default.
itemPropsSelectItemKey'props'Object field that holds the props of the item, or a function that returns them
itemsany[] | undefined[]Array of items to display
itemTitleSelectItemKey'title'Object field used as the item title, or a function that returns it
itemTypeSelectItemKey'type'Object field that defines the item type (item, divider, subheader), or a function that returns it
itemValueSelectItemKey'value'Object field used as the item value, or a function that returns it
labelstring | undefined—Label text of the component
listPropsCdsListProps | undefined—Props passed through to the inner CdsList component.
loadingstring | boolean | undefined—Loading indicator for the component
maxErrorsstring | number | undefined1Maximum number of validation errors shown
maxWidthstring | number | undefined—Maximum component width
menuboolean | undefined—Controls the open state of the dropdown menu (v-model:menu).
menuHeightstring | number | undefined178Maximum height of the dropdown menu.
menuIconIconValue | undefined'chevron-down'Icon indicating that the menu can be expanded.
menuPropsCdsMenuProps | undefined—Props passed through to the inner CdsMenu component.
messagesstring | readonly string[] | undefined[]Messages shown under the input
minWidthstring | number | undefined—Minimum component width
modelModifiersRecord<string, boolean> | undefined—v-model modifiers passed by Vue to process the field value
modelValueanynullValue of the component in v-model. If the component supports the multiple prop, an empty array is used by default.
multipleboolean | undefined—Allows selecting several values. The selected items are shown as chips or as a list.
namestring | undefined—Name of the input
nativeSelectboolean | undefined—Renders a native HTML select instead of the custom dropdown menu (CdsMenu)
noAutoScrollboolean | undefined—Turns off the automatic scrolling of the menu to the selected item on opening.
noDataTextstring | undefined'$cds.noDataText'Text shown in the menu when the item list is empty.
noFilterboolean | undefined—Turns off the built-in filtering — the list is shown as is, the search is handled outside
openOnClearboolean | undefined—Opens the menu after the value is cleared.
openTextstring | undefined'$cds.open'Text for screen readers describing the open action of the menu.
persistentClearableboolean | undefined—Always show the clear button, not only on hover or focus
persistentCounterboolean | undefined—Always show the counter, not only while the field is in use
persistentHintboolean | undefined—Always show the hint, not only on focus
persistentPlaceholderboolean | undefined—Always show the placeholder instead of hiding it while the field is in use
placeholderstring | undefined—Placeholder text shown in an empty field
prefixstring | undefined—Text prefix shown before the field value
prependIconIconValue | undefined—Icon in the prepend slot, before the content
prependInnerIconIconValue | undefined—Icon in the inner prepend slot, before the content of the field
readonlyboolean | null | undefinednullRead-only state
returnObjectboolean | undefined—Return an object in the model value instead of an array
reverseboolean | undefined—Reverses the order of the elements inside the field
rolestring | undefined'combobox'ARIA role for the native input element
rulesreadonly ValidationRule[] | undefined[]Accepts an array of items of different types: functions, booleans and strings. Functions take the input value as an argument and must return either true / false, or a string with an error message. The input goes into the error state if a function returns false (or any value in the array is false) or is a string.
searchstring | undefined—Current value of the search query used to filter the items (v-model:search).
sizenumber | "xs" | "sm" | "md" | "lg" | "xl" | undefined'md'Size of the component
suffixstring | undefined—Text suffix shown after the field value
textColorstring | undefined—Text color of the component
themestring | undefined—Component theme
transitionstring | boolean | (TransitionProps & { component?: Component | undefined; }) | { component: Component; } | null | undefined{ component: CdsModalTransition }Transition animation
typestring | undefined'text'Type of the native input
validateOnValidateOn | undefined—Changes the type of the event that triggers validation
valueComparatorValueComparator | undefined—Function that compares item values to determine the selected state
widthstring | number | undefined—Component width

Events

NameTypeDescription
update:focused[focused: boolean]The focus state of the component changed (v-model:focused).
update:menu[ue: boolean]The open state of the dropdown menu changed (v-model:menu).
update:modelValue[value: any]The selected value changed (v-model).
update:search[value: string]The search query changed (v-model:search).
update:selectedAll[value: boolean]The "all selected" state changed (for multiple + isSelectAll only).

Slots

NameTypeDescription
appendCdsInputSlotAdds an element after the input
append-innerCdsInputDefaultSlotSlot added at the end of the input
append-itemanyContent after the item list in the menu.
chip{ item: any; internalItem: ListItem<any>; index: number; props: Record<string, unknown>; }Custom rendering of the chip of a selected value (relevant together with chips).
clearCdsInputDefaultSlot & { props: Record<string, any>; }Slot for a custom clear icon (shown when the clearable prop is true).
description{ description: string | undefined; props: Record<string, any>; }Default slot of the CdsDescription component
detailsCdsInputSlotSlot for custom content that lets you customize how the messages are displayed
divider{ props: Record<string, unknown>; index: number; }Custom rendering of a divider in the menu list.
item{ item: any; internalItem: ListItem<any>; index: number; props: Record<string, unknown>; }Custom rendering of an item of the menu list.
label{ label: string | undefined; props: Record<string, any>; }Default slot of the CdsLabel component
loaderLoaderSlotPropsSlot for a custom loader (shown when the loading prop is true).
menu-footer{ search: Ref<string | undefined, string | undefined>; filteredItems: ListItem<any>[]; }Content of the menu footer. Receives the current search query and the filtered items.
menu-header{ search: Ref<string | undefined, string | undefined>; filteredItems: ListItem<any>[]; }Content of the menu header. Receives the current search query and the filtered items.
messageCdsMessageSlotSlot for customizing the content of a message
messagesCdsInputSlotSlot for custom content that lets you customize how the messages are displayed
no-dataanyContent shown in the menu when the item list is empty.
prependCdsInputSlotAdds an element before the input
prepend-innerCdsInputDefaultSlotSlot added at the start of the input
prepend-itemanyContent before the item list in the menu.
selection{ item: any; internalItem: ListItem<any>; index: number; }Custom rendering of the selected value inside the field.
subheader{ props: Record<string, unknown>; index: number; }Custom rendering of a group subheader in the menu list.

Exposed

NameTypeDescription
controlRefHTMLElement | undefinedRef to the control of the input
fieldIconColorstring | undefinedIcon color
filteredItemsListItem<any>[]Items filtered by the current search query.
isDirtybooleanWhether the input is dirty
isDisabledbooleanWhether the input is disabled
isFocusedbooleanWhether the component is focused.
isPurebooleanWhether the input is pure
isReadonlybooleanWhether the input is read-only
isValidboolean | nullWhether the input is valid
isValidatingbooleanWhether the input is being validated
reset() => Promise<void>Resets the input to its initial state
resetValidation() => Promise<void>Resets the validation of the input
selectAll() => voidToggle the selection of all available items (for multiple + isSelectAll only).
validate(silent?: boolean) => Promise<string[]>Validates the input