Skip to content

VegaSelect ​

The VegaSelect component is a versatile tool that merges a dropdown list with a searchable input field. It allows users to select from predefined or dynamically loaded options, tailored for a variety of applications. Key features include customizable styling, support for infinite scrolling, and the ability to enable or disable user input through the searchable property.

Simple example:

vue
selected: <code>{{ value }}</code>
<VegaSelect
  v-model="value"
  :options="options"
  value-field="id"
  label-field="title"
>
</VegaSelect>

<script setup>
  import { VegaSelect } from 'vega-ui'
  const value = ref('')

  const options = ref([
    { id: 1, title: 'one' },
    { id: 2, title: '2S' },
  ])

</script>

Code above will give you a following result:

selected:

Props ​

Prop NameTypeDefault ValueDescription
background-colorstring"none"Background color of the input field.
background-color-dropdownstring'transparent'Background color of the dropdown.
border-colorstring"var(--vega-border-color)"Color of the input border.
border-color-dropdownstring'var(--vega-border-color)'Border color of the dropdown.
border-radiusstring"4px"Border radius of the input field.
border-radius-dropdownstring'4px'Border radius of the dropdown container.
clearablebooleantrueWhether to show a clear button in the input field.
delay-debouncenumber300Delay in milliseconds for debouncing input events.
dropdown-auto-positionbooleanfalseAutomatically positions the dropdown based on available space.
dropdown-close-no-selectbooleantrueCloses the dropdown when an option is selected.
dropdown-item-heightnumber34Height of each dropdown item in pixels.
dropdown-item-selected-colorstringvar(--vega-primary)Color of the selected dropdown item.
dropdown-scrollbar-colorstring'var(--vega-border-color)'Scrollbar color for the dropdown.
dropdown-z-indexnumber1Z-index of the dropdown menu.
filtersobjectOptional filters for remote data fetching.
font-colorstring"var(--vega-text-color)"Text color of the input field.
font-sizestring"inherit"Font size of the input text.
font-size-dropdownstring'inherit'Font size of the text in the dropdown.
focus-border-colorstring"var(--vega-border-color)"Border color when the input is focused.
hide-empty-dropdownbooleanfalseHides the dropdown when there are no options available.
hover-border-colorstring"var(--vega-border-color)"Border color when the input is hovered.
hover-color-dropdownstring'transparent'Background color of the option when hovered.
infinite-scrollbooleanfalseEnables infinite scrolling for the dropdown options.
labelstring''Label displayed above the input field.
label-fieldstring'label'Field in the option object that contains the display label.
model-valuestring, number, null""Value bound to the input via v-model.
no-options-messagestring'No options available'Message shown when there are no options to display.
not-emptybooleanfalseSelects the first option by default if set to true.
option-padding-dropdownstring'8px 12px'Padding inside each dropdown option.
optionsarray[]Array of selectable options (can be objects or primitives).
paddingstring"10px"Padding inside the input field.
placeholderstring""Placeholder text displayed when the input is empty.
placeholder-colorstring"var(--vega-gray)"Color of the placeholder text.
readonlybooleanfalseMakes the input field read-only if set to true.
remote-handlerfunctionFunction to fetch options remotely based on query parameters.
response-handlerfunction(response) => response.data.dataFunction to process the remote API response.
search-persistbooleanfalseRetains search input value when reopening the dropdown.
search-query-keystringsearchKey used for search queries in remote requests.
searchablebooleanfalseAllows user to filter options by typing in the input field.
text-alignstring"left"Text alignment within the input field.
text-color-dropdownstring'inherit'Text color of the options in the dropdown.
tooltip-fieldstringOptional field in the option object for tooltip text.
transition-duration-dropdownstring'0.3s'Duration of transition effects in the dropdown.
value-fieldstring'value'Field in the option object that contains the value to submit.
widthstring"100%"Width of the input field.
heightstring"auto"Height of the input field.

API Response Format ​

The remoteHandler function should expect the following response format from the server:

json
{
  "data": {
    "data": [
      { "id": 1, "name": "Option 1" },
      { "id": 2, "name": "Option 2" }
    ],
    "meta": {
      "total": 2
    }
  }
}

Events ​

The component emits the following events:

Event NameDescription
selectedEmitted when the user selects a value from the dropdown. The event passes the selected value as a parameter, allowing you to handle the selection in your application logic.
clearEmitted when the clear button is pressed, allowing you to reset the input field or perform other cleanup actions.

Slots ​

The component provides several slots that allow for the insertion of custom content at various points within the component. These slots enable you to enhance functionality and tailor the appearance to better fit the design of your user interface.

Slot NameDescription
labelUse this slot to insert custom label content above the input field, such as an icon or additional text.
triggerUsed to insert custom trigger content, such as a button or input field, that opens the dropdown.
clear-iconSlot for adding a custom icon for the clear action in the input component.
prefixSlot for adding content before the input field content, typically used for icons or labels.
postfixSlot for adding content after the input field content. Includes dynamic adjustment when the dropdown is opened.