Skip to content

value= shouldn't be converted to defaultValue= for <option> #625

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

Closed
philiptzou opened this issue Jul 10, 2022 · 6 comments · Fixed by #790
Closed

value= shouldn't be converted to defaultValue= for <option> #625

philiptzou opened this issue Jul 10, 2022 · 6 comments · Fixed by #790

Comments

@philiptzou
Copy link

The value of <option> tags of <select> are fixed. Converting their value= to defaultValue= results bug if the option label is different from the value. For example:

<select name="range" value="gte-2">
  <option value="lt-1">Less than 1</option>
  <option value="gte-2">≥2<option>
</select>

The value of <select>'s "gte-2" won't get a match and it will fallback to "Less than 1".

// convert attribute to uncontrolled component prop (e.g., `value` to `defaultValue`)
// https://reactjs.org/docs/uncontrolled-components.html
if (
(propName === 'checked' || propName === 'value') &&
!inputIsValueOnly
) {
propName = getPropName('default' + attributeNameLowerCased);
}

@remarkablemark
Copy link
Owner

Thanks for opening this issue @philiptzou.

What versions are you using (html-react-parser and react/react-dom) and can you provide a reproducible example?

philiptzou added a commit to philiptzou/html-react-parser that referenced this issue Jul 11, 2022
@philiptzou
Copy link
Author

@remarkablemark I already provided an example. I don't think the version is relevant since the current source code explicitly changed value to defaultValue. I have submitted a pull request.

philiptzou added a commit to philiptzou/html-react-parser that referenced this issue Jul 11, 2022
@arpitBhalla
Copy link

Hey @remarkablemark, I have a question, but it's not related to this issue, I was looking for various alternatives, and found this package, I was thinking how this how package is different from Babel Transform, or jscodeshift?

@remarkablemark
Copy link
Owner

@arpitBhalla for questions unrelated, do you mind creating a new issue? But to answer your current question, this package converts raw HTML string to React elements. If you're looking for something that generates an AST tree, then you can go with Babel or something else.

@arpitBhalla
Copy link

Thanks

adammockor added a commit to adammockor/html-react-parser that referenced this issue Jan 5, 2023
adammockor added a commit to adammockor/html-react-parser that referenced this issue Jan 5, 2023
remarkablemark pushed a commit that referenced this issue Jan 5, 2023
* fix(attributes-to-props): don't convert value of option tag

Fixes #625

* fix(attributes-to-props): fix issues with tests

* fix(attributes-to-props): increase size limit

* fix(attributes-to-props): improve jsdoc documentation

* fix(attributes-to-props): remove lock file

* fix(attributes-to-props): fix type issues
@remarkablemark
Copy link
Owner

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