Skip to content

Select

Select components for single and multiple value selection. Choose between Single Select, Multi Select, or Tag Select variants.

ts
import { CoarSelect, CoarMultiSelect, CoarTagSelect } from '@cocoar/vue-ui';
import type { CoarSelectOption } from '@cocoar/vue-ui';

Single Select

Select a single option from a dropdown list.

Selected: none

vue
<template>
  <div style="max-width: 320px;">
    <CoarFormField label="Favorite fruit">
      <CoarSelect
        v-model="value"
        :options="options"
        placeholder="Choose a fruit..."
      />
    </CoarFormField>
    <p style="margin-top: 8px; font-size: 13px; color: #64748b;">
      Selected: {{ value || 'none' }}
    </p>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { CoarSelect, CoarFormField } from '@cocoar/vue-ui';
import type { CoarSelectOption } from '@cocoar/vue-ui';

const options: CoarSelectOption<string>[] = [
  { value: 'apple', label: 'Apple' },
  { value: 'banana', label: 'Banana' },
  { value: 'cherry', label: 'Cherry' },
  { value: 'date', label: 'Date' },
  { value: 'elderberry', label: 'Elderberry' },
  { value: 'fig', label: 'Fig' },
];

const value = ref<string | null>(null);
</script>

States

Disabled, required, and error states.

Please select an option
vue
<template>
  <div style="display: flex; flex-direction: column; gap: 16px; max-width: 320px;">
    <CoarFormField label="Required" required>
      <CoarSelect :options="options" placeholder="Required field" :required="true" />
    </CoarFormField>
    <CoarFormField label="With Error" error="Please select an option">
      <CoarSelect :options="options" placeholder="Error state" />
    </CoarFormField>
    <CoarFormField label="Disabled">
      <CoarSelect :options="options" placeholder="Disabled" :disabled="true" />
    </CoarFormField>
  </div>
</template>

<script setup lang="ts">
import { CoarSelect, CoarFormField } from '@cocoar/vue-ui';
import type { CoarSelectOption } from '@cocoar/vue-ui';

const options: CoarSelectOption<string>[] = [
  { value: 'apple', label: 'Apple' },
  { value: 'banana', label: 'Banana' },
  { value: 'cherry', label: 'Cherry' },
];
</script>

Multi Select & Tag Select

Select multiple values from a dropdown. Multi Select shows checkmarks, Tag Select shows removable tags inline.

Selected: none

Selected: none

vue
<template>
  <div style="display: flex; flex-direction: column; gap: 24px; max-width: 320px;">
    <div>
      <CoarFormField label="Favorite fruits">
        <CoarMultiSelect
          v-model="multiValue"
          :options="fruitOptions"
          placeholder="Choose multiple..."
        />
      </CoarFormField>
      <p style="margin-top: 8px; font-size: 13px; color: #64748b;">
        Selected: {{ multiValue.join(', ') || 'none' }}
      </p>
    </div>
    <div>
      <CoarFormField label="Countries">
        <CoarTagSelect
          v-model="tagValue"
          :options="countryOptions"
          placeholder="Add countries..."
        />
      </CoarFormField>
      <p style="margin-top: 8px; font-size: 13px; color: #64748b;">
        Selected: {{ tagValue.join(', ') || 'none' }}
      </p>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { CoarMultiSelect, CoarTagSelect, CoarFormField } from '@cocoar/vue-ui';
import type { CoarSelectOption } from '@cocoar/vue-ui';

const fruitOptions: CoarSelectOption<string>[] = [
  { value: 'apple', label: 'Apple' },
  { value: 'banana', label: 'Banana' },
  { value: 'cherry', label: 'Cherry' },
  { value: 'date', label: 'Date' },
  { value: 'elderberry', label: 'Elderberry' },
  { value: 'fig', label: 'Fig' },
];

const countryOptions: CoarSelectOption<string>[] = [
  { value: 'us', label: 'United States' },
  { value: 'de', label: 'Germany' },
  { value: 'fr', label: 'France' },
  { value: 'jp', label: 'Japan' },
  { value: 'br', label: 'Brazil' },
  { value: 'au', label: 'Australia' },
];

const multiValue = ref<string[]>([]);
const tagValue = ref<string[]>([]);
</script>

Options Format

Options must follow the CoarSelectOption<T> interface:

ts
interface CoarSelectOption<T> {
  value: T;
  label: string;
  disabled?: boolean;
  group?: string;
  icon?: string;
}

const options: CoarSelectOption<string>[] = [
  { value: 'apple', label: 'Apple' },
  { value: 'banana', label: 'Banana', disabled: true },
];

API

Props

PropTypeDefaultDescription
v-modelT | nullnullSelected value (the option's value field)
optionsCoarSelectOption<T>[][]Array of { value, label } option objects
placeholderstring''Placeholder when empty
size'xs' | 's' | 'm' | 'l''m'Input size
disabledbooleanfalseDisable the select
requiredbooleanfalseMark as required
errorbooleanfalseError state (auto-injected from CoarFormField)

i18n Keys

These keys can be translated via @cocoar/vue-localization.

These keys apply to CoarSelect, CoarMultiSelect, and CoarTagSelect.

KeyDefault (English)Used as
coar.ui.select.clearSelection'Clear selection'Clear button aria-label
coar.ui.select.options'Options'Options listbox aria-label
coar.ui.select.noResults'No results found'Empty state text when search returns no matches
coar.ui.select.noOptions'No options available'Empty state text when options list is empty
coar.ui.tagSelect.remove'Remove'Tag remove button aria-label
coar.ui.tagSelect.options'Options'Tag select listbox aria-label

Released under the Apache-2.0 License.