Handle Var passed to rx.toast

If the user provides a `Var` for `message` then apply it as `props["title"]` to
avoid a var operations error.
This commit is contained in:
Masen Furer 2024-11-20 14:12:15 -08:00
parent 681b616000
commit 85a9cef377
No known key found for this signature in database
GPG Key ID: 2AE2BD5531FF94F4

View File

@ -251,7 +251,9 @@ class Toaster(Component):
"Toaster component must be created before sending a toast. (use `rx.toast.provider()`)"
)
toast_command = f"{toast_ref}.{level}" if level is not None else toast_ref
if message == "" and ("title" not in props or "description" not in props):
if isinstance(message, Var):
props.setdefault("title", message)
elif message == "" and ("title" not in props and "description" not in props):
raise ValueError("Toast message or title or description must be provided.")
if props:
args = LiteralVar.create(ToastProps(component_name="rx.toast", **props)) # type: ignore