Select

Elsio SanchezAbout 4 minComponentAtomSelectAtomComponent

When there are plenty of options, use a drop-down menu to display and select desired ones.

Tips

This component requires the <client-only></client-only> wrap when used in SSR (eg: Nuxtopen in new window) and SSG (eg: VitePressopen in new window).

Basic usage

v-model is the value of el-option that is currently selected.

Viwer Source

Code

```vue
<template>
  <FieldSelect :value="value" :optionList="options" size="small" />
  <FieldSelect :value="value" :optionList="options" />
  <FieldSelect :value="value" :optionList="options" size="small" />
</template>
<script lang="ts" setup>
import { ref } from 'vue'

const value = ref('')

const options = [
  {
    value: 'Option1',
    label: 'Option1',
    disabled: false,
  },
  {
    value: 'Option2',
    label: 'Option2',
    disabled: false,
  },
  {
    value: 'Option3',
    label: 'Option3',
    disabled: false,
  },
  {
    value: 'Option4',
    label: 'Option4',
    disabled: false,
  },
  {
    value: 'Option5',
    label: 'Option5',
    disabled: false,
  },
]
</script>

```

:::

Disabled Option

Set the value of disabled in el-option to true to disable this option.

Viwer Source

Code

```vue
<template>
  <FieldSelect :value="value" :optionList="options" size="small" />
  <FieldSelect :value="value" :optionList="options" />
  <FieldSelect :value="value" :optionList="options" size="small" />
</template>
<script lang="ts" setup>
import { ref } from 'vue'

const value = ref('')

const options = [
  {
    value: 'Option1',
    label: 'Option1',
    disabled: false,
  },
  {
    value: 'Option2',
    label: 'Option2',
    disabled: false,
  },
  {
    value: 'Option3',
    label: 'Option3',
    disabled: false,
  },
  {
    value: 'Option4',
    label: 'Option4',
    disabled: false,
  },
  {
    value: 'Option5',
    label: 'Option5',
    disabled: false,
  },
]
</script>

```

:::

Disabled Select

Disable the whole component.

Set disabled of el-select to make it disabled.

Viwer Source

Code

```vue
<template>
  <FieldSelect :value="value" :optionList="options" :disabled="true" />
</template>
<script lang="ts" setup>
import { ref } from 'vue'

const value = ref('')

const options = [
  {
    value: 'Option1',
    label: 'Option1',
    disabled: false,
  },
  {
    value: 'Option2',
    label: 'Option2',
    disabled: true,
  },
  {
    value: 'Option3',
    label: 'Option3',
    disabled: false,
  },
  {
    value: 'Option4',
    label: 'Option4',
    disabled: false,
  },
  {
    value: 'Option5',
    label: 'Option5',
    disabled: false,
  },
]
</script>

```

:::

Clearable Single Select

You can clear Select using a clear icon.

Set clearable attribute for el-select and a clear icon will appear. Note that clearable is only for single select.

Code

#### **Viwer Source**

```vue
<template>
  <FieldSelect :value="value" :optionList="options" :clearable="true" />
</template>
<script lang="ts" setup>
import { ref } from 'vue'

const value = ref('')

const options = [
  {
    value: 'Option1',
    label: 'Option1',
    disabled: false,
  },
  {
    value: 'Option2',
    label: 'Option2',
    disabled: true,
  },
  {
    value: 'Option3',
    label: 'Option3',
    disabled: false,
  },
  {
    value: 'Option4',
    label: 'Option4',
    disabled: false,
  },
  {
    value: 'Option5',
    label: 'Option5',
    disabled: false,
  },
]
</script>

```

:::

Basic Multiple Select

Multiple select uses tags to display selected options.

Set multiple attribute for el-select to enable multiple mode. In this case, the value of v-model will be an array of selected options. By default the selected options will be displayed as Tags. You can collapse them to a text by using collapse-tags attribute. You can check them when mouse hover collapse text by using collapse-tags-tooltip attribute.

default

use collapse-tags

use collapse-tags-tooltip

use max-collapse-tags

Viwer Source

Code

```vue
<template>
  <p>default</p>
  <FieldSelect :value="value1" :optionList="options" :multiple="true" />
  <p>use collapse-tags</p>
  <FieldSelect :value="value2" :optionList="options" :multiple="true" :collapseTags="true" />
  <p>default</p>
  <FieldSelect :value="value3" :optionList="options" :multiple="true" :collapseTags="true" :collapseTagsTooltip="true" />
  <p>default</p>
  <FieldSelect :value="value4" :optionList="options" :multiple="true" :collapseTags="true" :collapseTagsTooltip="true" :multipleLimit="3" />
</template>
<script lang="ts" setup>
import { ref } from 'vue'

const value1 = ref([])
const value2 = ref([])
const value3 = ref([])
const value4 = ref([])

const options = [
  {
    value: 'Option1',
    label: 'Option1',
    disabled: false,
  },
  {
    value: 'Option2',
    label: 'Option2',
    disabled: true,
  },
  {
    value: 'Option3',
    label: 'Option3',
    disabled: false,
  },
  {
    value: 'Option4',
    label: 'Option4',
    disabled: false,
  },
  {
    value: 'Option5',
    label: 'Option5',
    disabled: false,
  },
]
</script>

```

:::

Option filtering

You can filter options for your desired ones.

Adding filterable to el-select enables filtering. By default, Select will find all the options whose label attribute contains the input value. If you prefer other filtering strategies, you can pass the filter-method. filter-method is a Function that gets called when the input value changes, and its parameter is the current input value.

Viwer Source

Code

```vue
<template>
  <FieldSelect :value="value" :optionList="options" :filterable="true" />
</template>
<script lang="ts" setup>
import { ref } from 'vue'

const value = ref('')

const options = [
  {
    value: 'Option1',
    label: 'Option1',
    disabled: false,
  },
  {
    value: 'Option2',
    label: 'Option2',
    disabled: true,
  },
  {
    value: 'Option3',
    label: 'Option3',
    disabled: false,
  },
  {
    value: 'Option4',
    label: 'Option4',
    disabled: false,
  },
  {
    value: 'Option5',
    label: 'Option5',
    disabled: false,
  },
]
</script>
```

:::

Props

NameDescriptionTypeMandatory
valuebinding valueStringTrue
optionListList of Options that must be displayed in the Select. Within the array of options, the attributes to be received and required are: { label: title, value: value, disabled: false rue } arrayTrue

Attributes

NameDescriptionTypeDefault
multiplewhether multiple-select is activatedBooleanFalse
collapseTagswhether to collapse tags to a text when multiple selectingBooleanFalse
collapseTagsTooltipwhether show all selected tags when mouse hover text of collapse-tags. To use this, collapse-tags must be trueBooleanFalse
multipleLimitmaximum number of options user can select when multiple is true. No limit when set to 0number0
disabledwhether Switch is disabledBooleanFalse
clearablewhether select can be clearedBooleanFalse
sizesize of Switch large / default / smallStringdefault
placeholderplaceholder the SelectStringSelect
filterablewhether Select is filterableBooleanFalse
allowCreatewhether creating new items is allowed. To use this, filterable must be trueBooleanFalse
noDataTextdisplayed text when there is no options, you can also use slot emptyStringNo data

Slots

NameDescription
headerCustomize Default Content Top
footerCustomize Default Content Bottom

Example for Developer

Open in StackBlitzopen in new window
Open in StackBlitz

Directory

  └─ src                                            # Main source code.
      └── Components                                # Global components
              └── Atoms                             # Atom components
                  └── FieldSelect                   # Field Select specific components.