Skip to content

Commit

Permalink
Fix - issue #12765 / the checked attribute is not initially set on th…
Browse files Browse the repository at this point in the history
…e input
  • Loading branch information
Wensheng Xu committed Jun 29, 2018
1 parent 6d6de60 commit b56f29d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions packages/react-dom/src/__tests__/ReactDOMInput-test.js
Expand Up @@ -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
Expand All @@ -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);

Expand Down Expand Up @@ -1324,7 +1332,6 @@ describe('ReactDOMInput', () => {
'set property value',
'set attribute value',
'set attribute checked',
'set attribute checked',
]);
});

Expand Down Expand Up @@ -1389,7 +1396,6 @@ describe('ReactDOMInput', () => {
'node.value = "1980-01-01"',
'node.setAttribute("value", "1980-01-01")',
'node.setAttribute("checked", "")',
'node.setAttribute("checked", "")',
]);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/client/ReactDOMFiberInput.js
Expand Up @@ -243,7 +243,7 @@ export function postMountWrapper(
node.name = '';
}
node.defaultChecked = !node.defaultChecked;
node.defaultChecked = !node.defaultChecked;
node.defaultChecked = node._wrapperState.initialChecked;
if (name !== '') {
node.name = name;
}
Expand Down

0 comments on commit b56f29d

Please sign in to comment.