fix(option list): fix size when options removed
Fix the OptionList size not updating correctly after removing options. Fixes https://github.com/Textualize/textual/issues/5728#issuecomment-2791776954
This commit is contained in:
parent
fd6cb52c1d
commit
41a002080a
3 changed files with 178 additions and 1 deletions
|
|
@ -534,7 +534,7 @@ class OptionList(ScrollView, can_focus=True):
|
|||
del self._id_to_option[option._id]
|
||||
del self._option_to_index[option]
|
||||
self.highlighted = self.highlighted
|
||||
self.refresh()
|
||||
self._clear_caches()
|
||||
return self
|
||||
|
||||
def _pre_remove_option(self, option: Option, index: int) -> None:
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 24 KiB |
|
|
@ -3893,3 +3893,25 @@ def test_notifications_markup(snap_compare):
|
|||
)
|
||||
|
||||
snap_compare(ToastApp())
|
||||
|
||||
|
||||
def test_option_list_size_when_options_removed(snap_compare):
|
||||
"""Regression test for https://github.com/Textualize/textual/issues/5728
|
||||
|
||||
You should see the height of the OptionList has updated correctly after
|
||||
half of its options are removed.
|
||||
"""
|
||||
|
||||
class OptionListApp(App):
|
||||
BINDINGS = [("x", "remove_options", "Remove options")]
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield OptionList(*[f"Option {n}" for n in range(30)])
|
||||
yield Footer()
|
||||
|
||||
def action_remove_options(self) -> None:
|
||||
option_list = self.query_one(OptionList)
|
||||
for _ in range(15):
|
||||
option_list.remove_option_at_index(0)
|
||||
|
||||
snap_compare(OptionListApp(), press=["x"])
|
||||
|
|
|
|||
Loading…
Reference in a new issue