Răsfoiți Sursa

Merge pull request #113 from DioxusLabs/jk/desktop-cursor-jump

fix: cursor jumping in desktop inputs
Jonathan Kelley 3 ani în urmă
părinte
comite
20a29409b2
1 a modificat fișierele cu 33 adăugiri și 30 ștergeri
  1. 33 30
      packages/desktop/src/index.js

+ 33 - 30
packages/desktop/src/index.js

@@ -1,31 +1,31 @@
-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",
-]
+const bool_attrs = {
+  allowfullscreen: true,
+  allowpaymentrequest: true,
+  async: true,
+  autofocus: true,
+  autoplay: true,
+  checked: true,
+  controls: true,
+  default: true,
+  defer: true,
+  disabled: true,
+  formnovalidate: true,
+  hidden: true,
+  ismap: true,
+  itemscope: true,
+  loop: true,
+  multiple: true,
+  muted: true,
+  nomodule: true,
+  novalidate: true,
+  open: true,
+  playsinline: true,
+  readonly: true,
+  required: true,
+  reversed: true,
+  selected: true,
+  truespeed: true,
+};
 
 function serialize_event(event) {
   switch (event.type) {
@@ -321,6 +321,7 @@ class Interpreter {
 
   CreatePlaceholder(edit) {
     let el = document.createElement("pre");
+    el.hidden = true;
     this.stack.push(el);
     this.nodes[edit.root] = el;
   }
@@ -386,7 +387,9 @@ class Interpreter {
     } else {
       switch (name) {
         case "value":
-          node.value = value;
+          if (value != node.value) {
+            node.value = value;
+          }
           break;
         case "checked":
           node.checked = value === "true";
@@ -399,7 +402,7 @@ class Interpreter {
           break;
         default:
           // https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364
-          if (value == "false" && bool_attrs.indexOf(name)) {
+          if (value == "false" && bool_attrs.hasOwnProperty(name)) {
             node.removeAttribute(name);
           } else {
             node.setAttribute(name, value);