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 auto focus to app. #2628

Merged
merged 1 commit into from
May 25, 2023
Merged

Add auto focus to app. #2628

merged 1 commit into from
May 25, 2023

Conversation

rodrigogiraoserrao
Copy link
Contributor

Closes #2594.

  • Docstrings on all new or modified functions / classes
  • Updated documentation
  • Updated CHANGELOG.md (where appropriate)

Related issues: #2594.
@@ -94,11 +94,12 @@ def __call__(self, result: ScreenResultType) -> None:
class Screen(Generic[ScreenResultType], Widget):
"""The base class for screens."""

AUTO_FOCUS: ClassVar[str | None] = "*"
AUTO_FOCUS: ClassVar[str | None] = None
Copy link
Member

Choose a reason for hiding this comment

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

Feel like I'm very late to the party with this, but out of curiosity - since this is a ClassVar do we not have a way of having 2 Screen instances have different auto-focus depending on context?

For example, when you push an EditForm screen, maybe the initially focused form control differs based on how you arrived at that screen. If you clicked "edit username", the username input would be auto-focused when the screen is pushed. If you clicked "edit date of birth", the date of birth input would be auto-focused when the screen is pushed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In that case you could set AUTO_FOCUS to "" (to disable it), then handle focusing manually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can also set AUTO_FOCUS on the instance and it'll be picked up. 🤷
Or what am I missing?

@rodrigogiraoserrao rodrigogiraoserrao merged commit 5cb30b5 into main May 25, 2023
@rodrigogiraoserrao rodrigogiraoserrao deleted the auto-focus-improv branch May 25, 2023 10:59
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.

AUTO_FOCUS on App should apply to screen
3 participants