File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -197,10 +197,9 @@ which let them call [actions](../guide/actions.md) in response to key presses.
197197
198198A widget is only able to handle key presses if it or one of its descendants has [ focus] ( ../guide/input.md#input-focus ) .
199199
200- To demonstrate, let's design a simple interactive counter widget which can be incremented and decremented using the keyboard.
201-
202- In the following example, we define a simple ` Counter ` widget with ` can_focus=True ` , and some CSS to make it stand out when focused.
203- Our app contains three ` Counter ` widgets, which we can focus by clicking or using ++tab++ and ++shift+tab++.
200+ Widgets aren't focusable by default.
201+ In order to allow a widget to be focused, we need to set ` can_focus=True ` when defining a widget subclass.
202+ Let's look at an example of defining a ` Counter ` widget which can be focused.
204203
205204=== "counter01.py"
206205
@@ -223,6 +222,9 @@ Our app contains three `Counter` widgets, which we can focus by clicking or usin
223222 ```{.textual path="docs/examples/guide/widgets/counter01.py"}
224223 ```
225224
225+
226+ Our app contains three ` Counter ` widgets, which we can focus by clicking or using ++tab++ and ++shift+tab++.
227+
226228Now that our counter is focusable, let's make it interactive by adding some key bindings and actions to it.
227229To do this, we add a ` BINDINGS ` class variable to ` Counter ` , with bindings for ++up++ and ++down++.
228230These new bindings are linked to the ` change_count ` action, which updates the ` count ` reactive attribute.
You can’t perform that action at this time.
0 commit comments