-
Notifications
You must be signed in to change notification settings - Fork 841
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 screens
#2527
Conversation
src/textual/screen.py
Outdated
@@ -101,6 +101,12 @@ class Screen(Generic[ScreenResultType], Widget): | |||
} | |||
""" | |||
|
|||
auto_focus: str | None = "*" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this an instance var, which should be the default unless there is good rationale for it being a classvar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly because it's a pain to set it as an instance attribute-only for people creating their own screens:
class FormScreen(Screen):
auto_focus = "Input"
...
vs
class FormScreen(Screen):
def __init__(
self,
name: str | None = None,
id: str | None = None,
classes: str | None = None,
) -> None:
self.auto_focus = "Input"
super().__init__(name=name, id=id, classes=classes)
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want it to be a classvar, suggest we make it a constant, i.e. AUTO_FOCUS
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Classvar it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually rather surprised this didn't break any unit tests.
See Textualize#2718. The problem is that the work done on Textualize#2527 and related PRs has changed the starting position of focus, which means that any code example that has key presses in them that start out by tabbing to a control will be off by one.
This will close #2457.
I've added a docstring but I haven't added documentation elsewhere. Should I?