diff --git a/components/list/__tests__/__snapshots__/pagination.test.js.snap b/components/list/__tests__/__snapshots__/pagination.test.js.snap index ddd19f3f73..8c873ac0f5 100644 --- a/components/list/__tests__/__snapshots__/pagination.test.js.snap +++ b/components/list/__tests__/__snapshots__/pagination.test.js.snap @@ -425,3 +425,143 @@ exports[`List.pagination should change page size work 2`] = ` `; + +exports[`List.pagination should default work 1`] = ` + +`; diff --git a/components/list/__tests__/pagination.test.js b/components/list/__tests__/pagination.test.js index a303971a52..a5c9f65647 100644 --- a/components/list/__tests__/pagination.test.js +++ b/components/list/__tests__/pagination.test.js @@ -175,4 +175,24 @@ describe('List.pagination', () => { .render(), ).toMatchSnapshot(); }); + + it('should default work', () => { + const wrapper = mount( + createList({ + pagination: { + defaultPageSize: 3, + defaultCurrent: 2, + pageSizeOptions: ['1', '3'], + showSizeChanger: true, + }, + }), + ); + + expect( + wrapper + .find('Pagination') + .first() + .render(), + ).toMatchSnapshot(); + }); }); diff --git a/components/list/index.tsx b/components/list/index.tsx index 47def135e9..1003875e9d 100644 --- a/components/list/index.tsx +++ b/components/list/index.tsx @@ -78,11 +78,6 @@ export default class List extends React.Component, ListState> { pagination: false as ListProps['pagination'], }; - state = { - paginationCurrent: 1, - paginationSize: 10, - }; - defaultPaginationProps = { current: 1, total: 0, @@ -94,6 +89,18 @@ export default class List extends React.Component, ListState> { private onPaginationShowSizeChange = this.triggerPaginationEvent('onShowSizeChange'); + constructor(props: ListProps) { + super(props); + + const { pagination } = props; + const paginationObj = typeof pagination === 'object' ? pagination : {}; + + this.state = { + paginationCurrent: paginationObj.defaultCurrent || 1, + paginationSize: paginationObj.defaultPageSize || 10, + }; + } + getChildContext() { return { grid: this.props.grid,