From 68250e6ce3dbe73e0b4b6b4392638df416a60c70 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 22 May 2023 15:25:11 +0100 Subject: [PATCH] Override _remove_option to update the selected values The developer could remove an option that is selected, so we need to catch that this has happened and update the collection of selected values. --- src/textual/widgets/_selection_list.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/textual/widgets/_selection_list.py b/src/textual/widgets/_selection_list.py index 427d0eda6..65032a012 100644 --- a/src/textual/widgets/_selection_list.py +++ b/src/textual/widgets/_selection_list.py @@ -410,3 +410,7 @@ class SelectionList(Generic[SelectionType], OptionList): def get_option(self, option_id: str) -> Selection[SelectionType]: return cast("Selection[SelectionType]", super().get_option(option_id)) + + def _remove_option(self, index: int) -> None: + self._deselect(self.get_option_at_index(index).value) + return super()._remove_option(index)