Select #
Select field components are used for collecting user provided information from a list of options. This component opens up a menu for the selection list and action.
Examples #
Default select #
Styles #
Select styles inherit from input styles
Multiple select #
Includes single or multiple selects.
Decorators #
Objects as options #
You can use objects as options. Text will be showing from text-by
property from object. Value can be also returned from select using value-by
instead of whole object. Comparing object values is done by track-by
prop or value-by
if it is not provided.
Note: Using text-by
without a value-by
or track-by
may cause inconsistencies in expected behavior.
When using Objects as options
, it's necessary to utilize track-by
because ObjectOptions are compared by object reference by default. track-by
allows resolving this comparison by either literal equality.
Track by #
Track by can be used if you have multiple options with same value.
Slots #
Includes option
, content
, prepend
, prepend-inner
, append
and append-inner
slots.
Tagging #
content
slot allows you to overwrite default input
element with custom one. So you are able to set tagging state via adding VaChip
component:
State #
Includes error, success, disabled or loading state
Searchable #
Supports ability to filter option list by typing
Allow create #
You can add options that initial options do not have
Validation rules #
Select accepts an array of functions that take an input value as an argument and return either true / false or a string with an error message
Max visible selected options #
The max-visible-options
props sets amount of selected options, that will be shown inside of input wrapper. The rest will be hidden, but may be shown after clicking the badge with hidden options counter.
Displaying selected options at the top of the list #
The selected-top-shown
prop forces to display selected options at the top of the options list.
Autocomplete #
The autocomplete
prop enables autocomplete behavior for the va-select
.
Icon-selection #
The 'iconOption' property allows the addition of custom options to the select dropdown menu, each with an icon and a name.
Accessibility #
Select has combobox
role associated with listbox
in dropdown menu. aria-expanded
is applied if dropdown is opened. aria-label
is set to $t:selectOption
if value is selected and $t:noSelectedOption
if value is empty. aria-controls
is set to combobox-controls-${id}
. aria-labelledby
is set to input-label-${id}
. aria-describedby
is set to input-character-count-${id}
. aria-activedescendant
is set to option-${id}
. aria-autocomplete
is set to list
if autocomplete is enabled. aria-owns
is set to combobox-controls-${id}
. aria-haspopup
is set to listbox
. aria-disabled
is set to true
if select is disabled. aria-required
is set to true
if select is required. aria-invalid
is set to true
if select is invalid. aria-multiselectable
is set to true
if select is multiple. aria-readonly
is set to true
if select is readonly.
Keyboard navigation #
By using ARROW DOWN
and ARROW UP
you can move between options
By using ENTER
and SPACE
you can select current option
If you type while option list is opened this will create a search buffer (will reset if you do not type for 1 second) that will be used to search in the options labels
API #
Props #
Name | Description | Types | Default |
---|---|---|---|
allowCreate | Allow creating new options. Can be set to |
|
|
anchor |
| - | |
anchorSelector | Anchor CSS selector instead of passing slot |
|
|
ariaClearLabel | Set aria label for clear button |
|
|
ariaLabel | Set aria label. By default it |
|
|
ariaSearchLabel | Set aria label for search input |
|
|
autocomplete | Enables the autocomplete behaviour. |
|
|
autoPlacement | If dropdown doesn't fit viewport, it will be placed automatically to fit viewport |
|
|
autoSelectFirstOption | Automatically select the first option |
|
|
background | The color name of the background color |
| - |
clearable | Sets ability to clear selection |
|
|
clearableIcon | Sets the cleaning button icon. |
|
|
clearValue | Sets value that should be set after clearing |
|
|
closeOnAnchorClick | Dropdown will be closed when anchor is clicked |
|
|
closeOnChange |
|
| |
closeOnClickOutside | Dropdown will be closed when clicked outside dropdown content and anchor |
|
|
closeOnContentClick |
|
| |
closeOnFocusOutside |
|
| |
color | Color of the component (theme string or |
|
|
contentClass |
|
| |
counter |
| - | |
cursor | Dropdown will be rendered relative to cursor position |
|
|
delay | Sets throttling delay (ms) for the components any data change (useful for huge data). |
|
|
dirty | Sets the dirty state of the component |
|
|
disabled | Applies |
| - |
disabledBy | Specify the key in the object to be used as item |
|
|
dropdownIcon | Sets the dropdown icon. Can be object if you want to sets different open/close icons |
|
|
error | Show component in error state. |
| - |
errorCount | Number of error messages displayed. |
|
|
errorMessages | Error messages for the component. |
| - |
groupBy | When |
|
|
hideSelected | Sets ability to hide selected options |
|
|
highlightMatchedText | Highlight chars in options that are match the input value (search or autocomplete). |
|
|
hoverOutTimeout | Time in |
|
|
hoverOverTimeout | Time in |
|
|
immediateValidation | Sets the validation to be performed when the component is mounted |
|
|
innerLabel |
|
| |
inputAriaDescribedby |
| - | |
inputAriaLabel |
|
| |
inputAriaLabelledby |
| - | |
isContentHoverable | If true, dropdown content will be hoverable |
|
|
isOpen |
| - | |
keepAnchorWidth |
|
| |
label | Same as native |
|
|
loading | Indicates that something is loading (spinner icon). |
|
|
maxHeight | Sets option list maximum height |
|
|
maxLength |
| - | |
maxSelections | Sets the maximum amount of selected options |
| - |
maxVisibleOptions | Max selected options amount, that will be shown inside of input wrapper. |
|
|
messages | Description messages for the component. |
|
|
minSearchChars | Minimal amount of chars in input value to initiate search or autocomplete. |
|
|
modelValue | The value of the |
| - |
multiple | Sets select in multiple mode |
|
|
name | Applies |
| - |
noOptionsText | Sets text whom displaying if list have no items |
|
|
offset |
|
| |
options | Available options that the user can select from |
|
|
placeholder | Sets the placeholder text to input |
|
|
placement | Sets option list placement. More about placements |
|
|
preset | Named preset combination of component props. |
| - |
readonly | Doesn't look disabled, but acts like one. Mostly useful for wrapper components. |
| - |
requiredMark | Adds required mark to the label |
|
|
role | Sets the |
|
|
rules | Validation rules . |
|
|
search |
| - | |
searchable | Sets ability to filter option list by typing |
|
|
searchPlaceholderText | The text of placeholder of the search input |
|
|
selectedTopShown | Selected options will be shown at the top of the options list. |
|
|
separator | Text to separate selected values |
|
|
stickToEdges | Dropdown will not be rendered outside of viewport. It will be moved in opposite direction. |
|
|
success | Show component in success state. |
|
|
tabindex | Sets the custom |
|
|
target | Navigation target, More info here. |
| - |
teleport | Element where content will be rendered |
| - |
textBy | When |
|
|
trackBy | When |
|
|
trigger | Action that will triggered when open and close dropdown. |
|
|
valueBy | When |
|
|
verticalScrollOnOverflow |
|
| |
virtualScroller | Enables virtual scrolling |
|
|
width | Sets option list width |
|
|
Events #
Name | Description |
---|---|
clear | Emitted if select value has been cleared. The event argument is:
|
createNew | Emitted if search input has created new option |
scrollBottom | Emitted once the scroll position of options has reached the bottom. The event argument is:
|
update:dirty | Fires when the dirty state changes |
update:error | Fires when the error state changes |
update:errorMessages | Fires when the error messages change |
update:isOpen | |
update:modelValue | The event is triggered when the component needs to change the model. Is also used by |
update:search | Emitted if search value has changed |
updateSearch | Emitted if search value has changed. The event argument is:
|
Slots #
Name | Description |
---|---|
append | Adds an item outside the input and after input content |
appendInner | Adds an item inside the input and after input content |
content | Adds an item instead the input |
hiddenOptionsBadge | Replaces default badge with hidden options counter (see |
hideOptionsButton | Replaces default button for hiding selected options that are over the limit (see |
option | Allows to specify option template |
prepend | Adds an item outside the input and before input content |
prependInner | Adds an item inside the input and before input content |
Methods #
Name | Description |
---|---|
reset | Clearing select value |
Css Variables #
Name | Default Value |
---|---|
--va-select-cursor | pointer |
--va-select-dropdown-background | var(--va-background-secondary) |
--va-select-state-icon-margin-left | 0.25rem |