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, });