Skip to content
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

fix(RadioButtonGroup): clones RadioButton #8283

Merged
merged 3 commits into from
Apr 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
});
tw15egan marked this conversation as resolved.
Show resolved Hide resolved
});

return children;
Expand Down