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

Option grouping #135

Open
lysdexic-audio opened this issue Oct 17, 2022 · 8 comments
Open

Option grouping #135

lysdexic-audio opened this issue Oct 17, 2022 · 8 comments
Labels
discussion Gathering feedback on open questions enhancement New feature or request help wanted Extra attention is needed UX User experience

Comments

@lysdexic-audio
Copy link

lysdexic-audio commented Oct 17, 2022

This is a perfect little component. In some cases where there are many fields it would be nice if a single Multiselect could contain several options, perhaps like this:

<script>
  import MultiSelect from 'svelte-multiselect'

  const genreTags = [`Rock`, `Electronic`, `Opera`]
  const keyTags = [`C`, `D`, `E`, `F`, `G`, `A`, `B`]
  const scaleTags = [`Major`, `Minor`]

  let selectedTags = []
</script>

<MultiSelect
  bind:selectedTags
  options={[genreTags, keyTags, scaleTags]}
  maxSelect={[null, 1, 1]}
  required={[true, true, false]}
  placeholder="Select Tags"
/>

I need this in my app - are you open to an PR (if this isn't already supported)?

@janosh janosh changed the title FR: Multiple options inside one Multiselect component Multiple options inside one multi-select component Oct 17, 2022
@janosh janosh added question Further information is requested awaiting user Needs more information from OP. labels Oct 17, 2022
@janosh
Copy link
Owner

janosh commented Oct 17, 2022

Why do they need to be in 1 multi-select? And what would the UI for that look like? How would you have 3 dropdowns in one component? Maybe you can elaborate on your use case.

@lysdexic-audio
Copy link
Author

Hey thanks for the quick reply - I'm referring to a binding to the HTML optgroup element

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/optgroup

@janosh
Copy link
Owner

janosh commented Oct 17, 2022

Ah, you're talking about grouping of options. Yes, I'd be happy to take a PR for that.

I should say upfront though, this sounds like a fair amount of work if you want to do it right. Your example suggests that you don't just want option grouping in the UI but for the groups to have separate maxSelect and required attributes. That raises some questions:

  1. What should happen when users create new options (when allowUserOptions=true)? Which group should the new option be added to?
  2. Does each group have separate defaultDisabledTitle?

@janosh janosh changed the title Multiple options inside one multi-select component Option grouping Oct 17, 2022
@janosh janosh added enhancement New feature or request help wanted Extra attention is needed discussion Gathering feedback on open questions and removed question Further information is requested awaiting user Needs more information from OP. labels Oct 17, 2022
@lysdexic-audio
Copy link
Author

lysdexic-audio commented Oct 17, 2022

Yes, exactly - not quite just the grouping of options, since the intention is to group other attributes from Multiselect like maxSelect....

  1. allowUserOptions could be either disabled for this feature or treated in the same way ie: boolean | boolean[]. When more than one option allows user options the optgroup label could be required for input - for example, input text like: genre=Electronic for something like the following:
<script>
  import MultiSelect from 'svelte-multiselect'

  const genreTags = {label: "Genre", options: [`Rock`, `Electronic`, `Opera`]}
  const keyTags = {label: "Key", options: [`C`, `D`, `E`, `F`, `G`, `A`, `B`]}
  const scaleTags = {label: "Scale", options: [`Major`, `Minor`]}

  let selectedTags = []
</script>

<MultiSelect
  bind:selected
  options={[genreTags, keyTags, scaleTags]}
  maxSelect={[null, 1, 1]}
  required={[true, true, false] }
  allowUserOptions={ [true, false, true] } 
  placeholder="Select Tags"
/>
  1. I'm not sure I can see a strong use case for this

@janosh
Copy link
Owner

janosh commented Oct 17, 2022

  1. Let's go with disabling allowUserOptions entirely when options are grouped for now.
  2. Fair point. We'll stick with a single defaultDisabledTitle for all groups.

As I said, happy to take a PR for this. Though the default way to group options should be an object of arrays imo:

<script>
  import MultiSelect from 'svelte-multiselect'

  const options: Record<string, Option[]> = {
    Genre: [`Rock`, `Electronic`, `Opera`],
    Key: [`C`, `D`, `E`, `F`, `G`, `A`, `B`],
    Scale: [`Major`, `Minor`],
  }

  let selected = []
</script>

<MultiSelect
  bind:selected
  {options}
  maxSelect={[null, 1, 1]}
  required={[true, true, false]}
  allowUserOptions={[true, false, true]}
  placeholder="Select Tags"
/>

We can expand to

options: Record<string, { label: string, options: Option[], required: boolean, maxSelect: number | null }>

later.

@janosh janosh added the UX User experience label Oct 25, 2022
@lysdexic-audio
Copy link
Author

Sorry @janosh bit too pressured at work to get onto doing this properly - working around it for now. Anyone else wants to jump in please do

@MaxJW
Copy link

MaxJW commented Oct 4, 2023

Hi, just wondered if there was any update on this, or if there is a branch I could take a look at to help towards implementing this?

@janosh
Copy link
Owner

janosh commented Oct 4, 2023

@MaxJW No progress here yet but PRs still welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Gathering feedback on open questions enhancement New feature or request help wanted Extra attention is needed UX User experience
Projects
None yet
Development

No branches or pull requests

3 participants