Browse Source

move add ref to component level render (#1019)

Sheldon 2 years ago
parent
commit
928501662e
2 changed files with 5 additions and 7 deletions
  1. 5 0
      pynecone/components/component.py
  2. 0 7
      pynecone/components/forms/input.py

+ 5 - 0
pynecone/components/component.py

@@ -320,6 +320,11 @@ class Component(Base, ABC):
         if hasattr(self, "as_"):
             props["as"] = self.as_  # type: ignore
 
+        # Add ref to element if `id` is not None.
+        ref = self.get_ref()
+        if ref is not None:
+            props["ref"] = Var.create(ref, is_local=False)
+
         return tag.add_props(**props)
 
     @classmethod

+ 0 - 7
pynecone/components/forms/input.py

@@ -70,13 +70,6 @@ class Input(ChakraComponent):
             "on_key_up": EVENT_ARG.key,
         }
 
-    def _render(self):
-        out = super()._render()
-        ref = self.get_ref()
-        if ref is not None:
-            out.add_props(ref=Var.create(ref, is_local=False))
-        return out
-
 
 class InputGroup(ChakraComponent):
     """The InputGroup component is a component that is used to group a set of inputs."""