Skip to content

Commit 497ad5f

Browse files
committed
Treat focus loss the same as pressing enter on most inputs.
1 parent 5cc52e6 commit 497ad5f

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

tests/installer/panels/basic_info_panel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from .panel import Panel
66
from ..log import log
7-
from ..widgets import ShortcutButton
7+
from ..widgets import ShortcutButton, MInput
88

99
from textual import on
1010
from textual.containers import Vertical, Horizontal
@@ -17,8 +17,8 @@
1717

1818
class BasicInfoPanel(Panel):
1919
def _build_widgets(self) -> Widget:
20-
self.name_input = Input(placeholder='Enter machine name', id='name-input')
21-
self.email_input = Input(placeholder='Enter email', id='email-input')
20+
self.name_input = MInput(placeholder='Enter machine name', id='name-input')
21+
self.email_input = MInput(placeholder='Enter email', id='email-input')
2222
return Vertical(
2323
Label('Some basic information', classes='header'),
2424
Label('The name should be something descriptive, such as '

tests/installer/panels/batch_scheduler_panel.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ..dialogs import TestJobsDialog
88
from ..log import log
99
from ..state import Attr, State
10-
from ..widgets import MSelect, ShortcutButton
10+
from ..widgets import MSelect, ShortcutButton, MInput
1111

1212
from textual import on
1313
from textual.app import ComposeResult
@@ -246,20 +246,20 @@ def _build_widgets(self) -> Widget:
246246
),
247247
Vertical(
248248
Label('Account/project:', classes='form-label'),
249-
Input(id='account-input'),
249+
MInput(id='account-input'),
250250
classes='bs-col-2 form-row batch-valid'
251251
),
252252
classes='w-100 form-row', id='batch-system-group-1'
253253
),
254254
Horizontal(
255255
Vertical(
256256
Label('Queue:', classes='form-label'),
257-
Input(id='queue-input'),
257+
MInput(id='queue-input'),
258258
classes='bs-col-1 form-row batch-valid'
259259
),
260260
Vertical(
261261
Label('Multi-node queue:', classes='form-label'),
262-
Input(id='mqueue-input'),
262+
MInput(id='mqueue-input'),
263263
classes='bs-col-2 form-row batch-valid'
264264
),
265265
Checkbox('Run [b bright_yellow]t[/b bright_yellow]est job', value=False,

tests/installer/widgets.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from textual.app import RenderResult
22
from typing import Optional, Any
33
from textual.binding import Binding
4-
from textual.widgets import Select, Button, LoadingIndicator
4+
from textual.events import Blur
5+
from textual.widgets import Select, Button, LoadingIndicator, Input
56

67

78
class MSelect(Select[str]):
@@ -51,3 +52,13 @@ def render(self) -> RenderResult:
5152
text = super().render()
5253
text.plain = '......' # type: ignore
5354
return text
55+
56+
57+
class MInput(Input):
58+
# A version of input that also runs the submit action on blur (seems silly from a UI
59+
# perspective to allow moving the focus from this input without the value being
60+
# committed to whatever model is underneath.
61+
62+
async def _on_blur(self, event: Blur) -> None: # type: ignore
63+
super()._on_blur(event)
64+
await self.action_submit()

0 commit comments

Comments
 (0)