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

Setting the value of an unfocused Input causes the first character to not display #1477

Closed
davep opened this issue Jan 4, 2023 · 3 comments · Fixed by #1548
Closed

Setting the value of an unfocused Input causes the first character to not display #1477

davep opened this issue Jan 4, 2023 · 3 comments · Fixed by #1548
Assignees
Labels
bug Something isn't working Task

Comments

@davep
Copy link
Contributor

davep commented Jan 4, 2023

Consider this code:

from textual.app     import App, ComposeResult
from textual.widgets import Header, Footer, Input

class InputPopulate( App[ None ] ):

    CSS = """
    Screen {
        align: center middle;
    }
    """

    def compose( self ) -> ComposeResult:
        yield Header()
        yield Input( placeholder="Data will go here" )
        yield Footer()

    def on_mount( self ) -> None:
        self.query_one( Input ).value = "This is a test value"

if __name__ == "__main__":
    InputPopulate().run()

After being run up, the Input looks like this:

Screenshot 2023-01-04 at 13 11 11

once focus is moved to it, however, the full value is shown:

Screenshot 2023-01-04 at 13 11 29

@davep davep added the bug Something isn't working label Jan 4, 2023
@Textualize Textualize deleted a comment from github-actions bot Jan 4, 2023
@davep
Copy link
Contributor Author

davep commented Jan 4, 2023

Possibly has some overlap with #1443?

@mrossinek
Copy link

Possibly has some overlap with #1443?

I had a quick look but that issue does not seem to be related. At least picking a placeholder for Input longer than one character still has the same behavior for the entire string as described in that issue (i.e. the first character does not get handled differently)

@rodrigogiraoserrao rodrigogiraoserrao self-assigned this Jan 11, 2023
rodrigogiraoserrao added a commit that referenced this issue Jan 11, 2023
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.
@rodrigogiraoserrao rodrigogiraoserrao linked a pull request Jan 11, 2023 that will close this issue
2 tasks
@github-actions
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants