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.

[QSelect] Group options inside select element with optgroup

See original GitHub issue

In basic HTML <select> elements, options can be grouped using the HTML <optgroup> element. I think this would be a great addition to Quasar as with the current QSelect component, it’s only possible to have 1 level of options and thus it’s not possible to structure the options.

Having grouped options helps users to find their options faster and makes using larger <select> elements easier.

Describe the solution you’d like I’d like to have the possibility to group options in optgroups so that options could be easily organized and structured inside a select element. (E.g. categories/subcategories, organizing a country list based on continents, etc.)

Also, it should be possible to use the same attributes that the HTML<optgroup> element provides:

  • disabled If this Boolean attribute is set, none of the items in this option group is selectable. Often browsers grey out such control and it won’t receive any browsing events, like mouse clicks or focus-related ones.
  • label The name of the group of options, which the browser can use when labeling the options in the user interface. This attribute is mandatory if this element is used.

Optgroups could be handled as follows:

export default {
  data () {
    return {
      model: null,
      options: [
      	'Some', 'Options', 'Outside', 'Of', 'Any', 'Group',
      	{
      		label: "Group 1",
      		options: {
      			'Option 1.1'
      		}
      	},
      	{
      		label: "Group 2",
      		options: {
      			'Option 2.1', 'Option 2.2'
      		}
      	},
      	{
      		label: "Group 3",
      		disabled: true,
      		options: {
      			'Option 3.1', 'Option 3.2', 'Option 3.3'
      		}
      	},
      	'Some', 'More', 'Options'
      ]
    }
  }
}

Additional context More info and example of basic HTML <optgroup> element: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/optgroup

Screenshot 2019-11-28 at 11 08 47

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:21
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
piperonecommented, Aug 28, 2020

Since <optgroup> is a widely used HTML element and a convenient way of grouping related select-values together, support for nested structures in q-select’s options-prop would be really nice. I was a little surprised to see that this wasn’t already a feature, but I guess even the best frameworks have room for improvement 😃

8reactions
hawkeye64commented, Jan 3, 2020

@pjar You can try something like this: https://codepen.io/Hawkeye64/pen/xxbXajq

Read more comments on GitHub >

github_iconTop Results From Across the Web

Easy way to quick select a whole optgroup in select box
If you want to select the entire group based on the user selecting the group, do the following: $("optgroup. className"). select(function(e) { $(this)....
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 >
Select | Quasar Framework
The QSelect Vue component has two types of selection - single or multiple. This component opens up a menu for the selection list...
Read more >
<optgroup>: The Option Group element - MDN Web Docs
The name of the group of options, which the browser can use when labeling the options in the user interface. This attribute is...
Read more >
Q-select with nested or grouped data and filtering?
I need to have a q-select field, but with option groups to allow the ... I couldn't see any way of using nested...
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