diff --git a/packages/material-ui/src/RadioGroup/RadioGroup.js b/packages/material-ui/src/RadioGroup/RadioGroup.js index 47a53c94f5c615..8d2c0ebf754ed9 100644 --- a/packages/material-ui/src/RadioGroup/RadioGroup.js +++ b/packages/material-ui/src/RadioGroup/RadioGroup.js @@ -9,13 +9,15 @@ import { createChainedFunction, find } from '../utils/helpers'; class RadioGroup extends React.Component { radios = []; - state = { - value: null, - }; - constructor(props) { super(); this.isControlled = props.value != null; + + if (!this.isControlled) { + this.state = { + value: props.defaultValue, + }; + } } focus = () => { diff --git a/packages/material-ui/src/RadioGroup/RadioGroup.test.js b/packages/material-ui/src/RadioGroup/RadioGroup.test.js index 4924aeb4f3fe39..a44b7c223e8218 100644 --- a/packages/material-ui/src/RadioGroup/RadioGroup.test.js +++ b/packages/material-ui/src/RadioGroup/RadioGroup.test.js @@ -56,6 +56,35 @@ describe('', () => { ); }); + it('should support default value in uncontrolled mode', () => { + const wrapper = shallow( + + + + , + ); + + 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;