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

Allow existing selected values

Open preinvent opened this issue 9 years ago • 4 comments

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.

preinvent avatar Mar 16 '16 04:03 preinvent

Any eyes on this?

preinvent avatar Apr 12 '16 16:04 preinvent

Exactly what I needed for this to be a good solution for me

mikeodell77 avatar Jun 23 '16 00:06 mikeodell77

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 });
        }
    }
}

ghalex avatar Dec 20 '16 11:12 ghalex

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)

fiatjaf avatar Dec 25 '16 17:12 fiatjaf