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
<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.
Prop | Description | Type | Default |
---|---|---|---|
modelValue | The value for the element | Any | undefined |
name | The name for the actual underlying select | String | '' |
options | Array of options for the select | Array | undefined |
normalizeOptions | If we should normalize the options | Array | undefined |
multiple | Allow/Deny multiple selections | Boolean | false |
disabled | Disable the select | Boolean | false |
showEmpty | Show a empty placeholder when nothing is selected | Boolean | true |
placeholder | Placeholder for when no options are shown | String | Select an option |
empty | The object or value when nothing is selected | String | undefined |
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.
Attribute | Description | Type |
---|---|---|
option | The actual option on the loop | Object , Array |
safe | If its save to print HTML or we should scape | Boolean |
Slot before
Slot to override or pre-pend to the component before the component, ex: icon, etc.
Attribute | Description | Type |
---|---|---|
className | Classes injected | String |
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 )
Attribute | Description | Type |
---|---|---|
hasErrors | If the field has errors | Boolean |
type | Type of input | String |
showingPassword | If the password showing is toggled | Boolean |
Slot errors
Slot that holds the error messages when the component errors
prop is defined.
Attribute | Description | Type |
---|---|---|
errors | The errors being injected | [String, Array] |
hasErrors | If the field has errors | Boolean |
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.
Attribute | Description | Type |
---|---|---|
errors | The errors being injected | [String, Array, Undefined] |
feedback | The feedback message | [String, Undefined] |
Events 🚇
Here you may find the events emitted by this component.
Event | Description | Value |
---|---|---|
update:modelValue | When the value changes | any |