Skip to content
On this page

Select

A Native <select /> support regular options, multiple & many more.

Preview & Playground 🖼️

Here you may find a preview of the component, with error & possible variants.

🏄 Click to expand the code
vue
<script setup lang="ts">
import { Select } from '@flavorly/vanilla-components'
import { ref } from 'vue'
const value = ref(undefined)
const valueDisabled = ref(undefined)
const value2 = ref(undefined)

const options = [
  { value: 'vue', text: 'Vue' },
  { value: 'not_react', text: 'Not React' },
  { value: [{ anotherObject: true, nested: 'deep' }], text: 'Vue?' },
  {
    value: 'seprator',
    text: 'Other Frameworks',
    children: [
      { value: 'not_svelt', text: 'Not Svelt' },
      { value: 'not_angular', text: 'Neither Angular' },
    ],
  },
]
</script>

<template>
  <PreviewWrapper>
    <div class="grid space-y-2">
      <!-- Regular -->
      <Select
        v-model="value"
        placeholder="Please choose your stack"
        feedback="You can add SVGs as addons before & After"
        :options="options"
      />

      <Select
        v-model="value2"
        placeholder="Please choose your stack"
        feedback="You can add SVGs as addons before & After"
        :options="options"
        errors="There is something wrong with this field"
      />

      <Select
        v-model="valueDisabled"
        :disabled="true"
        placeholder="Im disabled"
        feedback="Im disabled :("
        :options="options"
      />
    </div>
  </PreviewWrapper>
</template>

Props 📥

Props available for this component extending the default variant & global props.

PropDescriptionTypeDefault
modelValueThe value for the elementAnyundefined
nameThe name for the actual underlying selectString''
optionsArray of options for the selectArrayundefined
normalizeOptionsIf we should normalize the optionsArrayundefined
multipleAllow/Deny multiple selectionsBooleanfalse
disabledDisable the selectBooleanfalse
showEmptyShow a empty placeholder when nothing is selectedBooleantrue
placeholderPlaceholder for when no options are shownStringSelect an option
emptyThe object or value when nothing is selectedStringundefined

Slots 🧬

Current slots available for this component are the following:

By default all slots get all the props and configuration from the component.

Slot option

This slot is used to render each option, please keep mind if you override this slot You must also make sure to support nested/children elements for groups. If you are looking for a select with more options please checkout the RichSelect component.

AttributeDescriptionType
optionThe actual option on the loopObject, Array
safeIf its save to print HTML or we should scapeBoolean

Slot before

Slot to override or pre-pend to the component before the component, ex: icon, etc.

AttributeDescriptionType
classNameClasses injectedString

Slot after

Slot to override or append to the component before the component, ex: icon, etc.

Attributes specially injected to the after slot for some inputs ( Ex: Password )

AttributeDescriptionType
hasErrorsIf the field has errorsBoolean
typeType of inputString
showingPasswordIf the password showing is toggledBoolean

Slot errors

Slot that holds the error messages when the component errors prop is defined.

AttributeDescriptionType
errorsThe errors being injected[String, Array]
hasErrorsIf the field has errorsBoolean

Slot feedback

Slot that holds the feedback messages when the component feedback prop is defined. When showing errors the feedback will be hidden by default, and vice-versa.

AttributeDescriptionType
errorsThe errors being injected[String, Array, Undefined]
feedbackThe feedback message[String, Undefined]

Events 🚇

Here you may find the events emitted by this component.

EventDescriptionValue
update:modelValueWhen the value changesany

Released under the MIT License.