-
Notifications
You must be signed in to change notification settings - Fork 797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSS Inheritance with Nested Pseudo-Selectors #5206
Comments
The type in the CSS is the name of the class when it was defined. By styling To create a custom widget, you will need to create a new name (don't call it Input again) and style that. class MyInput(Input):
DEFAULT_CSS = """
MyWidget {
...
}
"""
""" This will ensure that the rules you add in If you need further help, please include a fully working MRE as requested...
|
Thank you very much for the quick reply. I had already suspected that the problem could be a naming conflict. Unfortunately, the problem exists independently of this. Rather, it is noticeable that there are no problems (even when named as |
I will need a fully working example to assist you further. |
from textual.app import App
from textual.widgets import Input
class MyInputNested(Input):
DEFAULT_CSS = """
MyInputNested {
border: none;
padding: 1 2;
margin-bottom: 1;
&:focus {
border: none;
}
}
"""
class MyInputNestedSubclass(MyInputNested):
DEFAULT_CSS = """
MyInputNestedSubclass {
padding: 0 2;
height: auto;
}
"""
class MyInput(Input):
DEFAULT_CSS = """
MyInput {
border: none;
padding: 1 2;
margin-bottom: 1;
}
MyInput:focus {
border: none;
}
"""
class MyInputSubclass(MyInput):
DEFAULT_CSS = """
MyInputSubclass {
padding: 0 2;
height: auto;
}
"""
class BugDemo(App):
def compose(self):
yield MyInputNested(placeholder="MyInputNested")
yield MyInputNestedSubclass(placeholder="MyInputNestedSubclass")
yield MyInput(placeholder="MyInput")
yield MyInputSubclass(placeholder="MyInputSubclass")
if __name__ == "__main__":
app = BugDemo()
app.run() |
Oddly the nested version only stops working if you add an instance of its subclass to the app. |
You're running quite an old version of Textual, have you tried upgrading? Because I can't seem to reproduce this with the latest version. |
You are absolutely right, should have checked that first. The bug seems to be fixed with the current version. |
Report
When extending Textual's
Input
widget with custom CSS using nested selectors, child classes do not properly inherit all CSS rules, specifically those within pseudo-selectors and modifier classes (:hover
is working). The issue manifests when using the nested&
syntax for pseudo-selectors and modifiers. However, the same CSS rules work correctly when written with non-nested syntax.Reproduction
Expectation
InlineInput
widget should inherit all CSS rules from its parent classInlineInput
should have no border, as specified in the parent's&:focus
ruleBehavior
InlineInput
widget shows a border when focused&:hover
)Input:focus
instead of&:focus
)Diagnostics
Versions
Python
Operating System
Terminal
Rich Console options
The text was updated successfully, but these errors were encountered: