Convert Figma logo to code with AI

shentao logovue-multiselect

Universal select/multiselect/tagging component for Vue.js

6,666
989
6,666
329

Top Related Projects

Everything you wish the HTML <select> element could do, wrapped up into a lightweight, extensible Vue component.

4,103

A lightweight Vue.js UI library with a simple API, inspired by Google's Material Design.

⚡️ Blazing fast scrolling for any amount of data

Vue drag-and-drop component based on Sortable.js

✅ Painless Vue forms

Quick Overview

Vue-multiselect is a feature-rich, customizable select/dropdown component for Vue.js. It supports single and multiple selections, tagging, searching, and custom option rendering, making it a versatile solution for various form input scenarios in Vue applications.

Pros

  • Highly customizable with numerous props and slots
  • Supports both single and multiple selections
  • Includes search functionality and custom option rendering
  • Actively maintained with good documentation

Cons

  • Learning curve for advanced customizations
  • May be overkill for simple select needs
  • Styling can be challenging to match with certain design systems
  • Performance might degrade with very large datasets

Code Examples

  1. Basic single select:
<template>
  <multiselect
    v-model="value"
    :options="options"
    :searchable="false"
    :close-on-select="false"
    placeholder="Pick a value"
  />
</template>

<script>
import Multiselect from 'vue-multiselect'

export default {
  components: { Multiselect },
  data() {
    return {
      value: null,
      options: ['Option 1', 'Option 2', 'Option 3']
    }
  }
}
</script>
  1. Multiple select with tagging:
<template>
  <multiselect
    v-model="value"
    tag-placeholder="Add this as new tag"
    placeholder="Search or add a tag"
    label="name"
    track-by="code"
    :options="options"
    :multiple="true"
    :taggable="true"
    @tag="addTag"
  />
</template>

<script>
import Multiselect from 'vue-multiselect'

export default {
  components: { Multiselect },
  data() {
    return {
      value: [],
      options: [
        { name: 'Vue.js', code: 'vu' },
        { name: 'React', code: 're' },
        { name: 'Angular', code: 'ng' }
      ]
    }
  },
  methods: {
    addTag(newTag) {
      const tag = {
        name: newTag,
        code: newTag.substring(0, 2)
      }
      this.options.push(tag)
      this.value.push(tag)
    }
  }
}
</script>
  1. Custom option template:
<template>
  <multiselect
    v-model="value"
    :options="options"
    :custom-label="nameWithLang"
    placeholder="Select an option"
    label="name"
    track-by="name"
  >
    <template slot="option" slot-scope="props">
      <span>{{ props.option.name }}</span>
      <span class="language">{{ props.option.language }}</span>
    </template>
  </multiselect>
</template>

<script>
import Multiselect from 'vue-multiselect'

export default {
  components: { Multiselect },
  data() {
    return {
      value: null,
      options: [
        { name: 'Vue.js', language: 'JavaScript' },
        { name: 'Rails', language: 'Ruby' },
        { name: 'Sinatra', language: 'Ruby' }
      ]
    }
  },
  methods: {
    nameWithLang({ name, language }) {
      return `${name} — [${language}]`
    }
  }
}
</script>

