Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 7 additions & 6 deletions packages/material-ui/src/RadioGroup/RadioGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import { createChainedFunction, find } from '../utils/helpers';
class RadioGroup extends React.Component {
radios = [];

state = {
value: null,
};

constructor(props) {
super();
this.isControlled = props.value != null;
super(props);

this.isControlled = !props.hasOwnProperty('defaultValue') && !props.hasOwnProperty('value');

this.state = {
value: this.isControlled ? props.value : props.defaultValue,
};
}

focus = () => {
Expand Down
16 changes: 13 additions & 3 deletions packages/material-ui/src/RadioGroup/RadioGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,28 @@ describe('<RadioGroup />', () => {

it('should support uncontrolled mode', () => {
const wrapper = shallow(
<RadioGroup name="group">
<RadioGroup name="group" defaultValue="zero">
<Radio value="zero" />
<Radio value="one" />
</RadioGroup>,
);

const radio = wrapper.children().first();
assert.strictEqual(
wrapper
.children()
.first()
.props().checked,
true,
);

const radio = wrapper.children().last();
const event = { target: { value: 'one' } };
radio.simulate('change', event, true);

assert.strictEqual(
wrapper
.children()
.first()
.last()
.props().checked,
true,
);
Expand Down