Skip to content

Basic Select

Build a single-select component from simple string options to a full-featured clearable select with object data.

String Options

The simplest possible select: an array of strings bound with v-model.

API Setup (String Options)

vue
<script setup>
import { ref } from 'vue'
import {
  SelectRoot,
  SelectControl,
  SelectInput,
  SelectContent,
  SelectOption,
} from 'vue-superselect'

const selected = ref(null)
const fruits = ['Apple', 'Banana', 'Cherry', 'Orange']
</script>
Basic String Select

Minimal Pattern

template
<SelectRoot v-model="selected">
  <SelectControl>
    <SelectInput placeholder="Pick a fruit..." />
  </SelectControl>
  <SelectContent>
    <SelectOption
      v-for="fruit in fruits"
      :key="fruit"
      :value="fruit"
      :label="fruit"
    >
      {{ fruit }}
    </SelectOption>
  </SelectContent>
</SelectRoot>

For string options, :value and :label are the same string. The label prop is used for filtering. When a user types in the input, options are matched against their label.

Need the full setup/import boilerplate? See Quick Start.

Object Options

When your options are objects, use label-key and value-key on SelectRoot to tell the component which fields to use.

Object Options with label-key / value-key

How Object Binding Works

template
<SelectRoot
  v-model="selected"
  :items="countries"
  label-key="name"
  value-key="code"
>
PropPurpose
:itemsThe full array of option objects. Used for label resolution when the dropdown is closed.
label-keyWhich field to display and filter by (e.g. "name")
value-keyWhich field becomes the v-model value (e.g. "code")

With value-key="code", the v-model value will be "au", "br", etc., not the full object.

Each SelectOption still receives the individual :value and :label:

template
<SelectOption
  v-for="country in countries"
  :key="country.code"
  :value="country.code"
  :label="country.name"
>
  {{ country.name }}
</SelectOption>

Clearable with Trigger and Empty State

Add a clear button, a dropdown toggle trigger, and a "no results" message for a complete select experience.

Clearable Select with Trigger and Empty State

Additional Components

ComponentPurpose
SelectClearButton that resets the value to null. Renders as <button> by default.
SelectTriggerButton that toggles the dropdown open/closed.
SelectEmptyShown when filtering produces zero visible options.
template
<SelectControl>
  <SelectInput />
  <SelectClear v-if="selected">x</SelectClear>
  <SelectTrigger>
    <!-- chevron icon -->
  </SelectTrigger>
</SelectControl>

SelectClear is conditionally rendered with v-if. Show it only when there's a value to clear.

SelectEmpty goes inside SelectContent:

template
<SelectContent>
  <SelectOption v-for="..." />
  <SelectEmpty>No results found</SelectEmpty>
</SelectContent>

Scoped Slot Props

Every SelectOption exposes scoped slot props for conditional styling:

template
<SelectOption v-slot="{ selected, active, disabled, option }">
  {{ option }}
</SelectOption>
PropTypeDescription
selectedbooleanWhether this option is currently selected
activebooleanWhether this option is keyboard-highlighted
disabledbooleanWhether this option is disabled
optionunknownThe raw value passed to :value

Next Steps