Skip to content

Commit c703b60

Browse files
guanputao1991123
authored andcommitted
fix(Radio): child can contain null
1 parent acfb99c commit c703b60

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/radio/radio-group.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class RadioGroup extends Component {
155155
let children;
156156
if (this.props.children) {
157157
children = React.Children.map(this.props.children, (child, index) => {
158+
if (!React.isValidElement(child)) return child;
158159
const checked = this.state.value === child.props.value;
159160
const tabIndex = ((index === 0 && !this.state.value) || checked) ? 0 : -1;
160161
return React.cloneElement(child, child.props.tabIndex === undefined ? {

test/radio/group-spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,14 @@ describe('Radio.Group', () => {
342342
</RadioGroup>);
343343
assert(wrapper.find('.next-radio-button').children().length === 2);
344344
});
345+
it('should support null children', () => {
346+
const wrapper = mount(<RadioGroup dataSource={['apple', 'orange', 'pear']}>
347+
{null}
348+
<Radio tabIndex="0" key="2">Orange</Radio>
349+
HelloWorld
350+
</RadioGroup>);
351+
assert(wrapper.find('label').length === 1);
352+
});
345353
});
346354

347355
});

0 commit comments

Comments
 (0)