Skip to content

How changed parent border when child-widget focused use css selector? #4756

Answered by TomJGooding
Yurii-huang asked this question in Q&A
Discussion options

You must be logged in to vote

If I've understood your question correctly, you can use the :focus-within pseudo selector which matches widgets with a focused child widget. https://textual.textualize.io/guide/CSS/#pseudo-classes

from textual.app import App, ComposeResult
from textual.widget import Widget
from textual.widgets import Input


class FocusWithinWidget(Widget):
    DEFAULT_CSS = """
    FocusWithinWidget {
        height: auto;
        border: tall red;
        margin: 1;
    }

    FocusWithinWidget:focus-within {
        border: tall green;
    }
    """

    def compose(self) -> ComposeResult:
        yield Input()
        yield Input()


class ExampleApp(App):
    def compose(self) -> ComposeResult:
        

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Yurii-huang
Comment options

Answer selected by Yurii-huang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants