Skip to content

VegaDropdown ​

The VegaDropdown component offers a flexible dropdown interface, enabling users to select options from a dynamic list. It is highly customizable, supporting various styling options through props such as background color, text color, border properties, and more. The component can operate with static options provided directly via props or fetch options dynamically using a remote handler function, ideal for scenarios where options are dependent on external data.

Simple example:

vue
<vega-dropdown
  :options="['Option 1', 'Option 2', 'Option 3']"
  value-field="id"
  label-field="name"
  background-color="#ffffff"
  hover-color="#f2f2f2"
  text-color="#333333"
  border-color="#cccccc"
  border-radius="8px"
  font-size="16px"
  option-padding="12px 15px"
  transition-duration="0.2s"
  infinite-scroll="true"
  max-width="200px"
  :remote-handler="() => {}"
>
  <template #trigger>
    <button>Click to Open</button>
  </template>
</vega-dropdown>

<script setup>
  import { VegaDropdown } from 'vega-ui'
</script>

Props ​

Props ​

Prop NameTypeDefault ValueDescription
background-colorstring'var(--vega-secondary)'Background color of the options list container.
border-colorstring'var(--vega-border-color)'Border color of the dropdown container.
border-radiusstring'4px'Border radius of the dropdown container.
close-on-selectbooleantrueCloses dropdown after selecting an option.
disabledbooleanfalseDisables interaction and prevents opening the dropdown.
filtersobject—Additional query params passed to remote-handler. Triggers reload when changed.
font-sizestring'inherit'Font size applied to dropdown content.
hide-if-emptybooleanfalseHides dropdown entirely if there are no options and it's opened.
hover-colorstring'var(--vega-border-color)'Background color of option on hover or keyboard navigation.
hover-text-colorstring'inherit'Text color of option when hovered or highlighted.
infinite-scrollbooleantrueEnables lazy loading more options on scroll (used with remote-handler).
item-selected-colorstring'var(--vega-primary)'Color used for selected option text and check icon.
label-fieldstring'description'Key used to display label when option is an object.
max-widthstring'300px'Maximum width of the dropdown container.
min-widthstring—Minimum width of the dropdown container.
max-heightnumber200Maximum height of options list before scrolling is enabled.
no-options-messagestring'No options available'Message shown when there are no options and not loading.
offset-leftnumber0Horizontal offset from trigger element (used by Floating UI).
offset-topnumber8Vertical offset from trigger element (used by Floating UI).
option-paddingstring'8px 12px'Padding applied to each option.
optionsArray<object | string | number>[]Static list of selectable options. Merged with remote data if provided.
placementDropdownPlacement'bottom' (Floating UI default)Preferred dropdown placement relative to trigger (e.g. top, bottom-start, etc.).
remote-handlerfunction—Async function for fetching options. Receives { page, per_page, search, ...filters }.
response-handlerfunction(res) => res.data.dataTransforms API response into options array.
scrollbar-colorstring'var(--vega-border-color)'Scrollbar color inside dropdown (Firefox-compatible).
show-searchbooleanfalseDisplays search input inside dropdown. Triggers remote fetch on input change.
show-selectedbooleanfalseDisplays selected value as a separate block at the top with a clear button.
text-colorstring'var(--vega-text-color)'Default text color of options.
tooltip-fieldstring—Key for tooltip text (shown via vega-tooltip if provided).
transition-durationstring'0.3s'Duration of dropdown fade-in/out animation.
value-fieldstring'id'Key used as unique value when option is an object.
wrapper-background-colorstring'var(--vega-border-color)'Background color of the outer dropdown wrapper (includes search and selected sections).
wrapper-paddingstring—Padding for the outer dropdown wrapper.
z-indexnumber1Controls stacking order of the dropdown.
search-placeholder-colorstring'var(--vega-text-color)'Search placeholder icon and text color
search-placeholder-textstring'Search...'Search placeholder text

API Response Format ​

The remote-handler function should expect the following response format from the server:

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

Events ​

The component emits the following events:

Event NameDescription
openEmitted when the dropdown is opened.
selectEmitted when an option is selected from the dropdown. This event passes the selected option as a parameter.
closeEmitted when the dropdown is closed.

Slots ​

The component provides slots that allow for the insertion of custom content at various points within the component.

Slot NameSlot PropsDescription
option{ option: Object }Slot for inserting custom content for each option within the dropdown list
trigger-Slot for inserting custom content used to trigger the dropdown. This slot is typically used for custom buttons or toggle elements that control the dropdown's visibility.