Skip to content

Commit 1f83f3f

Browse files
committed
fix(option list): fix size when options cleared
Fix the OptionList size not updating correctly after clearing the options. Fixes #5728
1 parent 41a0020 commit 1f83f3f

File tree

3 files changed

+175
-2
lines changed

3 files changed

+175
-2
lines changed

src/textual/widgets/_option_list.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,8 +759,7 @@ def _get_option_render(self, option: Option, style: Style) -> list[Strip]:
759759

760760
def _update_lines(self) -> None:
761761
"""Update internal structures when new lines are added."""
762-
if not self.options or not self.scrollable_content_region:
763-
# No options -- nothing to
762+
if not self.scrollable_content_region:
764763
return
765764

766765
line_cache = self._line_cache
Lines changed: 154 additions & 0 deletions
Loading

tests/snapshot_tests/test_snapshots.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3915,3 +3915,23 @@ def action_remove_options(self) -> None:
39153915
option_list.remove_option_at_index(0)
39163916

39173917
snap_compare(OptionListApp(), press=["x"])
3918+
3919+
3920+
def test_option_list_size_when_options_cleared(snap_compare):
3921+
"""Regression test for https://github.com/Textualize/textual/issues/5728
3922+
3923+
You should see the height of the OptionList has updated correctly after
3924+
its options are cleared.
3925+
"""
3926+
3927+
class OptionListApp(App):
3928+
BINDINGS = [("x", "clear_options", "Clear options")]
3929+
3930+
def compose(self) -> ComposeResult:
3931+
yield OptionList(*[f"Option {n}" for n in range(30)])
3932+
yield Footer()
3933+
3934+
def action_clear_options(self) -> None:
3935+
self.query_one(OptionList).clear_options()
3936+
3937+
snap_compare(OptionListApp(), press=["x"])

0 commit comments

Comments
 (0)