diff --git a/packages/react-dom/src/__tests__/ReactDOMInput-test.js b/packages/react-dom/src/__tests__/ReactDOMInput-test.js index 578e5b100e8a9..9bfcb20b2a8dc 100644 --- a/packages/react-dom/src/__tests__/ReactDOMInput-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMInput-test.js @@ -739,9 +739,12 @@ describe('ReactDOMInput', () => { const cNode = stub.refs.c; expect(aNode.checked).toBe(true); + expect(aNode.getAttribute('checked')).toBe(''); expect(bNode.checked).toBe(false); + expect(bNode.getAttribute('checked')).toBe(null); // c is in a separate form and shouldn't be affected at all here expect(cNode.checked).toBe(true); + expect(cNode.getAttribute('checked')).toBe(''); bNode.checked = true; // This next line isn't necessary in a proper browser environment, but @@ -750,6 +753,11 @@ describe('ReactDOMInput', () => { aNode.checked = false; expect(cNode.checked).toBe(true); + // The original 'checked' attribute should be unchanged + expect(aNode.getAttribute('checked')).toBe(''); + expect(bNode.getAttribute('checked')).toBe(null); + expect(cNode.getAttribute('checked')).toBe(''); + // Now let's run the actual ReactDOMInput change event handler ReactTestUtils.Simulate.change(bNode); diff --git a/packages/react-dom/src/client/ReactDOMFiberInput.js b/packages/react-dom/src/client/ReactDOMFiberInput.js index c164d984199a0..bb0bb8a269a68 100644 --- a/packages/react-dom/src/client/ReactDOMFiberInput.js +++ b/packages/react-dom/src/client/ReactDOMFiberInput.js @@ -242,7 +242,7 @@ export function postMountWrapper( if (name !== '') { node.name = ''; } - node.defaultChecked = !node.defaultChecked; + node.defaultChecked = !node._wrapperState.initialChecked; node.defaultChecked = !node.defaultChecked; if (name !== '') { node.name = name;