diff --git a/docs/examples/widgets/list_view.css b/docs/examples/widgets/list_view.css new file mode 100644 index 000000000..9f85bc875 --- /dev/null +++ b/docs/examples/widgets/list_view.css @@ -0,0 +1,13 @@ +Screen { + align: center middle; +} + +ListView { + width: 30; + height: auto; + margin: 2 2; +} + +Label { + padding: 1 2; +} diff --git a/docs/examples/widgets/list_view.py b/docs/examples/widgets/list_view.py new file mode 100644 index 000000000..aeaae3513 --- /dev/null +++ b/docs/examples/widgets/list_view.py @@ -0,0 +1,17 @@ +from textual.app import App, ComposeResult +from textual.widgets import ListView, ListItem, Label, Footer + + +class ListViewExample(App): + def compose(self) -> ComposeResult: + yield ListView( + ListItem(Label("One")), + ListItem(Label("Two")), + ListItem(Label("Three")), + ) + yield Footer() + + +app = ListViewExample(css_path="list_view.css") +if __name__ == "__main__": + app.run() diff --git a/src/textual/widgets/_list_item.py b/src/textual/widgets/_list_item.py index 59844ed67..0d4cee285 100644 --- a/src/textual/widgets/_list_item.py +++ b/src/textual/widgets/_list_item.py @@ -15,7 +15,10 @@ class ListItem(Widget, can_focus=False): ListItem > Widget :hover { background: $boost; } - ListItem.--highlight { + ListView ListItem.--highlight { + background: $accent 50%; + } + ListView:focus ListItem.--highlight { background: $accent; } ListItem > Widget {