-
Notifications
You must be signed in to change notification settings - Fork 822
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 Blur message to Input widget #5414
base: main
Are you sure you want to change the base?
Add Blur message to Input widget #5414
Conversation
a message when triggered to match the Submitted and Changed messages.
The reason is most likely that the from textual import on
from textual.app import App, ComposeResult
from textual.containers import Horizontal, Vertical
from textual.events import DescendantBlur
from textual.widgets import Input, Log
class InputBlurTest(App[None]):
def compose(self) -> ComposeResult:
with Horizontal():
with Vertical():
for n in range(10):
yield Input(placeholder=str(n), id=f"input-{n}")
yield Log()
@on(DescendantBlur, "Input")
def log_input_blur(self, message: DescendantBlur) -> None:
self.query_one(Log).write_line(f"This input lost focus: {message.control!r}")
if __name__ == "__main__":
InputBlurTest().run() |
@davep I think the problem being addressed here is that while...
...you can't do the same when the |
I was offering a possible explanation as to why that particular message was missing; not suggesting that this PR shouldn't have been PRd. |
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.
Good idea, just a request.
src/textual/widgets/_input.py
Outdated
@@ -284,6 +284,29 @@ def control(self) -> Input: | |||
"""Alias for self.input.""" | |||
return self.input | |||
|
|||
@dataclass | |||
class Blur(Message): |
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 call it Blurred
, which is more consistent with existing messages, and avoids confusion with the existing Blur
message.
@davep I believe @edward-jazzhands was talking about a hypothetical |
@davep Ah I was not aware of the DescendantBlur and DescendantFocus messages. Didn't notice those in the reference. Yes indeed it would solve the problem. I see now that this would effectively create another message that's doing the same thing as DescendantBlur, but attached specifically to the Input widget, just to give it a message that can be used in a manner that's more similar to the other two messages, and a bit more intuitive to figure out. Perhaps if this section of the reference (https://textual.textualize.io/widgets/input/#validating-input) was updated to mention the DescendantFocus message then this would be unnecessary. But nevertheless, I've submitted the changes that @willmcgugan requested. |
I realized working with the Input widget that its options for
validate_on
are "submitted", "changed", and "blur". However, there's only messages for Submitted and Changed. This makes it trickier to synchronize a function with the blur validator than it is with the other two validators, which I believe in this situation does not make sense.Now I had figured a Blur event most likely does not exist for a reason (i.e. perhaps if one widget has it then why wouldn't all of them). But in this situation I can't help but feel like its existence is warranted in order to make the
validate_on=['blur']
parameter be able to be used in a manner that's identical to "submitted" and "changed" without needing to subclass the Input widget.The problem: