feat: bool attr white list

This commit is contained in:
YuKun Liu 2022-01-09 02:02:23 +08:00
parent 4f1894ff5c
commit 8f4aa84f1a
3 changed files with 67 additions and 2 deletions

View File

@ -18,6 +18,11 @@ fn app(cx: Scope) -> Element {
disabled: "{disabled}",
"lower button"
}
input {
value: "false",
}
}
})
}

View File

@ -369,8 +369,38 @@ class Interpreter {
node.innerHTML = value;
break;
default:
const bool_attrs = [
"allowfullscreen",
"allowpaymentrequest",
"async",
"autofocus",
"autoplay",
"checked",
"controls",
"default",
"defer",
"disabled",
"formnovalidate",
"hidden",
"ismap",
"itemscope",
"loop",
"multiple",
"muted",
"nomodule",
"novalidate",
"open",
"playsinline",
"readonly",
"required",
"reversed",
"selected",
"truespeed",
]
// https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364
if (value == "false" && name != "capture" && name != "download") {
if (value == "false" && bool_attrs.indexOf(name)) {
node.removeAttribute(name);
} else {
node.setAttribute(name, value);

View File

@ -348,8 +348,38 @@ impl WebsysDom {
}
}
_ => {
let bool_attrs = vec![
"allowfullscreen",
"allowpaymentrequest",
"async",
"autofocus",
"autoplay",
"checked",
"controls",
"default",
"defer",
"disabled",
"formnovalidate",
"hidden",
"ismap",
"itemscope",
"loop",
"multiple",
"muted",
"nomodule",
"novalidate",
"open",
"playsinline",
"readonly",
"required",
"reversed",
"selected",
"truespeed",
];
// https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364
if value == "false" && ((name != "capture") && (name != "download")) {
if value == "false" && bool_attrs.contains(&name) {
if let Some(el) = node.dyn_ref::<Element>() {
let _ = el.remove_attribute(name);
}