From ce9995acdc1474de6dcb691041fd7480caede848 Mon Sep 17 00:00:00 2001 From: maxin <48519459+nnmax@users.noreply.github.com> Date: Wed, 25 May 2022 14:19:59 +0800 Subject: [PATCH] fix(table): fix onChange calls twice (#2042) Co-authored-by: maxin --- src/table/Title.tsx | 22 ++++++++++----------- src/table/demos/sorting/Sorting.stories.tsx | 10 +++++++++- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/table/Title.tsx b/src/table/Title.tsx index 48c16cda6d..b787dac81f 100644 --- a/src/table/Title.tsx +++ b/src/table/Title.tsx @@ -25,19 +25,19 @@ const Title = (props: TitleProps): React.ReactElement = const nextSortOrder = getNextSortDirection(sortDirections, sortOrder ?? null); const changedSorterState: SortState = sorterState ? { - ...sorterState, - sortOrder: nextSortOrder, - } + ...sorterState, + sortOrder: nextSortOrder, + } : { - sortOrder: nextSortOrder, - column, - isControlled: 'sortOrder' in column, - key: columnKey, - sortDirections, - sortPriorityOrder, - }; + sortOrder: nextSortOrder, + column, + isControlled: 'sortOrder' in column, + key: columnKey, + sortDirections, + sortPriorityOrder, + }; - onTriggerStateUpdate({ sorterState: updateSorterStates(changedSorterState) }); + updateSorterStates(changedSorterState); }; return ( diff --git a/src/table/demos/sorting/Sorting.stories.tsx b/src/table/demos/sorting/Sorting.stories.tsx index 9d54f2b850..937b793cdd 100644 --- a/src/table/demos/sorting/Sorting.stories.tsx +++ b/src/table/demos/sorting/Sorting.stories.tsx @@ -39,7 +39,15 @@ export const Sorting = () => { title: 'Address', }, ]; - return pagination={false} dataSource={genDataSource()} columns={columns} rowKey="id" />; + return ( + + pagination={false} + onChange={action('handleTableChange')} + dataSource={genDataSource()} + columns={columns} + rowKey="id" + /> + ); }; // ----------------------- Sorting -----------------------//