How changed parent border when child-widget focused use css selector? #4756
-
Some components are drawn through the current component, and when it has a focus, the topmost border (i.e. the border of the current component) can change color based on whether there is a focus. And in component overlay construction, when selecting sub components, I change the top-level front node border. What should I do? Can CSS selectors do it?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If I've understood your question correctly, you can use the 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:
yield FocusWithinWidget()
yield FocusWithinWidget()
yield FocusWithinWidget()
if __name__ == "__main__":
app = ExampleApp()
app.run() |
Beta Was this translation helpful? Give feedback.
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