You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/input.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -113,9 +113,16 @@ The app splits the screen in to quarters, with a `RichLog` widget in each quarte
113
113
114
114
You can move focus by pressing the ++tab++ key to focus the next widget. Pressing ++shift+tab++ moves the focus in the opposite direction.
115
115
116
+
### Focusable widgets
117
+
118
+
Each widget has a boolean `can_focus` attribute which determines if it is capable of receiving focus.
119
+
Note that `can_focus=True` does not mean the widget will _always_ be focusable.
120
+
For example, a disabled widget cannot receive focus even if `can_focus` is `True`.
121
+
116
122
### Controlling focus
117
123
118
124
Textual will handle keyboard focus automatically, but you can tell Textual to focus a widget by calling the widget's [focus()][textual.widget.Widget.focus] method.
125
+
By default, Textual will focus the first focusable widget when the app starts.
119
126
120
127
### Focus events
121
128
@@ -154,6 +161,9 @@ Note how the footer displays bindings and makes them clickable.
154
161
Multiple keys can be bound to a single action by comma-separating them.
155
162
For example, `("r,t", "add_bar('red')", "Add Red")` means both ++r++ and ++t++ are bound to `add_bar('red')`.
156
163
164
+
When you press a key, Textual will first check for a matching binding in the `BINDINGS` list of the currently focused widget.
165
+
If no match is found, it will search upwards through the DOM all the way up to the `App` looking for a match.
166
+
157
167
### Binding class
158
168
159
169
The tuple of three strings may be enough for simple bindings, but you can also replace the tuple with a [Binding][textual.binding.Binding] instance which exposes a few more options.
1. Associates presses of ++up++ or ++k++ with the `change_count` action, passing `1` as the argument to increment the count. The final argument ("Increment") is a user-facing label displayed in the footer when this binding is active.
241
+
2. Called when the binding is triggered. Take care to add the `action_` prefix to the method name.
242
+
243
+
=== "counter.tcss"
244
+
245
+
```css title="counter.tcss"
246
+
--8<-- "docs/examples/guide/widgets/counter.tcss"
247
+
```
248
+
249
+
1. These styles are applied only when the widget has focus.
In previous examples we've set strings as content for Widgets. You can also use special objects called [renderables](https://rich.readthedocs.io/en/latest/protocol.html) for advanced visuals. You can use any renderable defined in [Rich](https://github.com/Textualize/rich) or third party libraries.
0 commit comments