@samitouri / QOS-React / commits / 85fe4ddce7

Fix - issue #12765 / the checked attribute is not initially set on the input (#13114)

XuMM_12 committed Jul 5, 2018 at 04:00 UTC 85fe4ddce7ae4d8c93a8107db9e7e65a0631baeb
2 files changed +9 -3
packages/react-dom/src/__tests__/ReactDOMInput-test.js
+8 -2
@@ -739,9 +739,12 @@ describe('ReactDOMInput', () => {
739 const cNode = stub.refs.c;
740
741 expect(aNode.checked).toBe(true);
742 + expect(aNode.hasAttribute('checked')).toBe(true);
743 expect(bNode.checked).toBe(false);
744 + expect(bNode.hasAttribute('checked')).toBe(false);
745 // c is in a separate form and shouldn't be affected at all here
746 expect(cNode.checked).toBe(true);
747 + expect(cNode.hasAttribute('checked')).toBe(true);
748
749 bNode.checked = true;
750 // This next line isn't necessary in a proper browser environment, but
@@ -750,6 +753,11 @@ describe('ReactDOMInput', () => {
753 aNode.checked = false;
754 expect(cNode.checked).toBe(true);
755
756 + // The original 'checked' attribute should be unchanged
757 + expect(aNode.hasAttribute('checked')).toBe(true);
758 + expect(bNode.hasAttribute('checked')).toBe(false);
759 + expect(cNode.hasAttribute('checked')).toBe(true);
760 +
761 // Now let's run the actual ReactDOMInput change event handler
762 ReactTestUtils.Simulate.change(bNode);
763
@@ -1324,7 +1332,6 @@ describe('ReactDOMInput', () => {
1332 'set property value',
1333 'set attribute value',
1334 'set attribute checked',
1327 - 'set attribute checked',
1335 ]);
1336 });
1337
@@ -1389,7 +1396,6 @@ describe('ReactDOMInput', () => {
1396 'node.value = "1980-01-01"',
1397 'node.setAttribute("value", "1980-01-01")',
1398 'node.setAttribute("checked", "")',
1392 - 'node.setAttribute("checked", "")',
1399 ]);
1400 });
1401
packages/react-dom/src/client/ReactDOMFiberInput.js
+1 -1
@@ -243,7 +243,7 @@ export function postMountWrapper(
243 node.name = '';
244 }
245 node.defaultChecked = !node.defaultChecked;
246 - node.defaultChecked = !node.defaultChecked;
246 + node.defaultChecked = !!node._wrapperState.initialChecked;
247 if (name !== '') {
248 node.name = name;
249 }