Skip to content

Commit 8d96d83

Browse files
committed
Enhance TemplateSelectModal with default template selection and keyboard navigation
1 parent e515c12 commit 8d96d83

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/template_select_modal.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@ def _load_template_names(self):
2121
def compose(self):
2222
yield Container(
2323
Static("Select a template:"),
24-
Select(options=self.templates, id="template_select"),
24+
Select(
25+
options=self.templates, value=self.templates[1][1], id="template_select"
26+
),
2527
Button("Confirm", variant="primary", id="confirm"),
2628
Button("Cancel", variant="default", id="cancel"),
2729
classes="template-modal",
2830
)
2931

32+
def _on_mount(self, event):
33+
self.focus_next("#confirm")
34+
return super()._on_mount(event)
35+
3036
def on_button_pressed(self, event: Button.Pressed) -> None:
3137
if event.button.id == "confirm":
3238
selected = self.query_one("#template_select").value
@@ -39,3 +45,11 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
3945
self.dismiss((False, None))
4046
else:
4147
self.dismiss((False, None))
48+
49+
def _on_key(self, event):
50+
if event.key == "escape":
51+
self.dismiss((False, None))
52+
# stop the bubbling of the event
53+
event.stop()
54+
return
55+
return super()._on_key(event)

0 commit comments

Comments
 (0)