-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
optgroups #59
Comments
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? |
I also need this, immediately. Is there work in progress, or should I fork? |
+1 |
+1 Anyone working on this? |
I also would love this. Planning on switching from Selectize.js (which has optgroup support) to this, but would need this functionality first. |
+1 |
1 similar comment
+1 |
We're accepting PRs, so don't feel bad if you beat @jossmac to it. It currently isn't on the hit list. |
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:
More here: https://github.com/elementalui/elemental/blob/master/src/components/Dropdown.js Ping @JedWatson for preferences on implementation details |
+1 |
@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 with an optgroup not in the optgroup set are ignored. Options without an optgroup are listed last. |
@zenjyn 👍 great if you working on public branch i can help with something ( would love to see this merged... and what do you think about something like this ? then you can sort the whole
|
@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? |
+1 |
@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. |
+1 |
2 similar comments
+1 |
👍 |
Trying to kick this thing up again... @piecyk - I like your proposed API, but I would rename |
@thataustin i agree the for now we can make simple crazy and naive wrapper, but should work as expected ;) const MyOptions = [
{
text: "Group 1",
children: [{
id: "one1",
text: "One1"
}, {
id: "two2",
text: "Two2"
}]
},{
text: "Group 2",
children: [{
id: "one2",
text: "One2"
}, {
id: "two2",
text: "Two22"
}]
}
];
function option(value, label, render, disabled = false) {
return {value, label, render, disabled};
}
const transformOptions = options => _.reduce(options, (res, el) => {
const parent = option(el.text, el.text, (<strong>{el.text}</strong>), true);
const children = _.map(el.children, child => _.assign(
{}, option(child.id, child.text, (<span style={{paddingLeft: 10}}>{child.text}</span>)), {parent: el.text}
));
return res.concat(parent).concat(children);
}, []);
const SelectGroups = React.createClass({
getInitialState() {
return {
value: this.props.value,
options: transformOptions(this.props.options)
};
},
optionRenderer(option) {
return option.render;
},
onChange(value) {
this.setState({value});
this.props.onChange(value);
},
filterOptions(options, term, currentValues) {
if (term === this.prevTerm) {
return this.prevOptions;
} else {
const almostReadyOptions = this.props.filterOptions ? this.props.filterOptions(options, term, currentValues)
// very naive filter, maybe ref form react-select and re-use the filterOptions ;)
: _.filter(options, o => o.parent ? _.includes(o.label.toLowerCase(), term.toLowerCase()) : true);
const optionsGroupByParent = _.groupBy(almostReadyOptions, 'parent');
// filter empty parents
const readyOptions = _.filter(almostReadyOptions,
option => option.parent ? option : _.size(optionsGroupByParent[option.value]) > 0);
this.prevTerm = term;
this.prevOptions = readyOptions;
return readyOptions;
}
},
render() {
return (
<Select
{...this.props}
value={this.state.value}
onChange={this.onChange}
optionRenderer={this.optionRenderer}
options={this.state.options}
filterOptions={this.filterOptions}
/>
);
}
});
// use it
//<SelectGroups
// options={MyOptions}
// onChange={val => console.log(val)}
///> |
Guys, i have a workaround:
Then you have to just push disabled values into
|
If we only wan to implement "optgroup" on top of "option", we can do something like this. It works for me.
|
@FrankRenyu it does not solve the problem with scrolling-off from the top as far as I understand ? |
+1 |
1 similar comment
+1 |
+1 |
1 similar comment
+1 |
unsubscribes |
…ld-trigger-close-menu Trigger closeMenu when isOpen changes from true to false
+1 |
2 similar comments
+1 |
+1 |
please stop (spam-)posting +1, just react with the thumbs up! |
+$50 |
+1 |
2 similar comments
+1 |
+1 |
I am really happy to say that groups are implemented in my new Everyone who has +1'd this will be happy to know this was one of the first things we implemented in the new version, and I'm quite happy with how they turned out. v2 is currently in alpha: see #2208 and the PR #2289 If you want an early preview, it's available here: https://deploy-preview-2289--react-select.netlify.com Expect it to hit final release sometime towards the end of February. Now, with great relief, I'm going to close this issue 🙂 |
@JedWatson brilliant thanks! Is there a lot of API changes in v2? Do you expect easy migrations or will it be a bit involved? |
I'm not sure yet - I need to finalise the new API before I can know, and then I'll publish an upgrade guide. Depends on how much you've customised it. I'm removing a lot of the edge-case props in favour of a more powerful architecture, but I'll try to make the upgrade as simple as possible. |
An end to the But seriously, I think everyone will be stoked with v2 -- we've really sweated the details. |
v2 is really great. One question ... How to get group label/object for selected option? for example in onChange method. Thanks |
Answer in #2417 |
Is there a way of having option groups, like the standard optgroup element in html select?
The text was updated successfully, but these errors were encountered: