mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Allow for storing the initial state of a selection
This commit is contained in:
@@ -35,6 +35,7 @@ class Selection(Generic[SelectionType], Option):
|
|||||||
self,
|
self,
|
||||||
prompt: TextType,
|
prompt: TextType,
|
||||||
value: SelectionType,
|
value: SelectionType,
|
||||||
|
initial_state: bool = False,
|
||||||
id: str | None = None,
|
id: str | None = None,
|
||||||
disabled: bool = False,
|
disabled: bool = False,
|
||||||
):
|
):
|
||||||
@@ -52,12 +53,19 @@ class Selection(Generic[SelectionType], Option):
|
|||||||
super().__init__(prompt.split()[0], id, disabled)
|
super().__init__(prompt.split()[0], id, disabled)
|
||||||
self._value: SelectionType = value
|
self._value: SelectionType = value
|
||||||
"""The value associated with the selection."""
|
"""The value associated with the selection."""
|
||||||
|
self._initial_state: bool = initial_state
|
||||||
|
"""The initial selected state for the selection."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def value(self) -> SelectionType:
|
def value(self) -> SelectionType:
|
||||||
"""The value for this selection."""
|
"""The value for this selection."""
|
||||||
return self._value
|
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):
|
class SelectionList(Generic[SelectionType], OptionList):
|
||||||
"""A vertical selection list that allows making multiple selections."""
|
"""A vertical selection list that allows making multiple selections."""
|
||||||
|
|||||||
Reference in New Issue
Block a user