question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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)?

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
janoshcommented, 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.

0reactions
lysdexic-audiocommented, Nov 7, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

<optgroup>: The Option Group element - MDN Web Docs
The <optgroup> HTML element creates a grouping of options within a <select> element. Try it. HTML Demo: <optgroup>. Reset. HTML CSS
Read more >
HTML optgroup tag - W3Schools
The <optgroup> tag is used to group related options in a <select> element (drop-down list). If you have a long list of options,...
Read more >
H85: Using optgroup to group option elements inside a select
In HTML, the select element is used to create both multi-select lists and combo boxes. The various allowed options are each indicated with...
Read more >
Options Group > Options Group Home
See why Options Group is the premier global recruiting firm for financial services with executive search talent planning, acquisition and retention.
Read more >
HTML: <optgroup> tag - TechOnTheNet
The HTML <optgroup> tag creates a group of options within a dropdown list of values in the <select> control. These dropdown values are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found