Răsfoiți Sursa

Add id for components to support anchors (#469)

PeterYusuke 2 ani în urmă
părinte
comite
60949e24e6
1 a modificat fișierele cu 6 adăugiri și 1 ștergeri
  1. 6 1
      pynecone/components/component.py

+ 6 - 1
pynecone/components/component.py

@@ -44,6 +44,9 @@ class Component(Base, ABC):
     # A unique key for the component.
     # A unique key for the component.
     key: Any = None
     key: Any = None
 
 
+    # The id for the component.
+    id: Any = None
+
     @classmethod
     @classmethod
     def __init_subclass__(cls, **kwargs):
     def __init_subclass__(cls, **kwargs):
         """Set default properties.
         """Set default properties.
@@ -360,7 +363,9 @@ class Component(Base, ABC):
         """
         """
         tag = self._render()
         tag = self._render()
         return str(
         return str(
-            tag.add_props(**self.event_triggers, key=self.key, sx=self.style).set(
+            tag.add_props(
+                **self.event_triggers, key=self.key, sx=self.style, id=self.id
+            ).set(
                 contents=utils.join(
                 contents=utils.join(
                     [str(tag.contents)] + [child.render() for child in self.children]
                     [str(tag.contents)] + [child.render() for child in self.children]
                 ).strip(),
                 ).strip(),