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

Select.Async multi doesn't work

Open dizel3d opened this issue 9 years ago • 15 comments

2017-06-02_12-25-09 Recommended plunker doesn't work, so I put the code here below.

class Foobar extends React.Component<null, {value: string[]}> {
    constructor(props) {
        super(props);
        this.state = {
            value: []
        };
    }

    options = [
        { value: 'one', label: 'One' },
        { value: 'two', label: 'Two' }
    ];

    loadOptions = (input, callback) => {
        callback(null, {options: this.options});
    };

    onChange = (options) => {
        this.setState({
            value: options.map(x => x.value)
        });
    };

    render() {
        console.log('state', this.state.value);
        return (
            <div>
                <p><b>Select</b> works well</p>
                <Select
                    multi
                    value={this.state.value}
                    options={this.options}
                    onChange={this.onChange}
                />
                <p>but <b>Select.Async</b> breaks as soon as you select an option</p>
                <Select.Async
                    multi
                    value={this.state.value}
                    loadOptions={this.loadOptions}
                    onChange={this.onChange}
                />
            </div>
        );
    }
}

dizel3d avatar Jun 02 '17 09:06 dizel3d

Adding of key={this.state.value.length} is a workaround.

<Select.Async
    multi
    key={this.state.value.length}
    value={this.state.value}
    loadOptions={this.loadOptions}
    onChange={this.onChange}
/>

dizel3d avatar Jun 02 '17 09:06 dizel3d

You can also check this pr #1612

dekelb avatar Jun 04 '17 10:06 dekelb

Thanks @dizel3d for reporting this and workaround. I am also getting bit by this issue trying to use react-select for the filter editor in Tad. The proposed workaround of setting key does help, but then the overall select control seems to lose keyboard focus each time a value is added to the selected set.

antonycourtney avatar Jun 27 '17 14:06 antonycourtney

@antonycourtney, key changing forces React to replace the element in DOM tree, so it leads to focus losing.

dizel3d avatar Jun 27 '17 14:06 dizel3d

@dizel3d Yep, understood. All the more reason to hope for a real fix. :-)

antonycourtney avatar Jun 27 '17 15:06 antonycourtney

Hi same problem here, here's my workaround with 1.0.0-rc.3: I don't use Async but regular Select have a "loading" boolean in the state and map it to the isLoading and disabled attributes. Also adjust the placeholder.

<Select
    isLoading={this.state.errortypeLoading}
    disabled={this.state.errortypeLoading}
    value={this.state.errortype} multi={true}
    options={this.state.errortypeOptions}
    onChange={this.handleSelectChanged.bind(this,'errortype')}
    placeholder={this.state.errortypeLoading ? "Loading..." : "Error type"} 
/>

in the in the getInitialState, fetch the values :

    getInitialState() {
        let component = this;
        fetch('api/TestData/Qualif/GetErrorTypes', {
            method: 'get',
            headers: {
                'Accept': 'application/json',
            }
        }).then(function(response) { 
            return response.json();
        }).then(function(j) {
            console.log(j); 
            component.setState( { errortypeLoading: false, errortypeOptions: j });
        }).catch(function(error) {
            console.log('error '+ error); 
        });

        return { errortype: this.props.filter.errortype, errortypeLoading: true, errortypeOptions: [] };
    }

vlaquest avatar Jun 28 '17 13:06 vlaquest

is this fixed yet?

timini avatar Jul 31 '18 14:07 timini

Async with multiple selection seems to work fine in 2.0 (which is a total rewrite and probably requires changing your code that uses the react-select components, but does seem to fix the problem).

nbudin avatar Jul 31 '18 15:07 nbudin

This is still broken in 2.1.1. Selecting any option makes it impossible to see or select further options.

cmbasnett avatar Nov 06 '18 05:11 cmbasnett

Having the same issue as @cmbasnett with 2.1.1 The first value selects fine, but afterwards the options returned by loadOptions are never shown anymore.

DarkLegend avatar Nov 17 '18 04:11 DarkLegend

I managed to get it working by defining formatOptionLabel, getOptionValue and getOptionLabel

DarkLegend avatar Nov 19 '18 03:11 DarkLegend

@DarkLegend can you send a fiddle or codesandbox... I couldnt get it working with latest release

hakancunier avatar Feb 21 '19 21:02 hakancunier

it is fixed please use this. import AsyncSelect from "react-select/lib/Async"; <AsyncSelect getOptionLabel={({ name }) => name} getOptionValue={({ id }) => id} loadOptions={this.promiseOption} isMulti onChange={option => this._handleChangeInSelect(option)} />

AtulVerma12 avatar Jul 04 '19 18:07 AtulVerma12

Hi all! I'd appreciate a Codesandbox link to replicate this issue so I can investigate, thank you.

bladey avatar Jun 17 '20 03:06 bladey

This issue will now be closed due to inactivity. If anyone can provide a Codesandbox example, please let me know and the issue will be re-opened.

bladey avatar Jun 29 '20 04:06 bladey