-
-
Notifications
You must be signed in to change notification settings - Fork 49k
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
Add Radio.Group props optionType
to choose item type
#12852
Conversation
Deploy preview for ant-design ready! Built with commit c8f6c4e |
…o.Button) when `options` is used. `optionType` default to `radio` for `Radio` (current behavior), and set to `button` for `Radio.Button`
Codecov Report
@@ Coverage Diff @@
## feature #12852 +/- ##
===========================================
- Coverage 92.64% 92.6% -0.04%
===========================================
Files 215 215
Lines 5613 5614 +1
Branches 1598 1571 -27
===========================================
- Hits 5200 5199 -1
- Misses 407 411 +4
+ Partials 6 4 -2
Continue to review full report at Codecov.
|
没什么特别的好处,也没解决什么问题,没必要换一种方式吧。 |
用声明式的方式可以通过声明不同的子元素来选择是 <Radio.Group>
<Radio>...</Radio>
<Radio.Group>
or
<Radio.Group>
<Radio.Button>...</Radio.Button>
<Radio.Group> 然而通过 如果没有 optionType 选项来实现,那么用户自己来实现这个需要再处理一遍 string类型的 options 和 object 类型的 options,然而这些都是 antd 内部的实现细节: export default class RadioButtonGroup extends PureComponent {
render() {
const {options, value, onChange} = this.props
return (
<Radio.Group value={value} onChange={onChange}>
{options.map((option, index) => {
if (typeof option === 'string') {
return (
<Radio.Button key={index} value={option}>
{option}
</Radio.Button>
)
} else {
return (
<Radio.Button key={index} value={option.value}>
{option.label}
</Radio.Button>
)
}
})}
</Radio.Group>
)
}
} 如果将来 这个PR就是解决这个问题的。 不知道这样解释是否能改变你的判断 @yesmeck ? |
之前没仔细看,这样是可以的,两种方式都保留好了。 |
还是不加了吧,加了反而会让用户疑惑: <Group optionType="button">
<Radio ... />
</Group> 原本的虽然麻烦,但是是可以实现这个功能的。 |
Add Radio.Group props
optionType
to choose item type (Radio or Radio.Button) whenoptions
is used.optionType
for
Radio` (default, current behavior)button
forRadio.Button
First of all, thank you for your contribution! :-)
Please makes sure that these checkboxes are checked before submitting your PR, thank you!
Make sure that you propose PR to right branch: bugfix for
master
, feature for branchfeature
.Make sure that you follow antd's code convention.
Run
npm run lint
and fix those errors before submitting in order to keep consistent code style.Rebase before creating a PR to keep commit history clear.
Add some descriptions and refer relative issues for you PR.
Update API docs for the component.
Update/Add demo to demonstrate new feature.
Update TypeScript definition for the component.
Add unit tests for the feature.