Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defaultChecked prop sets only checked attribute #12765

Closed
klintmane opened this issue May 8, 2018 · 3 comments
Closed

defaultChecked prop sets only checked attribute #12765

klintmane opened this issue May 8, 2018 · 3 comments

Comments

@klintmane
Copy link

klintmane commented May 8, 2018

Type

inconsistency for common use cases.
bug for projects relying on correct DOM emissions.

Description

It's unclear to me if the following is a known issue or not.
Take in consideration the snippet below:

<input type="checkbox" defaultChecked={true} />

Current Behavior

Setting the defaultValue prop on inputs of other types sets both the value and defaultValue attribute on the DOM element.

When setting the defaultChecked prop on inputs of type checkbox only the checked attribute is correctly set, leaving the defaultChecked attribute unchanged.

Expected Behaviour

Like mentioned above, the expected behavior would be for the defaultChecked prop to set both the checked and defaultChecked attributes on the corresponding DOM node (like it's the case with the defaultValue prop).

@Checkson
Copy link

Checkson commented May 9, 2018

I also found the same problem, I am now very distressed, ask how to solve?

@nhunzaker
Copy link
Contributor

nhunzaker commented Jun 25, 2018

This does appear to be a bug: https://codesandbox.io/s/qx0110rpo6

The "checked" attribute is not initially set on the input:

<input type="checkbox" defaultChecked={true} />

screen shot 2018-06-25 at 8 42 36 am

It looks like this has been a bug since 15.0.0. I think we need to add/remove the checked attribute in the post-mount wrapper:
https://github.com/facebook/react/blob/master/packages/react-dom/src/client/ReactDOMFiberInput.js#L245-L246

dilidili pushed a commit to dilidili/react that referenced this issue Jun 28, 2018
dilidili pushed a commit to dilidili/react that referenced this issue Jun 28, 2018
dilidili pushed a commit to dilidili/react that referenced this issue Jun 29, 2018
dilidili pushed a commit to dilidili/react that referenced this issue Jun 29, 2018
dilidili pushed a commit to dilidili/react that referenced this issue Jun 29, 2018
dilidili pushed a commit to dilidili/react that referenced this issue Jun 29, 2018
@nhunzaker
Copy link
Contributor

Fixed by #13114

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants