-
-
Notifications
You must be signed in to change notification settings - Fork 457
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov Report
@@ 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
📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more |
src/BaseSelect.tsx
Outdated
@@ -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; |
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.
labelRender?: (props: DisplayValueType) => React.ReactNode; | |
labelRender?: (item: DisplayValueType) => React.ReactNode; |
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.
不要在 BaseSelect 里加这个属性。BaseSelect 是基类,其他组件有自己的实现。参考 https://github.com/react-component/cascader/blob/master/src/Cascader.tsx#L73 实现在 Select 里。不要改动 BaseSelect 和 Selector。
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.
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.
不要在 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) => { |
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.
const labelRender = (props: any) => { | |
const labelRender = (item: DisplayValueType) => { |
这个功能什么时候能用? |
为啥要关闭 这里有什么问题或者代替实现么 |
这PR谁关的都看不到, 而且无法重新打开. |
fork 库被删掉了。 |
学会了 |
提交后长期无反馈,清理仓库时就删除了。 |
单选时,允许自定义渲染 label 。
使用场景:
当初始化时,若 value 不存在于待选列表中。之前的默认行为,是将 value 作为 label 显示。
但大部分场景,会将 id 作为 value ,将 name 作为 label 。此时默认行为就不够友好了。
现提供 labelRender 配置,允许用户自定义此场景下的显示策略。
fix ant-design/ant-design#27678
fix ant-design/ant-design#28138