From 258180c996ad2a98eab1883a492bcb1a994656c2 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 15 May 2023 10:25:30 +0100 Subject: [PATCH] Add a selected flag to the Selection --- src/textual/widgets/_selection_list.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/textual/widgets/_selection_list.py b/src/textual/widgets/_selection_list.py index 0b620fb67..4a3b05fc7 100644 --- a/src/textual/widgets/_selection_list.py +++ b/src/textual/widgets/_selection_list.py @@ -19,6 +19,7 @@ class Selection(Generic[SelectionType], Option): self, value: SelectionType, prompt: RenderableType, + selected: bool = False, id: str | None = None, disabled: bool = False, ): @@ -27,11 +28,18 @@ class Selection(Generic[SelectionType], Option): Args: value: The value for the selection. prompt: The prompt for the selection. + selected: The initial selected state for the selection. id: The optional ID for the selection. disabled: The initial enabled/disabled state. Enabled by default. """ super().__init__(prompt, id, disabled) self._value: SelectionType = value + self._selected: bool = selected + + @property + def selected(self) -> bool: + """The selected state of this selection.""" + return self._selected class SelectionList(Generic[SelectionType], OptionList):