Skip to content
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

feat: support custom label render #760

Closed
wants to merge 3 commits into from
Closed

feat: support custom label render #760

wants to merge 3 commits into from

Conversation

pfdgithub
Copy link

@pfdgithub pfdgithub commented May 13, 2022

单选时,允许自定义渲染 label 。

使用场景:
当初始化时,若 value 不存在于待选列表中。之前的默认行为,是将 value 作为 label 显示。
但大部分场景,会将 id 作为 value ,将 name 作为 label 。此时默认行为就不够友好了。
现提供 labelRender 配置,允许用户自定义此场景下的显示策略。

fix ant-design/ant-design#27678
fix ant-design/ant-design#28138

@vercel
Copy link

vercel bot commented May 13, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
select ✅ Ready (Inspect) Visit Preview May 18, 2022 at 6:18AM (UTC)

@codecov
Copy link

codecov bot commented May 13, 2022

Codecov Report

Merging #760 (e691363) into master (15babe4) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head e691363 differs from pull request most recent head a0c7ae3. Consider uploading reports for the commit a0c7ae3 to get more accurate results

@@           Coverage Diff           @@
##           master     #760   +/-   ##
=======================================
  Coverage   99.50%   99.50%           
=======================================
  Files          25       25           
  Lines        1018     1020    +2     
  Branches      337      338    +1     
=======================================
+ Hits         1013     1015    +2     
  Misses          4        4           
  Partials        1        1           
Impacted Files Coverage Δ
src/BaseSelect.tsx 100.00% <ø> (ø)
src/Selector/index.tsx 100.00% <ø> (ø)
src/Selector/SingleSelector.tsx 100.00% <100.00%> (ø)

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@@ -125,6 +125,7 @@ export interface BaseSelectProps extends BaseSelectPrivateProps, React.AriaAttri
style?: React.CSSProperties;
showSearch?: boolean;
tagRender?: (props: CustomTagProps) => React.ReactElement;
labelRender?: (props: DisplayValueType) => React.ReactNode;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
labelRender?: (props: DisplayValueType) => React.ReactNode;
labelRender?: (item: DisplayValueType) => React.ReactNode;

Copy link
Member

@zombieJ zombieJ May 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要在 BaseSelect 里加这个属性。BaseSelect 是基类,其他组件有自己的实现。参考 https://github.com/react-component/cascader/blob/master/src/Cascader.tsx#L73 实现在 Select 里。不要改动 BaseSelect 和 Selector。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要在 BaseSelect 里加这个属性。BaseSelect 是基类,其他组件有自己的实现。参考 https://github.com/react-component/cascader/blob/master/src/Cascader.tsx#L73在Select 里实现。不要随便 BaseSelect 和 Selector。

已切换至 Select 中实现。


it('labelRender', () => {
const onLabelRender = jest.fn();
const labelRender = (props: any) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const labelRender = (props: any) => {
const labelRender = (item: DisplayValueType) => {

@Orange-Yellow
Copy link

这个功能什么时候能用?

@duxphp
Copy link

duxphp commented Jun 22, 2023

为啥要关闭 这里有什么问题或者代替实现么

@yoyo837
Copy link
Member

yoyo837 commented Jun 25, 2023

这PR谁关的都看不到, 而且无法重新打开.

@afc163
Copy link
Member

afc163 commented Jun 25, 2023

fork 库被删掉了。

@yoyo837
Copy link
Member

yoyo837 commented Jun 25, 2023

fork 库被删掉了。

学会了

@pfdgithub
Copy link
Author

提交后长期无反馈,清理仓库时就删除了。
这个问题很常见,一定还有其他人的 PR 未关闭。
麻烦上点心,找个合适的 PR 或者你们直接自己修一下。

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants