-
-
Notifications
You must be signed in to change notification settings - Fork 52k
feat: Adding custom renderer for select with demos #21064
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
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 6d4140e:
|
…this becomes a minimum for this feature
Codecov Report
@@ Coverage Diff @@
## feature #21064 +/- ##
===========================================
- Coverage 97.56% 97.55% -0.01%
===========================================
Files 299 300 +1
Lines 6969 6994 +25
Branches 1882 1882
===========================================
+ Hits 6799 6823 +24
- Misses 170 171 +1
Continue to review full report at Codecov.
|
…r and enriched edit experience
There is an an issue with snapshots in |
# Conflicts: # package.json
Seems multiple un-related files were prettieried. Could you help revert them? |
@zombieJ, apologies for that, the automated husky hooks triggered on the commit. This should now been clear. |
One demo is good enough. |
```jsx | ||
import { Select, Tag } from 'antd'; | ||
|
||
const OPTIONS = ['Hello', 'World', '42']; |
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.
OPTIONS = ['gold', 'cyan']
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.
and follow tagRender
just reuse the value.
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.
and follow
tagRender
just reuse the value.
If I do that without extra checks any other tags that's not a color understood by will essentially be transparent. As long as you're OK with that.
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.
We can just simplify demo for multiple
instead:
<Select
mode="multiple"
tagRender={tagRender}
defaultValue={OPTIONS}
style={{ width: '100%' }}
options={...}
/>
PS: Not Options
in children. options
is a prop.
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.
I've now switched over to "multiple" and aligned the demo to the "big-data" one for options.
LGTM |
I am trying to use this ability to render custom colors for each tag, but it looks like the colors are entirely dependent on either the It would be helpful to have the entire option passed through where we can access both |
@lawrencety, @dotexe0, The custom rendering is in no way limited to colors. You can bring-in rendering logic from your upper level component. While you cannot have more than |
@fguitton Thanks for the quick response. The issue there is then we are not able to directly control each individual tag's colors. It looks like all tags must share the same color if we are using a higher level component. If we want to render different properties for each select option. A straightforward and controlled way to do so is by passing in custom props for the custom tags. Those props would be passed through from a higher level component. Something like this:
Furthermore, if we are allowed to bring in any rendering logic, why limit the props that are passed down per record? It would make more sense to just pass the whole record. If there's a way to effectively set up custom properties for each tag that are controlled by the select options/properties please let us know. |
@lawrencety, You don't strictly need to pass in the all the elements you want to the
|
@fguitton Thank you, this was really helpful! |
But what if I want to dinamically set the colors of the labels itself not the options? I can't see a way to do that |
🤔 This is a ...
🔗 Related issue link
close #12910
💡 Background and solution
We want to be able to customise the rendering of elements in the Select component. For example to indicate invalid emails
This is the effective result :

Currently the work is in progress, as it necessitates react-component/select#445 to be merged first
📝 Changelog
This simply adds an example for using underlying
rc-select
change.☑️ Self Check before Merge
View rendered components/select/demo/custom-tag-render.md
View rendered components/select/index.en-US.md
View rendered components/select/index.zh-CN.md
IssueHunt Summary
Referenced issues
This pull request has been submitted to:
tags
) Override Tag StyleIssueHunt has been backed by the following sponsors. Become a sponsor