mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-27 06:30:20 +00:00
Merge pull request #1104 from Demonthos/fix-booleans-with-boolean-attributes
Fix boolean attributes with raw boolean values
This commit is contained in:
commit
4145e50bbf
2 changed files with 14 additions and 7 deletions
|
@ -48,17 +48,17 @@ export function setAttributeInner(node, field, value, ns) {
|
|||
node.defaultValue = value;
|
||||
break;
|
||||
case "checked":
|
||||
node.checked = value === "true" || value === true;
|
||||
node.checked = truthy(value);
|
||||
break;
|
||||
case "selected":
|
||||
node.selected = value === "true" || value === true;
|
||||
node.selected = truthy(value);
|
||||
break;
|
||||
case "dangerous_inner_html":
|
||||
node.innerHTML = value;
|
||||
break;
|
||||
default:
|
||||
// https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364
|
||||
if (value === "false" && bool_attrs.hasOwnProperty(name)) {
|
||||
if (!truthy(value) && bool_attrs.hasOwnProperty(name)) {
|
||||
node.removeAttribute(name);
|
||||
} else {
|
||||
node.setAttribute(name, value);
|
||||
|
@ -66,3 +66,7 @@ export function setAttributeInner(node, field, value, ns) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function truthy(val) {
|
||||
return val === "true" || val === true;
|
||||
}
|
||||
|
|
|
@ -78,17 +78,17 @@ mod js {
|
|||
node.defaultValue = value;
|
||||
break;
|
||||
case "checked":
|
||||
node.checked = value === "true";
|
||||
node.checked = truthy(value);
|
||||
break;
|
||||
case "selected":
|
||||
node.selected = value === "true";
|
||||
node.selected = truthy(value);
|
||||
break;
|
||||
case "dangerous_inner_html":
|
||||
node.innerHTML = value;
|
||||
break;
|
||||
default:
|
||||
// https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364
|
||||
if (value === "false" && bool_attrs.hasOwnProperty(name)) {
|
||||
if (!truthy(value) && bool_attrs.hasOwnProperty(name)) {
|
||||
node.removeAttribute(name);
|
||||
} else {
|
||||
node.setAttribute(name, value);
|
||||
|
@ -164,6 +164,9 @@ mod js {
|
|||
selected: true,
|
||||
truespeed: true,
|
||||
};
|
||||
function truthy(val) {
|
||||
return val === "true" || val === true;
|
||||
}
|
||||
"#;
|
||||
|
||||
extern "C" {
|
||||
|
|
Loading…
Reference in a new issue