Skip to content

TextArea background in css theme becomes "sticky" after setting a non-css theme #5964

@davep

Description

@davep

The description for the css theme of the TextArea widget suggests that, when it is used, the background of the TextArea will be whatever the background styling is for that widget. Out of the box this is the case. With TextArea.theme set to css you can change the background and that's the background for the TextArea.

However, if you change the TextArea.theme to something other than css, then change it back to css, the background of that TextArea is no longer responsive to a change in background; it gets stuck with whatever the background colour was for the last theme that wasn't css.

To illustrate:

from pathlib import Path

from textual import on
from textual.app import App, ComposeResult
from textual.containers import Vertical
from textual.widgets import Button, TextArea

class TextAreaThemeApp(App[None]):

    CSS = """
    Screen {
        layout: horizontal;
        Vertical {
            width: auto;
        }
    }
    """

    def compose(self) -> ComposeResult:
        with Vertical():
            yield Button("github_light + textual-light", id="light")
            yield Button("CSS + textual-dark", id="default")
        with Vertical():
            yield TextArea(Path(__file__).read_text(), language="python", id="sticky")
            yield TextArea(Path(__file__).read_text(), language="python")

    @on(Button.Pressed, "#light")
    def _go_light(self) -> None:
        self.theme = "textual-light"
        self.query_one("#sticky", TextArea).theme = "github_light"

    @on(Button.Pressed, "#default")
    def _go_css(self) -> None:
        self.theme = "textual-dark"
        self.query_one("#sticky", TextArea).theme = "css"

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

On startup the app looks like this:

Image

After pressing the "gitub_light + textual-light" button it looks like this:

Image

The top TextArea is using github_light as its theme and the bottom is using css still. Everything looks as we'd expect. Now if we press the CSS + textual-dark button, we get this:

Image

In this case the top TextArea, despite being themed as css, still has the github_light background.

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