Skip to content

Conversation

@ericvaladas
Copy link
Owner

@ericvaladas ericvaladas commented Feb 21, 2019

Something changed in React in version 16.3 that caused the value attribute to appear on an input when it had a defaultValue of undefined or null. In previous versions the attribute would be omitted unless it had a value.

For example, this JSX:

<input name="test" defaultValue={undefined}/>

will generate this HTML:

<input name="test" value>

whereas in versions prior to 16.3, it would generate this HTML:

<input name="test">

This change can cause an issue with checkbox values. When the value attribute is omitted on a checkbox, the target value will be "on" when checked. When a checkbox has the value attribute set, the target value will be that of the attribute when checked. In the case where the attribute is present without a value, the target value will be "" when checked, which is a falsey value.

This PR implements some logic for setting the value and defaultValue on child elements only when needed to workaround this issue. Also, checkboxes will now have a value of true when checked and the value attribute is empty.

@coveralls
Copy link

coveralls commented Feb 21, 2019

Pull Request Test Coverage Report for Build 283

  • 10 of 10 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 279: 0.0%
Covered Lines: 123
Relevant Lines: 123

💛 - Coveralls

@ericvaladas ericvaladas merged commit 2f80b0e into master Feb 21, 2019
@ericvaladas ericvaladas deleted the fix-empty-value-attribute branch February 21, 2019 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants