mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 22:36:31 +08:00
sort
This commit is contained in:
parent
660ebbd58f
commit
c8d5243b97
@ -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;
|
||||
}),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user