Skip to content

Commit

Permalink
Fix pc.link with no href (#1178)
Browse files Browse the repository at this point in the history
  • Loading branch information
picklelo authored Jun 10, 2023
1 parent a275b4a commit 2bc45b0
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions pynecone/components/navigation/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,25 @@ def _get_imports(self) -> imports.ImportDict:
return {**super()._get_imports(), **NextLink.create()._get_imports()}

@classmethod
def create(
cls, *children, href: Optional[Var] = None, rel: Optional[Var] = None, **props
) -> Component:
def create(cls, *children, href: Optional[Var] = None, **props) -> Component:
"""Create a Link component.
Args:
*children: The children of the component.
href (Var): The href attribute of the link. Defaults to None.
rel (Var): The rel attribute of the link. Defaults to None.
href: The href attribute of the link.
**props: The props of the component.
Raises:
ValueError: in case of missing children
ValueError: in case of missing href
Returns:
Component: The link component
"""
if href and not len(children):
raise ValueError("Link without a child will not display")
elif href is None and len(children):
raise ValueError("Link without 'href' props will not work.")
else:
props.update({"href": href})
if rel:
props.update({"rel": rel})
# Don't use a NextLink if there is no href.
props["as_"] = "Link"
if href:
props["href"] = href
return super().create(*children, **props)

0 comments on commit 2bc45b0

Please sign in to comment.