FormSelect Component
The FormSelect
component is built with Vue 3 and provides a customizable select input with support for custom icons and slots. It's designed to be flexible and easy to integrate into your forms.
Basic Usage
Import and use FormSelect
in your Vue components as follows:
vue
<template>
<FormSelect v-model="select1">
<option value="">Select an option</option>
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
</FormSelect>
</template>
<script setup>
import { FormSelect } from '@robuust-digital/vue-components';
</script>
Props
The FormSelect component accepts the following props:
Prop | Type | Default | Description |
---|---|---|---|
modelValue | String , Number , Object | null | The selected value(s) |
icon | Object , Function | null | Specifies an icon to display within the select. @heroicons/vue can be used, or you can import your own .svg files. |
rootClass | String | '' | Additional classes for the root div |
Slots
The FormSelect component provides several slots for customization:
Default Slot
The default slot is used for the select options:
Show code
vue
<template>
<FormSelect v-model="select2">
<option value="">Choose a color</option>
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
</FormSelect>
</template>
Icon Slot
You can customize the dropdown icon using the icon
slot:
Show code
vue
<template>
<FormSelect v-model="select3">
<option value="">Select an option</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<template #icon>
<BeakerIcon />
</template>
</FormSelect>
</template>
<script setup>
import { BeakerIcon } from '@heroicons/vue/16/solid';
</script>
Examples
Pre-selected Value
Show code
vue
<template>
<FormSelect v-model="select4">
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
</FormSelect>
</template>
<script setup>
const select4 = ref('option2');
</script>
Custom Icon
Show code
vue
<template>
<FormSelect :icon="BeakerIcon">
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option selected value="option3">Option 3</option>
</FormSelect>
</template>
<script setup>
import { BeakerIcon } from '@heroicons/vue/16/solid';
</script>
Customization with Tailwind CSS
To customize the select styles globally, extend your Tailwind configuration:
javascript
// tailwind.config.js
import components from '@robuust-digital/vue-components/tailwind';
export default {
theme: {
extend: {
components: (theme) => ({
select: {
'--rvc-select-border-radius': 'var(--rvc-base-border-radius)',
'--rvc-select-border-width': 'var(--rvc-base-border-width)',
'--rvc-select-border-color': 'var(--rvc-base-border-color)',
'--rvc-select-font-size': 'var(--rvc-base-font-size)',
'--rvc-select-box-shadow': 'var(--rvc-base-box-shadow)',
'--rvc-select-color': 'var(--rvc-input-color)',
'--rvc-select-bg-color': 'var(--rvc-input-bg-color)',
'--rvc-select-icon-size': 'var(--rvc-input-icon-size)',
'--rvc-select-icon-color': 'var(--rvc-input-icon-color)',
'--rvc-select-padding-y': 'var(--rvc-input-padding-y)',
'--rvc-select-padding-x': 'var(--rvc-input-padding-x)',
'--rvc-select-line-height': '1.375rem',
},
}),
},
},
plugins: [components],
};