Skip to content

Commit

Permalink
Button can only accept str/Text as label.
Browse files Browse the repository at this point in the history
Fixes: #1870.
  • Loading branch information
rodrigogiraoserrao committed Feb 24, 2023
1 parent 336f000 commit 74efdc1
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/textual/widgets/_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 74efdc1

Please sign in to comment.