react-select-popover
react-select-popover copied to clipboard
Allow existing selected values
In some cases the component may need to be populated with existing values. if we send in an array of label/value pairs to props.selectedOptions and initialize the state from that, we can easily support this.
Any eyes on this?
Exactly what I needed for this to be a good solution for me
I have extend the class to be able to add selectedValues:
class ExtendSelectPopover extends SelectPopover {
constructor(props) {
super(props);
this.state = {
focus: "out",
searchTerm: "",
selectedValues: this.props.selectedValues || []
}
}
componentWillReceiveProps(nextProps) {
if (nextProps.selectedValues) {
this.setState({ selectedValues: nextProps.selectedValues });
}
}
}
My fork: https://github.com/fiatjaf/react-select-popover, has support for this. It accepts a value prop that may be a simple array with the selected values referencing those in options (remember that options is an array of objects with the keys .value and .label). See prop types.
(I actually merged this same PR here, but ended up modifying the interface because I found some bugs and some inefficiencies).
(To install: npm install --save fiatjaf/react-select-popover)