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"
  width="200px"
  :remote-handler="() => {}"
>
  <template #trigger>
    <button>Click to Open</button>
  </template>
</vega-dropdown>

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

Props ​

Prop NameTypeDefault ValueDescription
auto-positionbooleanfalseAutomatically places dropdown above/below depending on available space. Uses item-height for accurate height calculation.
background-colorstring'transparent'Background color of the dropdown menu.
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 with the dropdown if true.
filtersobjectOptional filters to apply when fetching remote data.
font-sizestring'inherit'Font size used inside the dropdown.
hide-if-emptybooleanfalseHides the dropdown if no options are available.
hover-colorstring'transparent'Background color of an option when hovered.
infinite-scrollbooleanfalseEnables infinite scroll for loading more dropdown options.
item-heightnumber34Height of a single dropdown item (in pixels).
item-selected-colorstringvar(--vega-primary)Background color of the selected dropdown item.
label-fieldstring'label'Key in the option object representing the label to display.
no-options-messagestring'No options available'Message displayed when there are no options to show.
offset-leftstring0Horizontal offset from the trigger element.
offset-topstring8pxVertical offset from the trigger element.
option-paddingstring'8px 12px'Padding applied to each dropdown option.
optionsArray<object | string | number>[]List of options available for selection. Can be primitives or objects.
remote-handlerfunctionFunction that fetches remote data based on query parameters and returns a promise with options.
response-handlerfunction(response) => response.data.dataFunction to process remote API responses.
scrollbar-colorstring'var(--vega-border-color)'Color of the scrollbar inside the dropdown.
text-colorstring'inherit'Text color for dropdown options.
tooltip-fieldstringOptional key in the option object for tooltip text.
transition-durationstring'0.3s'Duration of transition animations within the dropdown.
value-fieldstring'value'Key in the option object representing the value to be submitted.
widthstring100%Width of the dropdown in CSS format.
z-indexnumber1Z-index of the dropdown element.

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 NameDescription
triggerSlot 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.