Skip to content

Commit

Permalink
Fix clear_options() for SelectionList
Browse files Browse the repository at this point in the history
  • Loading branch information
nmay231 committed Aug 8, 2023
1 parent 5a662e6 commit 36ff32b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/textual/widgets/_selection_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,3 +694,12 @@ def add_option(
SelectionError: If the selection option is of the wrong form.
"""
return self.add_options([item])

def clear_options(self) -> Self:
"""Clear the content of the selection list.
Returns:
The `SelectionList` instance.
"""
self._selected.clear()
return super().clear_options()
7 changes: 6 additions & 1 deletion tests/selection_list/test_selection_list_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import pytest
from rich.text import Text

from textual.app import App, ComposeResult
from textual.widgets import SelectionList
from textual.widgets.option_list import Option
Expand Down Expand Up @@ -98,3 +97,9 @@ async def test_add_non_selections() -> None:
selections.add_option(("Nope",))
with pytest.raises(SelectionError):
selections.add_option(("Nope", 0, False, 23))

async def test_clear_options() -> None:
async with SelectionListApp().run_test() as pilot:
selections = pilot.app.query_one(SelectionList)
selections.clear_options()
assert selections.selected == []

0 comments on commit 36ff32b

Please sign in to comment.