Skip to content

Commit

Permalink
fix(controller): running-elephant#368 on select custom optionItem
Browse files Browse the repository at this point in the history
  • Loading branch information
xieliuduo committed Dec 16, 2021
1 parent 3ca5628 commit 90380f8
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 90380f8

Please sign in to comment.