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

Max number of options

Open SVITY opened this issue 10 years ago • 4 comments

Hello! Could I set max number of selected options for multi select? Thanks!

SVITY avatar Nov 28 '16 10:11 SVITY

It would be nice to have it built in, but it is also easy to do by yourself:

For example:

let newOptions = this.state.currentOptions;

if (this.state.selected != null && this.state.selected.length === MAX) {
  newOptions = [];
}

return (
<Select
  multi
  value={this.state.selected}
  options={newOptions}/>
);

caiolopes avatar Mar 28 '17 01:03 caiolopes

@caiolopes That method doesn't quite work. Upon hitting MAX, the options already selected disappear ostensibly because the values in the array passed to the value prop are no longer founder in options.

mattlong avatar May 11 '18 20:05 mattlong

Please disregard, I had been passing in an array of strings, e.g. ["apple", "banana"] for the value property.

I was not aware I could also pass in [{label: "Apple", value: "apple"}, {label: "Banana", value: "banana"}]. Of course that is perfectly reasonable sense that's the format returned in onChange :)

mattlong avatar May 11 '18 21:05 mattlong

Hello -

In an effort to sustain the react-select project going forward, we're closing old issues / pull requests.

We understand this might be inconvenient but in the best interest of supporting the broader community we have to direct our limited efforts to maintain the latest version.

If you aren't using the latest version of react-select please consider upgrading to see if it resolves any issues you're having.

If you feel this issue / pull request is still relevant and you'd like us to review it, please leave a comment and we'll do our best to get back to you.

bladey avatar May 27 '20 06:05 bladey