Skip to content

Commit

Permalink
fix(RadioButtonGroup): clones Radio Button (#8283)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
andreancardona and kodiakhq[bot] authored Apr 16, 2021
1 parent 11ccbfa commit 6711067
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions packages/react/src/components/RadioButtonGroup/RadioButtonGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import PropTypes from 'prop-types';
import React from 'react';
import classNames from 'classnames';
import RadioButton from '../RadioButton';
import { warning } from '../../internal/warning';
import { settings } from 'carbon-components';

Expand Down Expand Up @@ -89,7 +88,7 @@ export default class RadioButtonGroup extends React.Component {

getRadioButtons = () => {
const children = React.Children.map(this.props.children, (radioButton) => {
const { value, ...other } = radioButton.props;
const { value } = radioButton.props;
/* istanbul ignore if */
if (typeof radioButton.props.checked !== 'undefined') {
warning(
Expand All @@ -99,16 +98,13 @@ export default class RadioButtonGroup extends React.Component {
);
}

return (
<RadioButton
{...other}
name={this.props.name}
key={value}
value={value}
onChange={this.handleChange}
checked={value === this.state.selected}
/>
);
return React.cloneElement(radioButton, {
name: this.props.name,
key: value,
value: value,
onChange: this.handleChange,
checked: value === this.state.selected,
});
});

return children;
Expand Down

0 comments on commit 6711067

Please sign in to comment.