-
-
Notifications
You must be signed in to change notification settings - Fork 51.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(Transfer): Dropdown is hidden & showSizeChanger
not work
#41906
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #41906 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 648 648
Lines 10965 10967 +2
Branches 2978 2978
=========================================
+ Hits 10965 10967 +2
☔ View full report in Codecov by Sentry. |
components/transfer/ListBody.tsx
Outdated
} | ||
|
||
const parsePagination = (pagination?: PaginationType) => { | ||
const parsePagination = (pagination?: PaginationType, pageSize?: number) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pageSize 应该包含在 pagination 里?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
放在里面的话会出现切换 pageSize 后页面数据不刷新,所以放到外面了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这很奇怪,不应该单独维护一个 pageSize,可以看看什么原因导致
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这很奇怪,不应该单独维护一个 pageSize,可以看看什么原因导致
ListBody 内部通过 ref 将过滤好的数据传递给外层,如果设置 showSizeChanger
后在 ListBody 内部维护 pageSize 那么就会出现我切换完 pageSize 后页面数据不会变化,因为没有触发外层组件的刷新。因此我将 pageSize
提取出来单独维护了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那应该还是合进去,这样的话参数冗余了。使用的时候可以这样
parsePagination({ ...pagination, pageSize})
any progress? |
8c91736
to
0ccaee7
Compare
好了~ |
components/transfer/ListBody.tsx
Outdated
const maxPageCount = Math.ceil(filteredRenderItems.length / mergedPagination.pageSize!); | ||
setCurrent(Math.min(current, maxPageCount)); | ||
} | ||
}, [filteredRenderItems, pagination]); | ||
}, [filteredRenderItems, pagination, pageSize]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}, [filteredRenderItems, pagination, pageSize]); | |
}, [filteredRenderItems, convertPagination, pageSize]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修改掉了
components/transfer/ListBody.tsx
Outdated
|
||
const [current, setCurrent] = React.useState<number>(1); | ||
const [pageSize, setPageSize] = React.useState<number>(convertPagination?.pageSize ?? 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果 pagination 里传进来的 pageSize 改变了是否应该响应?如果是的话应该用 useMergeState 代理受控
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯嗯,但是这样做的话,就始终使用传入的 pagesize,不可更改了,酱紫是正常的么
components/transfer/ListBody.tsx
Outdated
const memoizedItems = React.useMemo<RenderedItem<RecordType>[]>(() => { | ||
const mergedPagination = parsePagination(pagination); | ||
const displayItems = mergedPagination | ||
const mergedPagination = parsePagination({ ...convertPagination, pageSize }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感觉这一行写了很多遍,可以单独写一个 useMemo 吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好,用 useMemo 封装了一下
if (!pagination) { | ||
return null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里判空还是得有?
components/transfer/ListBody.tsx
Outdated
onScroll, | ||
onItemSelect, | ||
onItemRemove, | ||
} = props; | ||
const convertPagination = typeof pagination === 'object' ? pagination : {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感觉这里不等价,pagination 可以是 false
的话就和 true
一样处理了。
并且 null 也是 object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我是觉得应该一并收到 mergedPagination 这个 memo 里处理好点?
受控还是要用 |
@MadCcc 可以考虑合并一下这个PR吗? |
@YMNNs ci 挂了 |
我这边跟进一下~ |
好,我康康 |
[中文版模板 / Chinese template]
🤔 This is a ...
🔗 Related issue link
close #41790
💡 Background and solution
在当前的


Transfer
组件中,如果设置了pagination={{ showSizeChanger: true, simple: false }}
,那么会出现切换分页数量的下拉按钮被隐藏的情况:解决被隐藏问题并添加右边距(之前贴边)后,如下图:
根据 /~https://github.com/ant-design/ant-design/issues/41790#issuecomment-1507831602,发现
Transfer
组件内部的Pagination
没有绑定showSizeChanger
方法,因此添加上对应方法。📝 Changelog
showSizeChanger
not workshowSizeChanger
方法无效☑️ Self-Check before Merge
🚀 Summary
🤖 Generated by Copilot at ff72fad
Added pagination support for the
Transfer
component, allowing users to select and change the page size of the transfer list. Updated the test cases, theTransferList
andListBody
components, and the style file to handle the pagination functionality.🔍 Walkthrough
🤖 Generated by Copilot at ff72fad
pageSize
andonPageSizeChange
props toTransferList
andListBody
components to enable changing the number of items per page in the transfer component (link, link, link, link, link, link)parsePagination
function to accept an optionalpageSize
parameter and use it to slice the render items according to the current page number and page size (link, link, link)onShowSizeChange
prop toPagination
component to trigger theonPageSizeChange
callback and reset the current page number when the user selects a different page size (link)generateData
function toindex.test.tsx
to create mock data items for testing the transfer component with pagination (link)antCls
parameter togenTransferListStyle
function instyle/index.ts
to access the ant design class name for the transfer list component (link)minHeight
property to the transfer list style to fix a flexbox bug that causes the list body to overflow the list container when the page size is larger than the number of items (link)paddingInlineEnd
property to the pagination options style to add some spacing between the page size changer and the pagination buttons (link)