react-select icon indicating copy to clipboard operation
react-select copied to clipboard

optgroups

Open kopancek opened this issue 11 years ago • 95 comments

Is there a way of having option groups, like the standard optgroup element in html select?

kopancek avatar Feb 06 '15 14:02 kopancek

I want to help with this future... i was thinking going with simple structure

var options = [{
            label: "Group 1",
            children: [{
                value: "one",
                lable: "One"
            }, {
                value: "two",
                lable: "Two"
            }];

is someone started to work on that?

piecyk avatar Mar 25 '15 17:03 piecyk

I also need this, immediately. Is there work in progress, or should I fork?

acthp avatar Mar 31 '15 03:03 acthp

+1

Venkatrao727 avatar Apr 02 '15 05:04 Venkatrao727

+1

Anyone working on this?

TSMMark avatar Apr 02 '15 16:04 TSMMark

I also would love this. Planning on switching from Selectize.js (which has optgroup support) to this, but would need this functionality first.

whather avatar Apr 15 '15 18:04 whather

+1

rick-li avatar Apr 27 '15 13:04 rick-li

+1

guillaumepiot avatar May 04 '15 01:05 guillaumepiot

We're accepting PRs, so don't feel bad if you beat @jossmac to it. It currently isn't on the hit list.

dcousens avatar May 07 '15 04:05 dcousens

I'm working almost exclusively on http://elemental-ui.com for the foreseeable future, so I won't be of much help I'm afraid. Incidentally I've implemented a dropdown over there that may be of interest using the following pattern:

var selectOptions = [
  { type: 'option', value: 'option', label: 'Option' },
  { type: 'option', value: 'another-option', label: 'Another option' },
  { type: 'option', value: 'something-else-here', label: 'Something else here' },
  { type: 'divider' },
  { type: 'label', label: 'Select label' },
  { type: 'option', value: 'separated-option', label: 'Separated option' },
];

More here: https://github.com/elementalui/elemental/blob/master/src/components/Dropdown.js

Ping @JedWatson for preferences on implementation details

jossmac avatar May 07 '15 05:05 jossmac

+1

rorykoehein avatar May 07 '15 14:05 rorykoehein

@JedWatson I'm currently working on this for a project. How would you like this implemented? The interface we need is a variation on the selectize structure, but I can handle that in a wrapper class if you prefer something different:

options: [
    {optgroup: 'Things', value: "thing1", label: "Thing 1" },
    {optgroup: 'Things', value: "thing2", label: "Thing 2" },
    {optgroup: 'Things', value: "thing3", label: "Thing 3" },
    {optgroup: 'Stuffs', value: "stuff1", label: "Stuff 1" },
    {optgroup: 'Piles', value: "pile1", label: "Pile 1" },
    {value: "pile1", label: "Pile 1" }
],
optgroups: [
    {position: 1, label: 'Things'},
    {position: 2: label: 'Stuffs'}
],

Options with an optgroup not in the optgroup set are ignored. Options without an optgroup are listed last.

zenjyn avatar Jun 15 '15 19:06 zenjyn

@zenjyn :+1: great if you working on public branch i can help with something ( would love to see this merged... and kill select2 at my project

what do you think about something like this ? then you can sort the whole options array by label (if we have values the render it as optgroup )

options: [
  {
    label: "Thing 1a",
    //value: "allThings1a" then in future we can also add selecting the whole group
    values: [
      {
        value: "thing1a", label: "Thing 1a"
      },
      {
        value: "thing2a", label: "Thing 2a" 
      }
    ]
  },
  {
    label: "Thing 2b",
    values: [
      {
        value: "thing1b", label: "Thing 1b"
      },
      {
        value: "thing2b", label: "Thing 2b" 
      }
    ]
  },
  {
    label: "Thing 3c",
    value: "thing3c"    
  }
];

piecyk avatar Jun 15 '15 19:06 piecyk

@piecyk I started with something like that on our end but determined that being able to add, remove, reorder the optgroups in their own array was slightly more flexible for our purposes. I'm still open to something more like your nested structure for the PR, however.

As far as group selecting goes, I wasn't planning on getting into that just yet, but we could make a group select flag then just enable a toggleGroup callback to the onClick event for optgroup divs. Thoughts?

zenjyn avatar Jun 16 '15 15:06 zenjyn

+1

grydstedt avatar Sep 10 '15 01:09 grydstedt

@zenjyn @piecyk any progress on a public branch? I'd be willing to help out too, I need this for a project very soon.

/cc @colbyr

banderson avatar Sep 23 '15 20:09 banderson

@banderson the optgroup issue for my project was pushed to the backlog almost immediately after I posted on here. I probably won't get to it unless it's still unimplemented by the time the task comes up again. For my project I believe it's on the roadmap 6 months out or so.

zenjyn avatar Sep 24 '15 00:09 zenjyn

+1

agrass avatar Oct 22 '15 21:10 agrass

+1

tineo avatar Oct 23 '15 17:10 tineo

:+1:

lanceschi avatar Nov 03 '15 13:11 lanceschi

Trying to kick this thing up again...

@piecyk - I like your proposed API, but I would rename values to children. I think it's a bit more obvious what the purpose is, and a bit easier to read (ie, easier to distinguish between the value and the children). Anyone else fine with that API? If we get some more feedback on that API, it will be easier to start in on it.

thataustin avatar Dec 09 '15 02:12 thataustin