Select
Vue Bootstrap 5 Select
Vue Select fields components are used for collecting user provided information from a list of options.
Note: Read the API tab to find all available options and advanced customization
Basic example
Select options are added using v-model with the
options
argument. You can get selected values in two ways. The first is to filter
the data given in v-model:options
by a selected
key. The second
method is to use v-model:selected
which is read-only and stores the currently
selected options as a string (single select) or as an array (multiple select).
Basic select behaves like a native one and by default marks the first available option as
selected. To change this setting, easily set the
preselect
property to false
.
Multiselect
Add multiple
property to the select component to activate multiple mode.
Select with label
It is possible to add select label by setting the
label
property.
Select with placeholder
Use placeholder
property to set placeholder for select input. The placeholder
will be displayed when input is focused and no option is selected.
Disabled select
Add disabled
attribute to the select component to disable select input.
Disabled options
Use disabled
key on option element to disable specific option.
Custom content
Custom content will be displayed at the end of the select dropdown.
Visible options
Use visibleOptions
property to change the number of options that will be
displayed in the select dropdown without scrolling.
Secondary text
Add secondary-text
key to the specific options to display secondary text.
Search
Set filter
property to enable options filtering.
Select with search inside a modal
Option groups
It is possible to group options by using optgroup
key.
Select with icons
Add icon
property to the specific options to display the option icon.
Validation
Set isValidated
and isValid
properties to enable component
validation. The validFeedback
and invalidFeedback
options allow to
modify the validation messages. Validate
method can be set on select's
change
event.
You can create custom rules and show the validation results via isValidated
and isValid
properties.
Set value
The setValue
method allows to programatically set the component selections.
Single selection
Add single value string to the arguments list to correctly select option with corresponding value in single selection mode.
Multi selection
Add array of string values to the arguments list to correctly select options with corresponding values in multi selection mode.
Select with toggle element
If you want to toggle Select via button, you have to add toggle
/ open
/ close
function from MDBSelect ref and pin her to this button.
Auto select
Set autoSelect
option to true
to enable selecting on Tab press.
Select - API
Import
Properties
Property | Type | Default | Description |
---|---|---|---|
autocomplete |
String | - |
Provides the autocomplete attribute to the input element. |
autoSelect |
Boolean | false |
Enables auto selecting on Tab press |
clearButton |
Boolean | false |
Adds clear button to the select input. |
disabled |
Boolean | false |
Changes select input state to disabled. |
displayedLabels |
Number | 5 |
The maximum number of comma-separated list of options displayed on the Multiselect. If a user selects more options than that value, the X options selected text will be displayed instead. If set to -1, the limit is off. |
excludeOptGroupsInFilter |
Boolean | false |
Allows to exclude option groups labels from the filter. If set to true , the filter will search only in the options and not show the option groups labels.
|
filter |
Boolean | false |
Displays filter input that allow to search for specific option. |
filterDebounce |
Number | 300 |
Adds delay to the options list updates when using filter input. Improves performance of the select with filter. |
filterFn |
Function | - |
Allows to customize the filter function. The Function should take two arguments: data and searchValue . The data argument is an array of options. The searchValue argument is a string value of the filter input. The function should return an array of filtered options.
|
invalidFeedback |
String |
|
The text which is displayed below the select when the
isValidated property is true and isValid prop is false.
|
isValidated |
Boolean | false |
Marks select as validated. |
isValid |
Boolean | false |
Marks select as valid. |
label |
String |
|
Defines select input label. |
multiple |
Boolean | false |
Enables multiple mode. |
noResultsText |
String | "No results" |
The text that will be displayed when no option is found after using select filter. |
optionHeight |
Number | 38 |
Height of the select option. Used to determine dropdown height and number of visible options. |
optionsSelectedLabel |
String | "options selected" |
The text which is displayed on the Multiselect when there are more than 5 (default) options selected, e.g. 7 options selected |
placeholder |
String |
|
Defines select input placeholder. |
preselect |
Boolean | true |
Basic select behaves like a native one and by default marks the first available option
as selected. To change this setting, easily set this property to false .
|
required |
Boolean | false |
Changes select input state to required. |
searchPlaceholder |
String | "Search..." |
Changes placeholder of the select search input. |
selectAll |
Boolean | true |
Displays select all option in multiselect dropdown. |
selectAllLabel |
String | "Select all" |
Changes label of select all option. |
size |
String |
|
Changes input size. Available options: sm , lg ,
default .
|
tag |
String | "div" |
Defines select wrapper tag. |
tabindex |
Number | 0 |
Adds passing tabindex value also to input. |
validFeedback |
String |
|
The text which is displayed below the select when the
isValidated and isValid properties are true.
|
visibleOptions |
Number | 5 |
The maximum number of options which are visible in the select dropdown without scrolling. |
v-model:options |
Array | Data array required to fill select component. | |
v-model:selected |
[String, Array, Number] | Readonly and reactive property for getting selected values. | |
white |
Boolean | false |
Adjust input colors for dark backgrounds. |
Methods
Name | Description | Example |
---|---|---|
clear |
Manually clears a selection | $refs.select1.clear(); |
close |
Manually closes a select | $refs.select1.close(); |
open |
Manually opens a select | $refs.select1.open(); |
setValue |
Programatically set component selections. Add single value for default select and array of values for multiselect. | $refs.select1.setValue(3); |
setOption |
Programatically set component selections by an option key. Use
-1 key to select all in multiple mode.
|
$refs.select1.setOption(2); |
toggle |
Manually toggles a select | $refs.select1.toggle(); |
toggleSelectAll |
Toggle select all. | $refs.select1.toggleSelectAll(); |
Events
Name | Description |
---|---|
change |
This event fires immediately on every select data change. |
clear |
This event fires immediately when the select is cleared. |
close |
This event fires immediately when the select is closed. |
closed |
This event fires when the select is closed and animation finished. |
open |
This event fires immediately when the select is opened. |
opened |
This event fires after the select is opened. |
search |
This event fires on input in search field. Information about the searched term can be accessed through the following property of the emitted event: e.value . |
CSS variables
As part of MDB’s evolving CSS variables approach, select now use local CSS variables for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.
Select CSS variables are in different classes which belong to this component. To make it easier to use them, you can find below all of the used CSS variables.