diff --git a/CHANGELOG.md b/CHANGELOG.md index fbc8be178..e77683ec0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - The DataTable cursor is now scrolled into view when the cursor coordinate is changed programmatically https://github.com/Textualize/textual/issues/2459 - run_worker exclusive parameter is now `False` by default https://github.com/Textualize/textual/pull/2470 +### Added + +- Added the `control` property to messages + - `OptionList.OptionHighlighted` and `OptionList.OptionSelected` + ## [0.23.0] - 2023-05-03 ### Fixed diff --git a/docs/widgets/option_list.md b/docs/widgets/option_list.md index 2c4a80789..a489e6b4f 100644 --- a/docs/widgets/option_list.md +++ b/docs/widgets/option_list.md @@ -90,18 +90,7 @@ tables](https://rich.readthedocs.io/en/latest/tables.html): - [OptionList.OptionHighlight][textual.widgets.OptionList.OptionHighlighted] - [OptionList.OptionSelected][textual.widgets.OptionList.OptionSelected] -Both of the messages above inherit from this common base, which makes -available the following properties relating to the `OptionList` and the -related `Option`: - -### Common message properties - -Both of the above messages provide the following properties: - -#### ::: textual.widgets.OptionList.OptionMessage.option -#### ::: textual.widgets.OptionList.OptionMessage.option_id -#### ::: textual.widgets.OptionList.OptionMessage.option_index -#### ::: textual.widgets.OptionList.OptionMessage.option_list +Both of the messages above inherit from the common base [`OptionList`][textual.widgets.OptionList.OptionMessage], so refer to its documentation to see what attributes are available. ## Bindings diff --git a/src/textual/widgets/_option_list.py b/src/textual/widgets/_option_list.py index 97744971a..c65eae740 100644 --- a/src/textual/widgets/_option_list.py +++ b/src/textual/widgets/_option_list.py @@ -253,6 +253,15 @@ class OptionList(ScrollView, can_focus=True): self.option_index: int = index """The index of the option that the message relates to.""" + @property + def control(self) -> OptionList: + """The option list that sent the message. + + This is an alias for [`OptionMessage.option_list`][textual.widgets.OptionList.OptionMessage.option_list] + and is used by the [`on`][textual.on] decorator. + """ + return self.option_list + def __rich_repr__(self) -> Result: yield "option_list", self.option_list yield "option", self.option