MultipleTagsSelect.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <template>
  2. <b-form-tags
  3. v-bind="$attrs" v-on="$listeners"
  4. :value="value"
  5. no-outer-focus
  6. >
  7. <template v-slot="{ tags, disabled, addTag, removeTag }">
  8. <b-dropdown
  9. :text="buttonText" size="sm"
  10. variant="outline-secondary" class="d-block rounded-0"
  11. >
  12. <b-dropdown-item-button
  13. v-for="option in availableOptions" :key="option"
  14. @click="addTag(option)"
  15. >
  16. {{ option }}
  17. </b-dropdown-item-button>
  18. </b-dropdown>
  19. <ul v-if="tags.length > 0" class="list-inline d-inline-block">
  20. <li v-for="tag in tags" :key="tag" class="list-inline-item">
  21. <b-form-tag
  22. :title="tag" :disabled="disabled" pill
  23. @remove="removeTag(tag)"
  24. >
  25. {{ tag }}
  26. </b-form-tag>
  27. </li>
  28. </ul>
  29. </template>
  30. </b-form-tags>
  31. </template>
  32. <script>
  33. export default {
  34. name: 'MultipleTagsSelect',
  35. props: {
  36. value: { type: Array, required: true },
  37. options: { type: Array, required: true },
  38. buttonText: { type: String, required: true }
  39. },
  40. computed: {
  41. availableOptions () {
  42. return this.options.filter(opt => this.value.indexOf(opt) === -1)
  43. }
  44. }
  45. }
  46. </script>
  47. <style lang="scss" scoped>
  48. </style>