From 39333253d9f4af8e266433d4d8278e8f357bd620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Tue, 27 Oct 2020 23:02:52 +0800 Subject: [PATCH] fix: Not merge additional data (#27412) --- .../table/__tests__/Table.pagination.test.js | 34 ++++++++++++++++++- components/table/hooks/usePagination.ts | 6 ++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/components/table/__tests__/Table.pagination.test.js b/components/table/__tests__/Table.pagination.test.js index 8649d61849..c112a18d91 100644 --- a/components/table/__tests__/Table.pagination.test.js +++ b/components/table/__tests__/Table.pagination.test.js @@ -39,7 +39,7 @@ describe('Table.pagination', () => { it('not crash when pageSize is undefined', () => { expect(() => { - mount(createTable({ pagination: { pageSIze: undefined } })); + mount(createTable({ pagination: { pageSize: undefined } })); }).not.toThrow(); }); @@ -409,4 +409,36 @@ describe('Table.pagination', () => { }); expect(wrapper.find('.ant-pagination')).toHaveLength(2); }); + + it('showTotal should hide when removed', () => { + const Demo = () => { + const [p, setP] = React.useState({ + showTotal: t => `>${t}<`, + total: 200, + current: 1, + pageSize: 10, + }); + + return ( + { + setP({ + ...pg, + total: 23, + }); + }} + /> + ); + }; + + const wrapper = mount(); + expect(wrapper.find('.ant-pagination-total-text').text()).toEqual('>200<'); + + // Should hide + wrapper.find('.ant-pagination-item-2').simulate('click'); + expect(wrapper.find('.ant-pagination-total-text')).toHaveLength(0); + }); }); diff --git a/components/table/hooks/usePagination.ts b/components/table/hooks/usePagination.ts index 8a5f5954e1..2e77a71a65 100644 --- a/components/table/hooks/usePagination.ts +++ b/components/table/hooks/usePagination.ts @@ -50,7 +50,10 @@ export default function usePagination( const { total: paginationTotal = 0, ...paginationObj } = pagination && typeof pagination === 'object' ? pagination : {}; - const [innerPagination, setInnerPagination] = useState(() => { + const [innerPagination, setInnerPagination] = useState<{ + current?: number; + pageSize?: number; + }>(() => { return { current: 'defaultCurrent' in paginationObj ? paginationObj.defaultCurrent : 1, pageSize: @@ -77,7 +80,6 @@ export default function usePagination( const refreshPagination = (current: number = 1, pageSize?: number) => { setInnerPagination({ - ...mergedPagination, current, pageSize: pageSize || mergedPagination.pageSize, });