Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 6 additions & 5 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;

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

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

focus = () => {
Expand Down
29 changes: 29 additions & 0 deletions packages/material-ui/src/RadioGroup/RadioGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,35 @@ describe('<RadioGroup />', () => {
);
});

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

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()
.last()
.props().checked,
true,
);
});

describe('imperative focus()', () => {
let wrapper;

Expand Down