Skip to content

Select

Overview

The Select component provides a dropdown list for selecting a single value from multiple options. The component is designed with customization and flexibility in mind, allowing various configurations for rendering the dropdown list.

Storybook

Props

PropTypeDefaultDescription
modelValueString''Initial value of the select component.
optionsArray[]List of options to display in the dropdown. Each option should have text and value attributes by default.
itemTextString'text'Attribute name for the displayed text in each option.
itemValueString'value'Attribute name for the value in each option.
nameString''Name attribute for the select input.
errorBooleanfalseDetermines if the component is in an error state.
sizeString''Size of the select input. This can be small, medium, or large.
disabledBooleanfalseIf true, the select input is disabled.
errorClassString''Class to be applied when the input is in an error state.
labelString''Label for the select input.
labelClassString''Class to be applied to the label.
wrapperClassString''Class to be applied to the component wrapper.
hintString''Hint or help text displayed below the input.
errorMessageString''Error message displayed when the input is in an error state.
idString''ID attribute for the select input. If not provided, name will be used.
readonlyBooleanfalseIf true, the select input is read-only.
shadowBooleanfalseIf true, applies a shadow style to the input.

Events

EventPayload TypeDescription
update:modelValueStringEmits the current value of the select component.

Slots

SlotPropsDescription
default{}Default slot for additional content.
hint{}Custom hint content. If not provided, the hint prop will be used.
error{}Custom error content. If not provided, the errorMessage prop will be used.

Methods

MethodDescription
focusFocuses the select input.

Usage

To use the Select component:

  1. Import the component.
  2. Bind the necessary props.
  3. Optionally, use the slots for custom content.
vue
<script setup lang="ts">
import {ref} from 'vue';
import {Select} from '@morpheme/forms';

const selectedValue = ref('');
const options = [
  {text: 'Option 1', value: 'opt1'},
  {text: 'Option 2', value: 'opt2'},
];
</script>

<template>
  <Select v-model="selectedValue" :options="options" label="Choose an option" />
</template>
<script setup lang="ts">
import {ref} from 'vue';
import {Select} from '@morpheme/forms';

const selectedValue = ref('');
const options = [
  {text: 'Option 1', value: 'opt1'},
  {text: 'Option 2', value: 'opt2'},
];
</script>

<template>
  <Select v-model="selectedValue" :options="options" label="Choose an option" />
</template>

This will render a dropdown list with two options. The value of the selected option will be bound to the selectedValue ref.