This commit is contained in:
2betop 2020-07-13 12:04:59 +08:00
commit 63d97bc511
1 changed files with 26 additions and 5 deletions

View File

@ -400,16 +400,37 @@ export class Select extends React.Component<SelectProps, SelectState> {
loadOptions && loadOptions('');
}
componentWillReceiveProps(nextProps: SelectProps) {
componentDidUpdate(prevProps: SelectProps) {
const props = this.props;
let fn:() => void = noop;
if (
props.value !== nextProps.value ||
JSON.stringify(props.options) !== JSON.stringify(nextProps.options)
props.value !== prevProps.value ||
JSON.stringify(props.options) !== JSON.stringify(prevProps.options)
) {
let selection: Array<Option>;
if (
(
!prevProps.options
|| !prevProps.options.length
)
&& props.options.length
) {
const {selection: stateSelection} = this.state;
const {multiple, defaultCheckAll, options, onChange, simpleValue} = props;
if (multiple && defaultCheckAll && options.length) {
selection = union(options, stateSelection);
fn = () => onChange(simpleValue ? selection.map(item => item.value) : selection);
} else {
selection = value2array(props.value, props);
}
} else {
selection = value2array(props.value, props);
}
this.setState({
selection: value2array(nextProps.value, nextProps)
});
selection: selection
}, fn);
}
}