-
Notifications
You must be signed in to change notification settings - Fork 815
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
Initial value of Input
not rendered upon .mount
#1443
Comments
To narrow this down a little: it does get rendered on It does work as expected if the action is made into an async action and then the mount is awaited before setting focus: async def action_prompt(self) -> None:
prompt = Input(value="This is a test")
await self.mount(prompt)
prompt.focus() |
This is indeed the case, thank you very much! In fact, |
When we get a moment I'd like to double-check this behaviour with @willmcgugan and @darrenburns first. It feels like it's behaving correctly, but I'd like their final say. |
When an input is instantiated without an argument for the parameter 'value', the first time the watchers associated with its reactive attributes run, the attribute self.view_position is set to 1, which makes no sense because there isn't even any value in the input. Thus, when the value is later modified programmatically, e.g., because it is set with 'some_input_widget.value = some_value', the attribute self.view_position will still be 1 and the text will be rendered starting from the first character. As two example situations of this, consider #1477 and #1443.
Don't forget to star the repository! Follow @textualizeio for Textual updates. |
Have you checked closed issues?
Yes, I did not find anything similar.
Please give a brief but clear explanation of the issue.
The value of
Input(value=value)
does not get rendered when anInput
is added via.mount
.It only gets rendered after an additional character is entered.
What Operating System are you running on?
Arch Linux; Kernel 6.0.12-arch1-1
Feel free to add screenshots and/or videos. These can be very helpful!
Screenshot of the snippet below which yields
Input
as part of.compose
:Screenshot of the snippet below which tries to
.mount
anInput
widget after pressingp
to trigger the action:After inserting an additional character the provided
value
gets rendered properly:If you can, include a complete working example that demonstrates the bug. Check it can run without modifications.
Here is a working example based on
.compose
:And here is the broken example trying to use
.mount
:Solution Ansatz
I am suspecting the problem to lie in the
Input
widget itself. Specifically this widget has aview_position
attribute which I believe to be the source of the error. Upon mounting this attribute has value2
and it gets reset to0
once inserting a character.You can verify this with the following patch:
The text was updated successfully, but these errors were encountered: