mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge pull request #5795 from rephorm/fork
Refresh layout of option lists on add.
This commit is contained in:
@@ -373,6 +373,7 @@ class OptionList(ScrollView, can_focus=True):
|
||||
self._id_to_option[option._id] = option
|
||||
add_option(option)
|
||||
if self.is_mounted:
|
||||
self.refresh(layout=self.styles.auto_dimensions)
|
||||
self._update_lines()
|
||||
return self
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 28 KiB |
@@ -10,6 +10,8 @@ from textual.widgets.option_list import Option
|
||||
|
||||
class OptionListApp(App[None]):
|
||||
|
||||
BINDINGS = [("a", "add", "add")]
|
||||
|
||||
def compose( self ) -> ComposeResult:
|
||||
with Horizontal():
|
||||
yield OptionList(
|
||||
@@ -20,6 +22,7 @@ class OptionListApp(App[None]):
|
||||
)
|
||||
yield OptionList(id="later-individual")
|
||||
yield OptionList(id="later-at-once")
|
||||
yield OptionList(id="after-mount")
|
||||
|
||||
def on_mount(self) -> None:
|
||||
options: list[None | str | Text | Option] = [
|
||||
@@ -41,5 +44,15 @@ class OptionListApp(App[None]):
|
||||
])
|
||||
option_list.highlighted = 0
|
||||
|
||||
def action_add(self):
|
||||
option_list = self.query_one("#after-mount", OptionList)
|
||||
option_list.add_options([
|
||||
"One",
|
||||
Option("Two"),
|
||||
None,
|
||||
Text.from_markup("[red]Three[/]"),
|
||||
])
|
||||
option_list.highlighted = 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
OptionListApp().run()
|
||||
|
||||
@@ -505,7 +505,7 @@ def test_option_list_tables(snap_compare):
|
||||
|
||||
|
||||
def test_option_list_build(snap_compare):
|
||||
assert snap_compare(SNAPSHOT_APPS_DIR / "option_list.py")
|
||||
assert snap_compare(SNAPSHOT_APPS_DIR / "option_list.py", press=["a"])
|
||||
|
||||
|
||||
def test_option_list_replace_prompt_from_single_line_to_single_line(snap_compare):
|
||||
|
||||
Reference in New Issue
Block a user