From c47bfb0c918de3d5a512c5bcd9afcc66e1204788 Mon Sep 17 00:00:00 2001 From: zhangchen Date: Fri, 28 Aug 2020 15:48:19 +0800 Subject: [PATCH] fix: Table topPaginationNode display logic should same with bottomPaginationNode (#26143) * fix: Tree bottomPaginationNode display logic should same with bottomPaginationNode * update: test --- components/table/Table.tsx | 4 +- .../table/__tests__/Table.pagination.test.js | 47 +++++++------------ 2 files changed, 18 insertions(+), 33 deletions(-) diff --git a/components/table/Table.tsx b/components/table/Table.tsx index 4d4f9d5e243d..1bff7e2fe854 100644 --- a/components/table/Table.tsx +++ b/components/table/Table.tsx @@ -420,7 +420,7 @@ function Table(props: TableProps) { let topPaginationNode: React.ReactNode; let bottomPaginationNode: React.ReactNode; - if (pagination !== false) { + if (pagination !== false && mergedPagination?.total) { let paginationSize: TablePaginationConfig['size']; if (mergedPagination.size) { paginationSize = mergedPagination.size; @@ -495,7 +495,7 @@ function Table(props: TableProps) { internalRefs={internalRefs as any} transformColumns={transformColumns} /> - {mergedData && mergedData.length > 0 && bottomPaginationNode} + {bottomPaginationNode} ); diff --git a/components/table/__tests__/Table.pagination.test.js b/components/table/__tests__/Table.pagination.test.js index da85ba5792aa..f6a56bba1410 100644 --- a/components/table/__tests__/Table.pagination.test.js +++ b/components/table/__tests__/Table.pagination.test.js @@ -378,39 +378,24 @@ describe('Table.pagination', () => { ); }); - it('should render pagination after last item on last page being removed with async mode', () => { - const lastPageNum = data.length; + it('should render pagination after last item on last page being removed', () => { + const total = data.length; + const paginationProp = { + pageSize: 1, + total, + current: total, + position: ['topLeft', 'bottomLeft'], + }; const wrapper = mount( - createTable({ pagination: { pageSize: 1, total: data.length, current: lastPageNum } }), + createTable({ + pagination: paginationProp, + }), ); - const newCol = [ - { - title: 'Name', - dataIndex: 'name', - }, - { - title: 'Action', - dataIndex: 'name', - render(_, record) { - const deleteRow = () => { - const newData = data.filter(d => d.key !== record.key); - wrapper.setProps({ - dataSource: newData, - pagination: { pageSize: 1, total: newData.length, current: lastPageNum }, - }); - }; - return ( - - Delete - - ); - }, - }, - ]; - - wrapper.setProps({ columns: newCol }); - wrapper.find('.btn-delete').simulate('click'); - expect(wrapper.find('.ant-pagination')).toHaveLength(1); + wrapper.setProps({ + dataSource: data.slice(total - 1), + pagination: { ...paginationProp, total: total - 1 }, + }); + expect(wrapper.find('.ant-pagination')).toHaveLength(2); }); });