Add default Esc
binding to unfocus Input
?
#2290
Replies: 3 comments 4 replies
-
What would unfocus mean on a screen of five inputs, a couple of checkboxes, a radio set or two plus a collection of buttons? What would be special about Input here, and what would unfocus mean exactly? |
Beta Was this translation helpful? Give feedback.
-
I like my Textual apps to be keyboard-first and normally have some 'shortcut' bindings to quickly focus parts of the app (quick example below). I suppose what's special about the But fair point about what exactly it would mean to 'unfocus'... from textual.app import App, ComposeResult
from textual.containers import Center
from textual.widgets import Button, Checkbox, Footer, Input, RadioButton
class ExampleApp(App):
BINDINGS = [
("i", "focus_input", "Input"),
("c", "focus_checkbox", "Checkbox"),
("r", "focus_radio", "Radio"),
("b", "focus_button", "Button"),
]
CSS = """
Screen {
align: center middle;
}
Input {
width: 30;
}
Checkbox {
height: 3;
content-align: center middle;
}
RadioButton {
height: 3;
content-align: center middle;
}
"""
def compose(self) -> ComposeResult:
yield Center(Input(placeholder="Enter some text..."))
yield Center(Checkbox("Check me!"))
yield Center(RadioButton("Choose me!"))
yield Center(Button("Press me!"))
yield Footer()
def action_focus_input(self) -> None:
self.query_one(Input).focus()
def action_focus_checkbox(self) -> None:
self.query_one(Checkbox).focus()
def action_focus_radio(self) -> None:
self.query_one(RadioButton).focus()
def action_focus_button(self) -> None:
self.query_one(Button).focus() |
Beta Was this translation helpful? Give feedback.
-
@TomJGooding, I'm following a similar philosophy. +1 for having BTW, the To build keyboard-first apps, I think we at least lack a couple of things:
|
Beta Was this translation helpful? Give feedback.
-
Any time I've wanted an
Input
widget in my Textual app, I've had to subclass it to add anEsc
binding to allow unfocusing it from the keyboard.This feels like it should be the default behaviour to me, but maybe I'm overlooking something - so posting here to see if anyone else would find this useful?
Beta Was this translation helpful? Give feedback.
All reactions