move add ref to component level render (#1019)

This commit is contained in:
Sheldon 2023-05-15 10:01:23 +08:00 committed by GitHub
parent b056b79479
commit 928501662e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 7 deletions

View File

@ -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

View File

@ -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."""