Select.Async multi doesn't work
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>
);
}
}
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}
/>
You can also check this pr #1612
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, key changing forces React to replace the element in DOM tree, so it leads to focus losing.
@dizel3d Yep, understood. All the more reason to hope for a real fix. :-)
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: [] };
}
is this fixed yet?
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).
This is still broken in 2.1.1. Selecting any option makes it impossible to see or select further options.
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.
I managed to get it working by defining formatOptionLabel, getOptionValue and getOptionLabel
@DarkLegend can you send a fiddle or codesandbox... I couldnt get it working with latest release
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)} />
Hi all! I'd appreciate a Codesandbox link to replicate this issue so I can investigate, thank you.
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.