Allow for storing the initial state of a selection

This commit is contained in:
Dave Pearson
2023-05-24 10:09:21 +01:00
parent 2e540548f8
commit da1faf8fb9

View File

@@ -35,6 +35,7 @@ class Selection(Generic[SelectionType], Option):
self,
prompt: TextType,
value: SelectionType,
initial_state: bool = False,
id: str | None = None,
disabled: bool = False,
):
@@ -52,12 +53,19 @@ class Selection(Generic[SelectionType], Option):
super().__init__(prompt.split()[0], id, disabled)
self._value: SelectionType = value
"""The value associated with the selection."""
self._initial_state: bool = initial_state
"""The initial selected state for the selection."""
@property
def value(self) -> SelectionType:
"""The value for this selection."""
return self._value
@property
def initial_state(self) -> bool:
"""The initial selected state for the selection."""
return self._initial_state
class SelectionList(Generic[SelectionType], OptionList):
"""A vertical selection list that allows making multiple selections."""