Skip to content

Commit

Permalink
fix: pagination componnet is not displayed at the position is none of… (
Browse files Browse the repository at this point in the history
ant-design#29256)

* fix: pagination componnet is not displayed at the position is none of array

* docs: update table/pagination position column typeValue

* fix: named invalid column

* fix: delete unless code

* refactor: refactor pagination position logic

* ci: fix lint error

* ci: fix lint error

* test: update snapshot
  • Loading branch information
mumiao authored Feb 7, 2021
1 parent bcd58bd commit d83e5fd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
30 changes: 16 additions & 14 deletions components/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,10 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) {
};

/**
* Controlled state in `columns` is not a good idea that makes too many code (1000+ line?) to read
* state out and then put it back to title render. Move these code into `hooks` but still too
* complex. We should provides Table props like `sorter` & `filter` to handle control in next big version.
* Controlled state in `columns` is not a good idea that makes too many code (1000+ line?) to
* read state out and then put it back to title render. Move these code into `hooks` but still
* too complex. We should provides Table props like `sorter` & `filter` to handle control in next
* big version.
*/

// ============================ Sorter =============================
Expand Down Expand Up @@ -439,18 +440,19 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) {
/>
);
const defaultPosition = direction === 'rtl' ? 'left' : 'right';
if (mergedPagination.position !== null && Array.isArray(mergedPagination.position)) {
const topPos = mergedPagination.position.find(p => p.indexOf('top') !== -1);
const bottomPos = mergedPagination.position.find(p => p.indexOf('bottom') !== -1);
if (!topPos && !bottomPos) {
const { position } = mergedPagination;
if (position !== null && Array.isArray(position)) {
const topPos = position.find(p => p.indexOf('top') !== -1);
const bottomPos = position.find(p => p.indexOf('bottom') !== -1);
const isDisable = position.every(p => `${p}` === 'none');
if (!topPos && !bottomPos && !isDisable) {
bottomPaginationNode = renderPagination(defaultPosition);
} else {
if (topPos) {
topPaginationNode = renderPagination(topPos!.toLowerCase().replace('top', ''));
}
if (bottomPos) {
bottomPaginationNode = renderPagination(bottomPos!.toLowerCase().replace('bottom', ''));
}
}
if (topPos) {
topPaginationNode = renderPagination(topPos!.toLowerCase().replace('top', ''));
}
if (bottomPos) {
bottomPaginationNode = renderPagination(bottomPos!.toLowerCase().replace('bottom', ''));
}
} else {
bottomPaginationNode = renderPagination(defaultPosition);
Expand Down
8 changes: 6 additions & 2 deletions components/table/__tests__/Table.pagination.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,17 @@ describe('Table.pagination', () => {
expect(wrapper.find('.ant-spin-container').children()).toHaveLength(3);
expect(wrapper.find('.ant-spin-container').childAt(0).find('.ant-pagination')).toHaveLength(1);
expect(wrapper.find('.ant-spin-container').childAt(2).find('.ant-pagination')).toHaveLength(1);
wrapper.setProps({ pagination: { position: ['none', 'none'] } });
expect(wrapper.find('.ant-pagination')).toHaveLength(0);
wrapper.setProps({ pagination: { position: ['invalid'] } });
expect(wrapper.find('.ant-pagination')).toHaveLength(1);
wrapper.setProps({ pagination: { position: ['invalid', 'invalid'] } });
expect(wrapper.find('.ant-pagination')).toHaveLength(1);
});

/**
* `pagination` is not designed to accept `true` value, but in practice, many people assign `true`
* to `pagination`, since they misunderstand that `pagination` can accept a boolean value.
* `pagination` is not designed to accept `true` value, but in practice, many people assign
* `true` to `pagination`, since they misunderstand that `pagination` can accept a boolean value.
*/
it('Accepts pagination as true', () => {
const wrapper = mount(createTable({ pagination: true }));
Expand Down
2 changes: 1 addition & 1 deletion components/table/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Properties for pagination.

| Property | Description | Type | Default |
| --- | --- | --- | --- |
| position | Specify the position of `Pagination`, could be `topLeft` \| `topCenter` \| `topRight` \|`bottomLeft` \| `bottomCenter` \| `bottomRight` | Array | \[`bottomRight`] |
| position | Specify the position of `Pagination`, could be`topLeft` \| `topCenter` \| `topRight` \|`bottomLeft` \| `bottomCenter` \| `bottomRight` | Array | \[`bottomRight`] |

More about pagination, please check [`Pagination`](/components/pagination/).

Expand Down

0 comments on commit d83e5fd

Please sign in to comment.