mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge pull request #2567 from davep/issue/2557/select-update
Fix clearing an OptionList
This commit is contained in:
@@ -627,11 +627,17 @@ class OptionList(ScrollView, can_focus=True):
|
|||||||
"""
|
"""
|
||||||
self._contents.clear()
|
self._contents.clear()
|
||||||
self._options.clear()
|
self._options.clear()
|
||||||
self._refresh_content_tracking(force=True)
|
|
||||||
self.highlighted = None
|
self.highlighted = None
|
||||||
self._mouse_hovering_over = None
|
self._mouse_hovering_over = None
|
||||||
self.virtual_size = Size(self.scrollable_content_region.width, 0)
|
self.virtual_size = Size(self.scrollable_content_region.width, 0)
|
||||||
self.refresh()
|
# TODO: See https://github.com/Textualize/textual/issues/2582 -- it
|
||||||
|
# should not be necessary to do this like this here; ideally here in
|
||||||
|
# clear_options it would be a forced refresh, and also in a
|
||||||
|
# `on_show` it would be the same (which, I think, would actually
|
||||||
|
# solve the problem we're seeing). But, until such a time as we get
|
||||||
|
# to the bottom of 2582... this seems to delay the refresh enough
|
||||||
|
# that things fall into place.
|
||||||
|
self._request_content_tracking_refresh()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def _set_option_disabled(self, index: int, disabled: bool) -> Self:
|
def _set_option_disabled(self, index: int, disabled: bool) -> Self:
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
21
tests/snapshot_tests/snapshot_apps/select_rebuild.py
Normal file
21
tests/snapshot_tests/snapshot_apps/select_rebuild.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
"""Test https://github.com/Textualize/textual/issues/2557"""
|
||||||
|
|
||||||
|
from textual.app import App, ComposeResult
|
||||||
|
from textual.widgets import Select, Button
|
||||||
|
|
||||||
|
|
||||||
|
class SelectRebuildApp(App[None]):
|
||||||
|
|
||||||
|
def compose(self) -> ComposeResult:
|
||||||
|
yield Select[int]((("1", 1), ("2", 2)))
|
||||||
|
yield Button("Rebuild")
|
||||||
|
|
||||||
|
def on_button_pressed(self):
|
||||||
|
self.query_one(Select).set_options((
|
||||||
|
("This", 0), ("Should", 1), ("Be", 2),
|
||||||
|
("What", 3), ("Goes", 4), ("Into",5),
|
||||||
|
("The", 6), ("Snapshit", 7)
|
||||||
|
))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
SelectRebuildApp().run()
|
||||||
@@ -493,3 +493,12 @@ def test_quickly_change_tabs(snap_compare):
|
|||||||
def test_fr_unit_with_min(snap_compare):
|
def test_fr_unit_with_min(snap_compare):
|
||||||
# https://github.com/Textualize/textual/issues/2378
|
# https://github.com/Textualize/textual/issues/2378
|
||||||
assert snap_compare(SNAPSHOT_APPS_DIR / "fr_with_min.py")
|
assert snap_compare(SNAPSHOT_APPS_DIR / "fr_with_min.py")
|
||||||
|
|
||||||
|
|
||||||
|
def test_select_rebuild(snap_compare):
|
||||||
|
# https://github.com/Textualize/textual/issues/2557
|
||||||
|
assert snap_compare(
|
||||||
|
SNAPSHOT_APPS_DIR / "select_rebuild.py",
|
||||||
|
press=["tab", "space", "escape", "tab", "enter", "tab", "space"]
|
||||||
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user