This commit is contained in:
yoyo837 2019-06-28 10:26:55 +08:00
parent 660ebbd58f
commit c8d5243b97

View File

@ -136,9 +136,22 @@ class CheckboxGroup extends React.Component<CheckboxGroupProps, CheckboxGroupSta
}
const onChange = this.props.onChange;
if (onChange) {
const values = value.filter(val => registeredValues.indexOf(val) !== -1);
const options = this.getOptions();
onChange(options.map(opt => opt.value).filter(val => values.includes(val)));
onChange(
value
.filter(val => registeredValues.indexOf(val) !== -1)
.sort((a, b) => {
const indexA = options.findIndex(opt => opt.value === a);
const indexB = options.findIndex(opt => opt.value === b);
if (indexA > indexB) {
return 1;
}
if (indexA < indexB) {
return -1;
}
return 0;
}),
);
}
};