fix: Table topPaginationNode display logic should same with bottomPaginationNode (#26143)

* fix: Tree bottomPaginationNode display logic should same with bottomPaginationNode

* update: test
This commit is contained in:
zhangchen 2020-08-28 15:48:19 +08:00 committed by GitHub
parent 77cbf724cf
commit c47bfb0c91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 33 deletions

View File

@ -420,7 +420,7 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) {
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<RecordType extends object = any>(props: TableProps<RecordType>) {
internalRefs={internalRefs as any}
transformColumns={transformColumns}
/>
{mergedData && mergedData.length > 0 && bottomPaginationNode}
{bottomPaginationNode}
</Spin>
</div>
);

View File

@ -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 (
<span className="btn-delete" onClick={deleteRow}>
Delete
</span>
);
},
},
];
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);
});
});