Skip to content

Commit 3e8ca2f

Browse files
author
Wensheng Xu
committed
Fix - issue #12765 / the checked attribute is not initially set on the input
1 parent 6d6de60 commit 3e8ca2f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

packages/react-dom/src/__tests__/ReactDOMInput-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,9 +739,12 @@ describe('ReactDOMInput', () => {
739739
const cNode = stub.refs.c;
740740

741741
expect(aNode.checked).toBe(true);
742+
expect(aNode.getAttribute('checked')).toBe('');
742743
expect(bNode.checked).toBe(false);
744+
expect(bNode.getAttribute('checked')).toBe(null);
743745
// c is in a separate form and shouldn't be affected at all here
744746
expect(cNode.checked).toBe(true);
747+
expect(cNode.getAttribute('checked')).toBe('');
745748

746749
bNode.checked = true;
747750
// This next line isn't necessary in a proper browser environment, but
@@ -750,6 +753,11 @@ describe('ReactDOMInput', () => {
750753
aNode.checked = false;
751754
expect(cNode.checked).toBe(true);
752755

756+
// The original 'checked' attribute should be unchanged
757+
expect(aNode.getAttribute('checked')).toBe('');
758+
expect(bNode.getAttribute('checked')).toBe(null);
759+
expect(cNode.getAttribute('checked')).toBe('');
760+
753761
// Now let's run the actual ReactDOMInput change event handler
754762
ReactTestUtils.Simulate.change(bNode);
755763

packages/react-dom/src/client/ReactDOMFiberInput.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ export function postMountWrapper(
242242
if (name !== '') {
243243
node.name = '';
244244
}
245-
node.defaultChecked = !node.defaultChecked;
245+
node.defaultChecked = !node._wrapperState.initialChecked;
246246
node.defaultChecked = !node.defaultChecked;
247247
if (name !== '') {
248248
node.name = name;

0 commit comments

Comments
 (0)