Fixing Select widget styling

This commit is contained in:
Darren Burns
2024-10-28 10:33:36 +00:00
parent 796a6ae73b
commit b34be61d13
2 changed files with 12 additions and 27 deletions

View File

@@ -261,9 +261,11 @@ class ChangingThemeApp(App[None]):
yield ThemeList(id="theme-list") yield ThemeList(id="theme-list")
with VerticalScroll(id="widget-list") as container: with VerticalScroll(id="widget-list") as container:
container.border_title = "Widget Gallery"
container.can_focus = False container.can_focus = False
yield Select(
[("foo", "foo"), ("bar", "bar"), ("baz", "baz"), ("qux", "qux")]
)
with Collapsible(title="An interesting story."): with Collapsible(title="An interesting story."):
yield Label("Interesting but verbose story.") yield Label("Interesting but verbose story.")
@@ -283,9 +285,6 @@ class ChangingThemeApp(App[None]):
yield Button.error("Error 3") yield Button.error("Error 3")
yield Button.warning("Warning 4") yield Button.warning("Warning 4")
yield Tabs("First tab", "Second tab", "Third tab", "Fourth tab") yield Tabs("First tab", "Second tab", "Third tab", "Fourth tab")
yield Select(
[("foo", "foo"), ("bar", "bar"), ("baz", "baz"), ("qux", "qux")]
)
yield MaskedInput( yield MaskedInput(
template="9999-9999-9999-9999;0", template="9999-9999-9999-9999;0",
) )

View File

@@ -45,22 +45,6 @@ class SelectOverlay(OptionList):
BINDINGS = [("escape", "dismiss", "Dismiss menu")] BINDINGS = [("escape", "dismiss", "Dismiss menu")]
DEFAULT_CSS = """
SelectOverlay {
border: tall $border-blurred;
background: $surface;
color: $foreground;
width: 100%;
padding: 0 1;
}
SelectOverlay:focus {
background-tint: $foreground 5%;
}
SelectOverlay > .option-list--option {
padding: 0 1;
}
"""
@dataclass @dataclass
class Dismiss(Message): class Dismiss(Message):
"""Inform ancestor the overlay should be dismissed.""" """Inform ancestor the overlay should be dismissed."""
@@ -110,7 +94,9 @@ class SelectCurrent(Horizontal):
DEFAULT_CSS = """ DEFAULT_CSS = """
SelectCurrent { SelectCurrent {
border: tall transparent;
color: $foreground; color: $foreground;
background: $surface;
width: 1fr; width: 1fr;
height: auto; height: auto;
padding: 0 2; padding: 0 2;
@@ -215,16 +201,14 @@ class Select(Generic[SelectType], Vertical, can_focus=True):
Select { Select {
height: auto; height: auto;
color: $foreground; color: $foreground;
background: $surface;
border: tall $border-blurred;
.up-arrow { .up-arrow {
display: none; display: none;
} }
&:focus { &:focus > SelectCurrent {
background-tint: $foreground 5%;
border: tall $border; border: tall $border;
background-tint: $foreground 5%;
} }
& > SelectOverlay { & > SelectOverlay {
@@ -235,12 +219,14 @@ class Select(Generic[SelectType], Vertical, can_focus=True):
overlay: screen; overlay: screen;
constrain: none inside; constrain: none inside;
color: $foreground; color: $foreground;
padding: 1 0; border: tall $border-blurred;
background: $surface;
&:focus { &:focus {
border: wide $border;
background-tint: $foreground 5%; background-tint: $foreground 5%;
} }
& > .option-list--option {
padding: 0 1;
}
} }
&.-expanded { &.-expanded {