Getting Started

  1. Install the package:

    npm install vue-multiselect
    
  2. Import and use in your Vue component:

    <template>
      <div>
        <multiselect v-model="value" :options="options"></multiselect>
      </div>
    </template>
    
    <script>
    import Multiselect from 'vue-multiselect'
    
    export default {
      components: {
    

Competitor Comparisons

Everything you wish the HTML <select> element could do, wrapped up into a lightweight, extensible Vue component.

Pros of vue-select

  • Lighter weight and simpler API, making it easier to integrate and use
  • More customizable appearance through scoped slots and CSS variables
  • Better TypeScript support with full type definitions

Cons of vue-select

  • Fewer built-in features compared to vue-multiselect (e.g., no tagging or grouping options)
  • Less extensive documentation and examples
  • Smaller community and fewer updates/maintenance

Code Comparison

vue-select:

<v-select
  v-model="selected"
  :options="options"
  :reduce="option => option.code"
  label="name"
/>

vue-multiselect:

<multiselect
  v-model="selected"
  :options="options"
  :custom-label="option => option.name"
  track-by="code"
  :multiple="true"
/>

Both libraries offer similar core functionality for creating select components in Vue applications. vue-select focuses on simplicity and customization, while vue-multiselect provides more built-in features out of the box. The choice between them depends on the specific requirements of your project, such as the need for advanced features, TypeScript support, or a lighter-weight solution.

4,103

A lightweight Vue.js UI library with a simple API, inspired by Google's Material Design.

Pros of Keen-UI

  • Offers a comprehensive set of UI components beyond just multiselect
  • Provides a consistent design language across all components
  • Includes accessibility features out of the box

Cons of Keen-UI

  • Larger bundle size due to the full UI component library
  • May require more setup and configuration for simple use cases
  • Less focused on optimizing the multiselect component specifically

Code Comparison

Keen-UI multiselect usage:

<template>
  <ui-select
    v-model="selectedItems"
    :options="options"
    multiple
    placeholder="Select items"
  ></ui-select>
</template>

Vue-multiselect usage:

<template>
  <multiselect
    v-model="selectedItems"
    :options="options"
    :multiple="true"
    placeholder="Select items"
  ></multiselect>
</template>

Both libraries offer similar syntax for basic multiselect functionality. However, Keen-UI uses the ui-select component name, while Vue-multiselect uses multiselect. Keen-UI's approach is consistent with its other UI components, while Vue-multiselect focuses solely on the multiselect functionality.

⚡️ Blazing fast scrolling for any amount of data

Pros of vue-virtual-scroller

  • Optimized for rendering large lists with improved performance
  • Supports dynamic item heights and horizontal scrolling
  • Provides smooth scrolling experience for large datasets

Cons of vue-virtual-scroller

  • More complex implementation compared to vue-multiselect
  • Requires additional setup for custom item rendering
  • May have a steeper learning curve for beginners

Code Comparison

vue-virtual-scroller:

<template>
  <RecycleScroller
    class="scroller"
    :items="list"
    :item-size="32"
    key-field="id"
    v-slot="{ item }"
  >
    <div class="user">{{ item.name }}</div>
  </RecycleScroller>
</template>

vue-multiselect:

<template>
  <multiselect
    v-model="value"
    :options="options"
    :multiple="true"
    :close-on-select="false"
    placeholder="Pick some"
  ></multiselect>
</template>

vue-virtual-scroller is focused on efficiently rendering large lists with virtual scrolling, while vue-multiselect is designed for creating customizable dropdown selection components. The former is better suited for performance-critical applications with extensive data, while the latter offers a more straightforward solution for multi-select functionality.

Vue drag-and-drop component based on Sortable.js

Pros of Vue.Draggable

  • Provides drag-and-drop functionality for list reordering
  • Integrates seamlessly with Vue.js components
  • Supports touch devices and works well on mobile

Cons of Vue.Draggable

  • Limited to drag-and-drop functionality, not a full-featured select component
  • May require additional styling and customization for complex use cases

Code Comparison

Vue.Draggable:

<draggable v-model="myArray">
  <div v-for="element in myArray" :key="element.id">
    {{ element.name }}
  </div>
</draggable>

vue-multiselect:

<multiselect
  v-model="value"
  :options="options"
  :multiple="true"
  :close-on-select="false"
  placeholder="Pick some"
></multiselect>

Summary

Vue.Draggable is focused on providing drag-and-drop functionality for list reordering, while vue-multiselect is a feature-rich select component with support for multiple selections, tagging, and searching. Vue.Draggable excels in its specific use case but lacks the versatility of vue-multiselect for complex selection scenarios. The choice between the two depends on the specific requirements of your project, with Vue.Draggable being ideal for sortable lists and vue-multiselect better suited for advanced selection interfaces.

✅ Painless Vue forms

Pros of vee-validate

  • More comprehensive form validation solution
  • Supports asynchronous and custom validation rules
  • Integrates well with various UI frameworks and form inputs

Cons of vee-validate

  • Steeper learning curve due to more complex API
  • Potentially heavier bundle size for simpler use cases
  • May require additional configuration for optimal performance

Code Comparison

vee-validate:

import { defineRule, Form, Field } from 'vee-validate';

defineRule('required', value => {
  if (!value || !value.length) {
    return 'This field is required';
  }
  return true;
});

vue-multiselect:

import Multiselect from 'vue-multiselect';

export default {
  components: { Multiselect },
  data() {
    return { value: null, options: ['Option 1', 'Option 2', 'Option 3'] }
  }
}

While vee-validate focuses on form validation with a more extensive API, vue-multiselect is specifically designed for creating customizable dropdown components. vee-validate offers greater flexibility for complex form scenarios, but vue-multiselect provides a simpler solution for multi-select functionality. The choice between the two depends on the specific requirements of your project, with vee-validate being more suitable for comprehensive form validation needs and vue-multiselect for specialized dropdown implementations.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

vue-multiselect

Documentation for version 3

Documentation for v3.0.0 is almost the same as for v2.x as it is mostly backward compatible. For the full docs for v3 and previous versions, check out: vue-multiselect.js.org

Sponsors

GetForm Logo

Suade Logo

Storyblok

Vue Mastery Logo

Features & characteristics:

  • NO dependencies
  • Single select
  • Multiple select
  • Tagging
  • Dropdowns
  • Filtering
  • Search with suggestions
  • Logic split into mixins
  • Basic component and support for custom components
  • V-model support
  • Vuex support
  • Async options support
  • Fully configurable (see props list below)

Install & basic usage

npm install vue-multiselect@next
<template>
  <div>
    <VueMultiselect
      v-model="selected"
      :options="options">
    </VueMultiselect>
  </div>
</template>

<script>
import VueMultiselect from 'vue-multiselect'
export default {
  components: { VueMultiselect },
  data () {
    return {
      selected: null,
      options: ['list', 'of', 'options']
    }
  }
}
</script>

<style src="vue-multiselect/dist/vue-multiselect.css"></style>

JSFiddle

Example JSFiddle – Use this for issue reproduction.

Examples

Single select / dropdown

<VueMultiselect
  :model-value="value"
  :options="source"
  :searchable="false"
  :close-on-select="false"
  :allow-empty="false"
  @update:model-value="updateSelected"
  label="name"
  placeholder="Select one"
  track-by="name"
/>

Single select with search

<VueMultiselect
  v-model="value"
  :options="source"
  :close-on-select="true"
  :clear-on-select="false"
  placeholder="Select one"
  label="name"
  track-by="name"
/>

Multiple select with search

<VueMultiselect
  v-model="multiValue"
  :options="source"
  :multiple="true"
  :close-on-select="true"
  placeholder="Pick some"
  label="name"
  track-by="name"
/>

Tagging

with @tag event

<VueMultiselect
  v-model="taggingSelected"
  :options="taggingOptions"
  :multiple="true"
  :taggable="true"
  @tag="addTag"
  tag-placeholder="Add this as new tag"
  placeholder="Type to search or add tag"
  label="name"
  track-by="code"
/>

addTag (newTag) {
  const tag = {
    name: newTag,
    code: newTag.substring(0, 2) + Math.floor((Math.random() * 10000000))
  }
  this.taggingOptions.push(tag)
  this.taggingSelected.push(tag)
},

Asynchronous dropdown

<VueMultiselect
  v-model="selectedCountries"
  :options="countries"
  :multiple="multiple"
  :searchable="searchable"
  @search-change="asyncFind"
  placeholder="Type to search"
  label="name"
  track-by="code"
>
  <template #noResult>
    Oops! No elements found. Consider changing the search query.
  </template>
</VueMultiselect>
methods: {
  asyncFind (query) {
    this.countries = findService(query)
  }
}

Special Thanks

Thanks to Matt Elen for contributing this version!

A Vue 3 upgrade of @shentao's vue-mulitselect component. The idea is that when you upgrade to Vue 3, you can swap the two components out, and everything should simply work. Feel free to check out our story of how we upgraded our product to Vue 3 on our blog at suade.org

Contributing

# distribution build with minification
npm run bundle

# run unit tests
npm run test

NPM DownloadsLast 30 Days