Fix pc.link with no href (#1178)

This commit is contained in:
Nikhil Rao 2023-06-09 18:55:21 -07:00 committed by GitHub
parent a275b4ad6e
commit 2bc45b000c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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