Add id for components to support anchors (#469)

This commit is contained in:
PeterYusuke 2023-02-09 07:09:03 +09:00 committed by GitHub
parent f2d0fbbd8d
commit 60949e24e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,6 +44,9 @@ class Component(Base, ABC):
# A unique key for the component.
key: Any = None
# The id for the component.
id: Any = None
@classmethod
def __init_subclass__(cls, **kwargs):
"""Set default properties.
@ -360,7 +363,9 @@ class Component(Base, ABC):
"""
tag = self._render()
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(
[str(tag.contents)] + [child.render() for child in self.children]
).strip(),