Skip to content

Commit

Permalink
fix: The current change of pagination triggers onChange (ant-design#3…
Browse files Browse the repository at this point in the history
…3411)

* fix: table pagination onChange error (ant-design#33374)

* test: add  test case for this (ant-design#33374)
  • Loading branch information
2724635499 authored Dec 27, 2021
1 parent 4f4e2f8 commit 629cacc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions components/table/__tests__/Table.pagination.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,4 +553,30 @@ describe('Table.pagination', () => {
'ant-pagination ant-table-pagination ant-table-pagination-right pagination',
);
});

// https://github.com/ant-design/ant-design/issues/33374
// https://codesandbox.io/s/festive-edison-6uq3e?file=/src/App.js
it('should called onChange when page number is changed by change of total ', () => {
const onChange = jest.fn();
const wrapper = mount(
createTable({
pagination: {
current: 2,
pageSize: 3,
total: 4,
onChange,
},
}),
);
wrapper.setProps({
dataSource: data.slice(0, 3),
pagination: {
current: 2,
pageSize: 3,
total: 3,
onChange,
},
});
expect(onChange).toHaveBeenCalledWith(1, 3);
});
});
1 change: 1 addition & 0 deletions components/table/hooks/usePagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default function usePagination(
if (mergedPagination.current! > maxPage) {
// Prevent a maximum page count of 0
mergedPagination.current = maxPage || 1;
mergedPagination.onChange?.(mergedPagination.current, mergedPagination?.pageSize!);
}

const refreshPagination = (current?: number, pageSize?: number) => {
Expand Down

0 comments on commit 629cacc

Please sign in to comment.