shentao / vue-multiselect

Universal select/multiselect/tagging component for Vue.js
https://vue-multiselect.js.org/
MIT License
6.66k stars 989 forks source link

Selected state in thje #1629

Open TrendyTim opened 1 year ago

TrendyTim commented 1 year ago

I was trying to easily convey selected state with the show-labels set to false, and was surprised there was no easy way to get the selected state (without manually managing it which is a bit hacky).

So I modified the .min.js version (using it in a vanilla html page) to add the isSelected: t.isSelected(e) to the options slot and i was able to do this in the slot

  <span class="checkbox-label" slot="option" slot-scope="scope">
      <input type="checkbox" :checked="scope.isSelected" @focus.prevent :key="scope.option.value"/>
      {{ scope.option.text }}
    </span>

And it seems to work perfectly, unless someone knows something I don't about performance.

I imagine it's the equivalent of this (as search slot param in the min.js references t.search so i assume isSelected would transfer like that)

 <slot name="option" :option="option" :search="search"  :isSelected="isSelected(option)" :index="index">

Also even a multipleShowCheck property that would automatically show the checkbox without even needing to use the slot would be awesome as well, and simple to add using the same kind of logic.

akki-jat commented 1 year ago

@TrendyTim Please provide repo link for your usecase.