Skip to content

Commit

Permalink
fix empty attr value in legacy input
Browse files Browse the repository at this point in the history
  • Loading branch information
amine-ini committed Dec 21, 2022
1 parent f11360a commit cc33501
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 57 deletions.
96 changes: 48 additions & 48 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-to-html-element",
"version": "1.4.6",
"version": "1.4.7",
"description": "Converts React Components to HTML Element (also known as Web Component, Custom Element)",
"main": "src/index.js",
"scripts": {
Expand Down
16 changes: 8 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ const handleValueAttr = (children) => {
if (typeof child.props === "object") {
child = {...child};
child.props = {...child.props}
}

if (['input', 'textarea', 'select'].indexOf(child.type) >= 0 && child?.props?.value) {
child.props.defaultValue = child.props.value;
delete child.props.value;
}
if (['input', 'textarea', 'select'].indexOf(child.type) >= 0 && Object.hasOwn(child.props, 'value')) {
child.props.defaultValue = child.props.value;
delete child.props.value;
}

if (child?.props?.children) {
let c = Array.isArray(child.props.children) ? child.props.children : [child.props.children];
child.props.children = handleValueAttr(c);
if (child.props?.children) {
let c = Array.isArray(child.props.children) ? child.props.children : [child.props.children];
child.props.children = handleValueAttr(c);
}
}

return child;
Expand Down

0 comments on commit cc33501

Please sign in to comment.