Improve the `ListView` documentation by explaining the `ListItem`
Closed this issue · 3 comments
TomJGooding commented
I think the ListView
documentation could be improved by explaining the ListItem
.
Here's a simple example adapted from the docs. I don't think it is clear from the documentation how you might get the Label
text when a ListItem
is highlighted:
from textual import on
from textual.app import App, ComposeResult
from textual.widgets import Label, ListItem, ListView
class ListViewExample(App):
CSS = """
Screen {
align: center middle;
}
ListView {
width: 30;
height: auto;
}
"""
def compose(self) -> ComposeResult:
yield ListView(
ListItem(Label("One")),
ListItem(Label("Two")),
ListItem(Label("Three")),
)
@on(ListView.Highlighted)
def notify_highlighted_label(self, event: ListView.Highlighted) -> None:
highlighted = event.item
self.notify(str(highlighted))
if __name__ == "__main__":
app = ListViewExample()
app.run()
github-actions commented
TomJGooding commented
Actually on reflection I don't think this is really necessary. ListItem
is just a widget and querying the children is already covered elsewhere in the docs.
github-actions commented
Don't forget to star the repository!
Follow @textualizeio for Textual updates.