Skip to content

Commit

Permalink
Merge pull request #378 from xieliuduo/dev-16.1
Browse files Browse the repository at this point in the history
fix(controller): #368 on select custom optionItem
  • Loading branch information
scottsut committed Dec 16, 2021
2 parents 5fe2de7 + 90380f8 commit 2e88c0a
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ export const CustomOptions: React.FC<CustomOptionsProps> = memo(

const handleRowStateUpdate = useCallback(
(row: FilterValueOption) => {
const oldRowIndex = rows.findIndex(r => r.index === row.index);
rows.splice(oldRowIndex, 1, row);
onChangeFilterOptions(rows.slice());
const newRows = [...rows];
const targetIndex = newRows.findIndex(r => r.index === row.index);
newRows.splice(targetIndex, 1, row);
onChangeFilterOptions(newRows);
},
[onChangeFilterOptions, rows],
);
Expand Down Expand Up @@ -107,11 +108,12 @@ export const CustomOptions: React.FC<CustomOptionsProps> = memo(
<a
href="#!"
style={{ color: record.isSelected ? 'red' : '' }}
onClick={() =>
handleRowStateUpdate(
Object.assign(record, { isSelected: !record.isSelected }),
)
}
onClick={() => {
handleRowStateUpdate({
...record,
isSelected: !record.isSelected,
});
}}
>
{record.isSelected ? '取消默认值' : '设为默认值'}
</a>
Expand Down

0 comments on commit 2e88c0a

Please sign in to comment.