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

[V2] How to get the group label in onChange #2417

Closed
s-dezign opened this issue Mar 5, 2018 · 4 comments
Closed

[V2] How to get the group label in onChange #2417

s-dezign opened this issue Mar 5, 2018 · 4 comments

Comments

@s-dezign
Copy link

s-dezign commented Mar 5, 2018

v2 is really great. One question ... How to get group label/object for selected option? for example in onChange method.

Thanks #59

@JedWatson JedWatson changed the title opts get group label [V2] How to get the group label in onChange Mar 6, 2018
@JedWatson
Copy link
Owner

The entire data structure for the selected option is passed to the onChange method, so the easiest way is to put it there yourself before passing the options array to Select.

i.e

const options = [
  { label: 'Group A', options: [
    { value: 'first', label: 'First', group: 'Group A' }
  ] },
  { label: 'Group B', options: [
    { value: 'second', label: 'Second', group: 'Group B' }
  ] }
];

<Select options={options} ... />

You could easily generate this at run-time... It adds a small amount of pre-processing to your options but I'm trying to keep the core feature set of v2 limited to things you can't easily do with the extension API.

@JedWatson JedWatson mentioned this issue Mar 6, 2018
@s-dezign
Copy link
Author

s-dezign commented Mar 6, 2018

@JedWatson thank you very much!

@sag1v
Copy link

sag1v commented Jan 17, 2019

@JedWatson Is it possible to select an entire group?
Like allowing a users to select all options of Group A with a single select instead of forcing them selecting all options of this group one by one

@keithbooher
Copy link

keithbooher commented Jan 30, 2019

Any options for styling group labels?

    const markup = '<h1><p>Cursive</p></h1>';
    const parser = new DOMParser()
    const el = parser.parseFromString(markup, "text/xml");
    console.log(el)

    let cursiveObject = { label: el, options: [] }

Id like the group labels to be bigger
Inserting as an element, shown above, throws an error.

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

No branches or pull requests

4 participants