|
| 1 | +# List View |
| 2 | + |
| 3 | +Displays a vertical list of `ListItem`s which can be highlighted and selected. |
| 4 | +Supports keyboard navigation. |
| 5 | + |
| 6 | +- [x] Focusable |
| 7 | +- [x] Container |
| 8 | + |
| 9 | +## Example |
| 10 | + |
| 11 | +The example below shows an app with a simple `ListView`. |
| 12 | + |
| 13 | +=== "Output" |
| 14 | + |
| 15 | + ```{.textual path="docs/examples/widgets/list_view.py"} |
| 16 | + ``` |
| 17 | + |
| 18 | +=== "list_view.py" |
| 19 | + |
| 20 | + ```python |
| 21 | + --8<-- "docs/examples/widgets/list_view.py" |
| 22 | + ``` |
| 23 | + |
| 24 | +## Reactive Attributes |
| 25 | + |
| 26 | +| Name | Type | Default | Description | |
| 27 | +|---------|-------|---------|---------------------------------| |
| 28 | +| `index` | `int` | `0` | The currently highlighted index | |
| 29 | + |
| 30 | +## Messages |
| 31 | + |
| 32 | +### Highlighted |
| 33 | + |
| 34 | +The `ListView.Highlighted` message is emitted when the highlight changes. |
| 35 | +This happens when you use the arrow keys on your keyboard and when you |
| 36 | +click on a list item. |
| 37 | + |
| 38 | +- [x] Bubbles |
| 39 | + |
| 40 | +#### Attributes |
| 41 | + |
| 42 | +| attribute | type | purpose | |
| 43 | +|-----------|------------|--------------------------------| |
| 44 | +| `item` | `ListItem` | The item that was highlighted. | |
| 45 | + |
| 46 | +### Selected |
| 47 | + |
| 48 | +The `ListView.Selected` message is emitted when a list item is selected. |
| 49 | +You can select a list item by pressing ++enter++ while it is highlighted, |
| 50 | +or by clicking on it. |
| 51 | + |
| 52 | +- [x] Bubbles |
| 53 | + |
| 54 | +#### Attributes |
| 55 | + |
| 56 | +| attribute | type | purpose | |
| 57 | +|-----------|------------|-----------------------------| |
| 58 | +| `item` | `ListItem` | The item that was selected. | |
| 59 | + |
| 60 | + |
| 61 | +### ChildrenUpdated |
| 62 | + |
| 63 | +The `ListView.ChildrenUpdated` message is emitted when the elements in the `ListView` |
| 64 | +are changed (e.g. a child is added, or the list is cleared). |
| 65 | + |
| 66 | +- [x] Bubbles |
| 67 | + |
| 68 | +#### Attributes |
| 69 | + |
| 70 | +| attribute | type | purpose | |
| 71 | +|------------|------------------|---------------------------| |
| 72 | +| `children` | `list[ListItem]` | The new ListView children | |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | +## See Also |
| 77 | + |
| 78 | +* [ListView](../api/list_view.md) code reference |
0 commit comments