Fix rx.link href prop and Var.to_string type (#1600)
* Fix rx.link href prop * Update bool var types
This commit is contained in:
parent
8ce3ee19cc
commit
00714c60ac
@ -36,8 +36,8 @@ def DynamicRoute():
|
||||
return rx.fragment(
|
||||
rx.input(value=DynamicState.token, is_read_only=True, id="token"),
|
||||
rx.input(value=DynamicState.page_id, is_read_only=True, id="page_id"),
|
||||
rx.link("index", href="/", id="link_index"), # type: ignore
|
||||
rx.link("page_X", href="/static/x", id="link_page_x"), # type: ignore
|
||||
rx.link("index", href="/", id="link_index"),
|
||||
rx.link("page_X", href="/static/x", id="link_page_x"),
|
||||
rx.link(
|
||||
"next", href="/page/" + DynamicState.next_page, id="link_page_next" # type: ignore
|
||||
),
|
||||
|
@ -1,6 +1,5 @@
|
||||
"""A link component."""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from reflex.components.component import Component
|
||||
from reflex.components.libs.chakra import ChakraComponent
|
||||
@ -33,12 +32,11 @@ class Link(ChakraComponent):
|
||||
return {**super()._get_imports(), **NextLink.create()._get_imports()}
|
||||
|
||||
@classmethod
|
||||
def create(cls, *children, href: Optional[Var] = None, **props) -> Component:
|
||||
def create(cls, *children, **props) -> Component:
|
||||
"""Create a Link component.
|
||||
|
||||
Args:
|
||||
*children: The children of the component.
|
||||
href: The href attribute of the link.
|
||||
**props: The props of the component.
|
||||
|
||||
Raises:
|
||||
@ -47,11 +45,10 @@ class Link(ChakraComponent):
|
||||
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):
|
||||
if props["href"]:
|
||||
if not len(children):
|
||||
raise ValueError("Link without a child will not display")
|
||||
else:
|
||||
# Don't use a NextLink if there is no href.
|
||||
props["as_"] = ""
|
||||
if href:
|
||||
props["href"] = href
|
||||
return super().create(*children, **props)
|
||||
|
@ -166,7 +166,7 @@ class Var(ABC):
|
||||
Returns:
|
||||
The stringified var.
|
||||
"""
|
||||
return self.operation(fn="JSON.stringify")
|
||||
return self.operation(fn="JSON.stringify", type_=str)
|
||||
|
||||
def __hash__(self) -> int:
|
||||
"""Define a hash function for a var.
|
||||
@ -650,7 +650,7 @@ class Var(ABC):
|
||||
Returns:
|
||||
A var representing the logical and.
|
||||
"""
|
||||
return self.operation("&&", other)
|
||||
return self.operation("&&", other, type_=bool)
|
||||
|
||||
def __rand__(self, other: Var) -> Var:
|
||||
"""Perform a logical and.
|
||||
@ -661,7 +661,7 @@ class Var(ABC):
|
||||
Returns:
|
||||
A var representing the logical and.
|
||||
"""
|
||||
return self.operation("&&", other, flip=True)
|
||||
return self.operation("&&", other, type_=bool, flip=True)
|
||||
|
||||
def __or__(self, other: Var) -> Var:
|
||||
"""Perform a logical or.
|
||||
@ -672,7 +672,7 @@ class Var(ABC):
|
||||
Returns:
|
||||
A var representing the logical or.
|
||||
"""
|
||||
return self.operation("||", other)
|
||||
return self.operation("||", other, type_=bool)
|
||||
|
||||
def __ror__(self, other: Var) -> Var:
|
||||
"""Perform a logical or.
|
||||
@ -683,7 +683,7 @@ class Var(ABC):
|
||||
Returns:
|
||||
A var representing the logical or.
|
||||
"""
|
||||
return self.operation("||", other, flip=True)
|
||||
return self.operation("||", other, type_=bool, flip=True)
|
||||
|
||||
def foreach(self, fn: Callable) -> Var:
|
||||
"""Return a list of components. after doing a foreach on this var.
|
||||
|
Loading…
Reference in New Issue
Block a user