Skip to content

Commit

Permalink
Merge pull request #4786 from Textualize/fix-select-remove
Browse files Browse the repository at this point in the history
Fix select remove
  • Loading branch information
willmcgugan authored Jul 24, 2024
2 parents 252e9e7 + bcf20b6 commit 0e36ac8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

- Fixed issues in Kitty terminal after exiting app https://github.com/Textualize/textual/issues/4779
- Fixed exception when removing Selects https://github.com/Textualize/textual/pull/4786

## [0.73.0] - 2024-07-18

Expand Down
6 changes: 5 additions & 1 deletion src/textual/widgets/_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,11 @@ def _on_mount(self, _event: events.Mount) -> None:

def _watch_expanded(self, expanded: bool) -> None:
"""Display or hide overlay."""
overlay = self.query_one(SelectOverlay)
try:
overlay = self.query_one(SelectOverlay)
except NoMatches:
# The widget has likely been removed
return
self.set_class(expanded, "-expanded")
if expanded:
overlay.focus()
Expand Down
25 changes: 25 additions & 0 deletions tests/select/test_remove.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from textual.app import App, ComposeResult
from textual.widgets import Header, Select

LINES = """I must not fear.
Fear is the mind-killer.
Fear is the little-death that brings total obliteration.
I will face my fear.
I will permit it to pass over me and through me.""".splitlines()


async def test_select_remove():
# Regression test for https://github.com/Textualize/textual/issues/4782
class SelectApp(App):
def compose(self) -> ComposeResult:
self.select = Select((line, line) for line in LINES)
self.select.watch_value = self.on_select
yield Header()
yield self.select

def on_select(self):
self.select.remove()

app = SelectApp()
async with app.run_test() as pilot:
await pilot.press("enter", "down", "down", "enter")

0 comments on commit 0e36ac8

Please sign in to comment.