Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How about optgroup? #342

Open
SoldierCorp opened this issue Oct 14, 2017 · 42 comments
Open

How about optgroup? #342

SoldierCorp opened this issue Oct 14, 2017 · 42 comments

Comments

@SoldierCorp
Copy link

No description provided.

@sagalbot
Copy link
Owner

Optgroup Support

@kramer65
Copy link

@sagalbot - We would really like to use optgroup in vue-select. Would you be willing to accept a donation to add support for optgroup to this library? We could maybe spare say $250?

@joaquinwojcik
Copy link

Any updates on this?

@Sjoerd82
Copy link

+1 for optgroups!

1 similar comment
@Kyii
Copy link

Kyii commented Oct 23, 2019

+1 for optgroups!

@arggasasao
Copy link

+1 for optgroups

2 similar comments
@hmshafeeq
Copy link

+1 for optgroups

@niqitosiq
Copy link

+1 for optgroups

@arggasasao
Copy link

Hi! Here my soluction using Vue slots.

<select @change="onChange($event, index)">
  <option selected>seleccionar</option>
  <slot v-for="(item, i) in topItems">
    <optgroup :key="i" v-if="item.sections" :label="item.name">
      <option v-for="(subItem, i) in item.sections.section" :key="i" :value="subItem.url">{{ sub.name }}</option>
    </optgroup>
    <option :key="i" v-if="!item.sections" :value="item.url"> {{ item.name }} </option>
  </slot>
</select>

@ezekielchow
Copy link

+1 for optgroups

@SimonFricker
Copy link

+1

3 similar comments
@Fozar
Copy link

Fozar commented Jun 20, 2020

+1

@komenixx
Copy link

+1

@subtronic
Copy link

+1

@smholsen
Copy link

+1 Would be awesome

@subtronic
Copy link

+1

@jiagbrody
Copy link

+1 please...

@sciracioglu
Copy link

+1

@Lug-As
Copy link

Lug-As commented Feb 16, 2021

+1 for optgroup, please

@mewlabs
Copy link

mewlabs commented Mar 3, 2021

please, we all need optgroups

@kovalevadim
Copy link

very much needed optgroup

@DanielTQI
Copy link

please optgroup 😢

@dev-santosh
Copy link

+1

@ShetlandJ
Copy link

+1

1 similar comment
@al-hz
Copy link

al-hz commented Nov 24, 2021

+1

@YajanaRao
Copy link

+1

11 similar comments
@cami-espinozaq
Copy link

+1

@kudinov-1
Copy link

+1

@willimaese
Copy link

+1

@hfelipeoliveira
Copy link

+1

@mkEmperor
Copy link

+1

@theneonwhale
Copy link

+1

@yasser-jam
Copy link

+1

@Dirk-Kokx
Copy link

+1

@Rolaxxx3
Copy link

+1

@effetmonstre
Copy link

+1

@mau4gdp
Copy link

mau4gdp commented Dec 12, 2022

+1

@phimaur
Copy link

phimaur commented Dec 27, 2022

`

<script> function selectableOption( option ) { return option.heading != true; } </script>
           <VueSelect
                multiple
              :options="menuTags"
              :selectable="selectableOption"
              placeholder="Choose multiple values.."
          >
              <template #option="{ label, tag, heading }">
                  <h5 v-if="heading" class="mb-0">{{ label }}</h5>
                  <span v-else class="ms-3">{{ label }}</span>
              </template>
          </VueSelect>

`

Here is a possible solution which looks similar as the optgroup.
I set the options array with objects. The group is identified by a heading boolean.

  • when heading is set, selectable prop makes it unselectable
  • the option slot set a different rendering with a small margin when the heading is not set.

@rlidev
Copy link

rlidev commented Jan 26, 2023

+1

@warmfire540
Copy link

another "workaround" until implemented, however v-select and v-overflow-btn can take an item w/ property header - and it shows semi grouped... or at least what I want..

here's a lone site which hinted at the property (which I missed in the v-select docs) but also works for overflow (not mentioned in docs): https://ourcodeworld.com/articles/read/1561/whats-the-equivalent-to-optgroup-selects-in-vuetify

image

@iwasherefirst2
Copy link

iwasherefirst2 commented Nov 23, 2023

`

<script> function selectableOption( option ) { return option.heading != true; } </script>
           <VueSelect
                multiple
              :options="menuTags"
              :selectable="selectableOption"
              placeholder="Choose multiple values.."
          >
              <template #option="{ label, tag, heading }">
                  <h5 v-if="heading" class="mb-0">{{ label }}</h5>
                  <span v-else class="ms-3">{{ label }}</span>
              </template>
          </VueSelect>

`

Here is a possible solution which looks similar as the optgroup. I set the options array with objects. The group is identified by a heading boolean.

* when heading is set, selectable prop makes it unselectable

* the option slot set a different rendering with a small margin when the heading is not set.

Thank you! Works with Vue3.

So for everyone who doesn't understand, you have to add the headings flat within your options (no grouping inside your options array), so its like this:

options = [
   { label: "Heading 1 ", heading: true} , 
   { label:  "Option A", id: 4, heading: false},  
   { label:  "Option B", id: 2, heading: false},
   { label: "Heading 2 ", heading: true} , 
   { label:  "Option C", id: 8, heading: false},  
   { label:  "Option D", id: 9, heading: false},
]

@jackmcdade
Copy link

@warmfire540 thank you so much for this, you saved my bacon today! I'd like to share it with you as my token of gratitude 🥓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests