diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d3de1f8fe..2175f30dde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Scrolling by page now adds to current position. - Markdown lists have been polished: a selection of bullets, better alignment of numbers, style tweaks https://github.com/Textualize/textual/pull/1832 - Added alternative method of composing Widgets https://github.com/Textualize/textual/pull/1847 +- Buttons no longer accept arbitrary renderables https://github.com/Textualize/textual/issues/1870 ### Removed diff --git a/src/textual/widgets/_button.py b/src/textual/widgets/_button.py index 156ba3f194..f8b22a9694 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