This commit is contained in:
2026-01-11 03:34:35 -08:00
parent 5985a8306a
commit df2bb76390
2 changed files with 74 additions and 40 deletions

View File

@@ -53,13 +53,17 @@ class SelectionModal(ModalScreen[str]):
with Container(id="selection-container"):
yield Static(self.selection_title, classes="selection-title")
with ScrollableContainer():
for opt in self.options:
yield Button(opt, id=f"opt-{opt}", classes="selection-button")
for i, opt in enumerate(self.options):
yield Button(opt, id=f"opt-{i}", classes="selection-button")
yield Button("Cancel", id="selection-cancel")
def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == "selection-cancel":
self.dismiss("")
elif event.button.id and event.button.id.startswith("opt-"):
selection = event.button.id.replace("opt-", "")
self.dismiss(selection)
try:
idx = int(event.button.id.replace("opt-", ""))
selection = self.options[idx]
self.dismiss(selection)
except (ValueError, IndexError):
pass