Skip to content

Commit a3b6d44

Browse files
Wensheng XuXuMM_12
authored andcommitted
Fix - issue #12765 / the checked attribute is not initially set on the input
1 parent 183aefa commit a3b6d44

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

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

Lines changed: 8 additions & 2 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.hasAttribute('checked')).toBe(true);
742743
expect(bNode.checked).toBe(false);
744+
expect(bNode.hasAttribute('checked')).toBe(false);
743745
// c is in a separate form and shouldn't be affected at all here
744746
expect(cNode.checked).toBe(true);
747+
expect(cNode.hasAttribute('checked')).toBe(true);
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.hasAttribute('checked')).toBe(true);
758+
expect(bNode.hasAttribute('checked')).toBe(false);
759+
expect(cNode.hasAttribute('checked')).toBe(true);
760+
753761
// Now let's run the actual ReactDOMInput change event handler
754762
ReactTestUtils.Simulate.change(bNode);
755763

@@ -1324,7 +1332,6 @@ describe('ReactDOMInput', () => {
13241332
'set property value',
13251333
'set attribute value',
13261334
'set attribute checked',
1327-
'set attribute checked',
13281335
]);
13291336
});
13301337

@@ -1389,7 +1396,6 @@ describe('ReactDOMInput', () => {
13891396
'node.value = "1980-01-01"',
13901397
'node.setAttribute("value", "1980-01-01")',
13911398
'node.setAttribute("checked", "")',
1392-
'node.setAttribute("checked", "")',
13931399
]);
13941400
});
13951401

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

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

0 commit comments

Comments
 (0)