Skip to content

Commit edab4c8

Browse files
author
刘欢
committed
fix: correct preserved page calculation on pageSize change
1 parent a7784f5 commit edab4c8

3 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/Pagination.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ const Pagination: React.FC<PaginationProps> = (props) => {
197197
}
198198

199199
function changePageSize(size: number) {
200-
const preservedPage = Math.ceil((current * pageSize) / size);
200+
const preservedPage = Math.floor(((current - 1) * pageSize) / size) + 1;
201201
const newCurrent = calculatePage(size, pageSize, total);
202202
const recommendPage =
203203
newCurrent === 0 ? 1 : Math.min(preservedPage, newCurrent);

tests/simple.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe('simple Pagination', () => {
131131
const pageSize1 = container.querySelectorAll('.rc-select-item')[0];
132132
fireEvent.click(pageSize1);
133133
expect(onChange).toHaveBeenCalled();
134-
expect(onChange).toHaveBeenLastCalledWith(1, 10, 2);
134+
expect(onChange).toHaveBeenLastCalledWith(1, 10, 1);
135135
});
136136

137137
it('should support keyboard event', () => {

tests/sizer.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('Pagination with sizer', () => {
6767
const pageSize1 = container.querySelectorAll('.rc-select-item')[0];
6868
fireEvent.click(pageSize1);
6969
expect(onChange).toHaveBeenCalled();
70-
expect(onChange).toHaveBeenLastCalledWith(1, 10, 2);
70+
expect(onChange).toHaveBeenLastCalledWith(1, 10, 1);
7171
});
7272

7373
// https://github.com/ant-design/ant-design/issues/26580

0 commit comments

Comments
 (0)