Skip to content
Snippets Groups Projects
DropdownMenuItem.vue 1.18 KiB
Newer Older
Florent Lavelle's avatar
dev
Florent Lavelle committed
<template>
  <Multiselect
Timothee P's avatar
Timothee P committed
    v-model="selection"
    :options="options"
    :allow-empty="true"
    track-by="label"
    label="label"
    :reset-after="false"
    select-label=""
    selected-label=""
    deselect-label=""
    :searchable="false"
    :placeholder="placeholder"
    :clear-on-select="false"
    :preserve-search="true"
    @select="select"
    @close="close"
Florent Lavelle's avatar
dev
Florent Lavelle committed
</template>

<script>
import Multiselect from 'vue-multiselect';

export default {
  name: 'DropdownMenuItem',

Timothee P's avatar
Timothee P committed
  components: {
    Multiselect
  },
Florent Lavelle's avatar
dev
Florent Lavelle committed

Timothee P's avatar
Timothee P committed
  props: {
    placeholder: {
      type: String,
      default: 'Sélectionnez une valeur'
    },
    options: {
      type: Array,
      default: () => {
        return [];
      }
    }
  },
Florent Lavelle's avatar
dev
Florent Lavelle committed

  data() {
    return {
      selection: null,
Timothee P's avatar
Timothee P committed
    };
Florent Lavelle's avatar
dev
Florent Lavelle committed
  },

Timothee P's avatar
Timothee P committed
  watch: {
    selection: {
      deep: true,
      handler(newValue) {
        if (!newValue) {
          this.selection = this.options[0];
          this.$emit('filter', this.selection);
        }
      }
    }
  },
Timothee P's avatar
Timothee P committed
  created() {
    this.selection = this.options[0];
  },
Florent Lavelle's avatar
dev
Florent Lavelle committed
  methods: {
    select(e) {
      this.$emit('filter', e);
Florent Lavelle's avatar
dev
Florent Lavelle committed
    },
    close() {
      this.$emit('close', this.selection);
    }
  }
Timothee P's avatar
Timothee P committed
};
Florent Lavelle's avatar
dev
Florent Lavelle committed
</script>