Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add can_focus to guide, mention how BINDINGS are checked #4985

Merged
merged 21 commits into from
Oct 3, 2024

Conversation

darrenburns
Copy link
Member

@darrenburns darrenburns commented Sep 11, 2024

Closes #4918.

Also noticed that we only seem to give examples of "global"/App-level bindings, so I've added a couple of sentences explaining how the focused widget is checked first, followed by a look upwards through the DOM.

@willmcgugan You mentioned in the issue to add it to the "widget" guide, but it seemed like the "input" when I checked as that's where most of the discussion around focus happens. Let me know if you disagree.

Copy link
Collaborator

@willmcgugan willmcgugan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a fully working example is needed here. It is a major deficiency in the docs that we don't cover focusing and bindings.

docs/guide/widgets.md Outdated Show resolved Hide resolved
@darrenburns
Copy link
Member Author

I've added a section to the guide showing how to construct a basic focusable widget with simple bindings defined.

image

@@ -190,6 +190,67 @@ If the supplied text is too long to fit within the widget, it will be cropped (a
There are a number of styles that influence how titles are displayed (color and alignment).
See the [style reference](../styles/index.md) for details.

## Focus & keybindings
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this section should be called "Focusable widgets"? Its just that prior to this heading, we've already introduced focus and keybindings. We want the reader to know what they are about to learn.

Copy link
Member Author

@darrenburns darrenburns Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I changed this around a few times -

We're on the "Widgets" page, so it felt clear to me that it was in the context of widgets. It also adds "keybindings" to the table of contents for the page, which I felt was important for discoverability.. "how do I add keybindings to my widget" feels like the "question" I'd be looking to an answer for, and having headings suggest that there might be answer contained within is important.

Its just that prior to this heading, we've already introduced focus and keybindings.

That was on a different docs page (a couple of pages back in the guide), before we'd introduced how to create a widget.

@@ -190,6 +190,67 @@ If the supplied text is too long to fit within the widget, it will be cropped (a
There are a number of styles that influence how titles are displayed (color and alignment).
See the [style reference](../styles/index.md) for details.

## Focus & keybindings

Widgets can have a list of associated key [bindings](../guide/input.md#bindings),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like repetition, since we have just been explaining it.

Copy link
Member Author

@darrenburns darrenburns Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It certainly is repetition, but our last mention of this stuff was quite some time ago (note that there are 2 files changed in this PR - this change is in "Widgets", but the stuff you're referring to is in "Input".) and repetition is sometimes important to build context or refresh memories.

My thought was someone unfamiliar with Textual and reading this for the first time would appreciate a 1-sentence refresher as well as a link back to the "main" explanation.


To demonstrate, let's design a simple interactive counter widget which can be incremented and decremented using the keyboard.

In the following example, we define a simple `Counter` widget with `can_focus=True`, and some CSS to make it stand out when focused.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the can_focus=True is a really important takeaway here. It's what we were lacking, and why we keep getting asked. Here it seems too much of a sidenote.

"Widgets aren't focusable by default. In order for a widget to be focusable we need to set can_focus=True when we define a widget subclass. Here's an example of a focusable widget ..."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is clearer in the rendered docs, as the example app below has a single highlighted line for the can_focus=True as well as a popup explaining it. The whole purpose of the example is to draw attention to the can_focus=True.

Have reworded to try and emphasise it more.

docs/guide/widgets.md Outdated Show resolved Hide resolved
docs/guide/widgets.md Outdated Show resolved Hide resolved
@willmcgugan willmcgugan merged commit 08f85e9 into main Oct 3, 2024
20 checks passed
@willmcgugan willmcgugan deleted the docs-updates-11sep24 branch October 3, 2024 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document can_focus
2 participants