Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

fixes #459 #492

Closed
Show file tree
Hide file tree
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
5 changes: 1 addition & 4 deletions src/RadioGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ const RadioGroup = (props) => {
const { name, value, children, container,
childContainer, onChange, ...otherProps } = props;

const hasOnChange = typeof onChange === 'function';
const checked = hasOnChange ? 'checked' : 'defaultChecked';

return React.createElement(container, otherProps,
React.Children.map(children, child => {
const clonedChild = React.cloneElement(child, {
[checked]: child.props.value === value,
checked: child.props.value === value,
name,
onChange,
...otherProps
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/RadioGroup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('RadioGroup', () => {

for (let i = 0; i < output.props.children.length; i++) {
const radio = output.props.children[i];
expect(radio.props.defaultChecked).toBe(value === radio.props.value);
expect(radio.props.checked).toBe(value === radio.props.value);
}
});

Expand Down