fix: Not merge additional data (#27412)

This commit is contained in:
二货机器人 2020-10-27 23:02:52 +08:00 committed by GitHub
parent abb724565d
commit 39333253d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 3 deletions

View File

@ -39,7 +39,7 @@ describe('Table.pagination', () => {
it('not crash when pageSize is undefined', () => { it('not crash when pageSize is undefined', () => {
expect(() => { expect(() => {
mount(createTable({ pagination: { pageSIze: undefined } })); mount(createTable({ pagination: { pageSize: undefined } }));
}).not.toThrow(); }).not.toThrow();
}); });
@ -409,4 +409,36 @@ describe('Table.pagination', () => {
}); });
expect(wrapper.find('.ant-pagination')).toHaveLength(2); 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 (
<Table
data={[]}
columns={[]}
pagination={p}
onChange={pg => {
setP({
...pg,
total: 23,
});
}}
/>
);
};
const wrapper = mount(<Demo />);
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);
});
}); });

View File

@ -50,7 +50,10 @@ export default function usePagination(
const { total: paginationTotal = 0, ...paginationObj } = const { total: paginationTotal = 0, ...paginationObj } =
pagination && typeof pagination === 'object' ? pagination : {}; pagination && typeof pagination === 'object' ? pagination : {};
const [innerPagination, setInnerPagination] = useState<TablePaginationConfig>(() => { const [innerPagination, setInnerPagination] = useState<{
current?: number;
pageSize?: number;
}>(() => {
return { return {
current: 'defaultCurrent' in paginationObj ? paginationObj.defaultCurrent : 1, current: 'defaultCurrent' in paginationObj ? paginationObj.defaultCurrent : 1,
pageSize: pageSize:
@ -77,7 +80,6 @@ export default function usePagination(
const refreshPagination = (current: number = 1, pageSize?: number) => { const refreshPagination = (current: number = 1, pageSize?: number) => {
setInnerPagination({ setInnerPagination({
...mergedPagination,
current, current,
pageSize: pageSize || mergedPagination.pageSize, pageSize: pageSize || mergedPagination.pageSize,
}); });