Skip to content

Setting own TextArea style doesn't work (base_style doesn't have a color attribute) #6482

@mistotebe

Description

@mistotebe

The bug

Trying to use a TextAreaTheme with a base_style doesn't seem to work, TextArea._set_theme() seems to expect that a Style object has a color attribute which isn't the case.

Either it should be a RichStyle or maybe it wants to use base_style.foreground?

from textual.app import App, ComposeResult
from textual.style import Style
from textual.widgets import TextArea
from textual.widgets.text_area import TextAreaTheme

class MyTextArea(TextArea):
    MY_THEME = TextAreaTheme(name="mytheme", base_style=Style("white", "default"))

    def on_mount(self) -> None:
        self.register_theme(self.MY_THEME)
        self.theme = "mytheme"

class MyTUI(App):
    def compose(self) -> ComposeResult:
        yield MyTextArea()

if __name__ == "__main__":
    MyTUI().run()

->

.../tester.py:11 in on_mount
AttributeError: 'Style' object has no attribute 'color'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions