From 74efdc153e3b2542cb00c096b12bf47e48b5b9a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Gir=C3=A3o=20Serr=C3=A3o?= <5621605+rodrigogiraoserrao@users.noreply.github.com> Date: Fri, 24 Feb 2023 12:19:16 +0000 Subject: [PATCH] Button can only accept str/Text as label. Fixes: #1870. --- src/textual/widgets/_button.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/textual/widgets/_button.py b/src/textual/widgets/_button.py index 156ba3f1946..f8b22a9694b 100644 --- a/src/textual/widgets/_button.py +++ b/src/textual/widgets/_button.py @@ -4,7 +4,6 @@ from typing import cast import rich.repr -from rich.console import RenderableType from rich.text import Text, TextType from typing_extensions import Literal @@ -145,7 +144,7 @@ class Button(Static, can_focus=True): ACTIVE_EFFECT_DURATION = 0.3 """When buttons are clicked they get the `-active` class for this duration (in seconds)""" - label: reactive[RenderableType] = reactive[RenderableType]("") + label: reactive[TextType] = reactive[TextType]("") """The text label that appears within the button.""" variant = reactive("default") @@ -209,15 +208,14 @@ def watch_variant(self, old_variant: str, variant: str): self.remove_class(f"-{old_variant}") self.add_class(f"-{variant}") - def validate_label(self, label: RenderableType) -> RenderableType: + def validate_label(self, label: TextType) -> TextType: """Parse markup for self.label""" if isinstance(label, str): return Text.from_markup(label) return label - def render(self) -> RenderableType: - label = self.label.copy() - label = Text.assemble(" ", label, " ") + def render(self) -> TextType: + label = Text.assemble(" ", self.label, " ") label.stylize(self.text_style) return label