Merge pull request #103 from mrxiaozhuox/boolattrs-limit-type

Boolattrs limit type
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2022-01-08 13:40:37 -05:00
commit 5b882ac409
3 files changed
+69 -3

No files matched your search

+5
View File
@@ -18,6 +18,11 @@ fn app(cx: Scope) -> Element {
disabled: "{disabled}", disabled: "{disabled}",
"lower button" "lower button"
} }
input {
value: "false",
}
} }
}) })
} }
+30 -1
View File
@@ -1,3 +1,32 @@
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",
]
function serialize_event(event) { function serialize_event(event) {
switch (event.type) { switch (event.type) {
case "copy": case "copy":
@@ -370,7 +399,7 @@ class Interpreter {
break; break;
default: default:
// https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364 // 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); node.removeAttribute(name);
} else { } else {
node.setAttribute(name, value); node.setAttribute(name, value);
+34 -2
View File
@@ -349,9 +349,41 @@ impl WebsysDom {
} }
_ => { _ => {
// https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364 // 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" {
if let Some(el) = node.dyn_ref::<Element>() { if let Some(el) = node.dyn_ref::<Element>() {
let _ = el.remove_attribute(name); match name {
"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" => {
let _ = el.remove_attribute(name);
}
_ => {
let _ = el.set_attribute(name, value);
}
};
} }
} else { } else {
fallback(); fallback();