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

An Input with width: auto tends to scroll the first character of its value off the left of its display #1693

Closed
davep opened this issue Jan 30, 2023 · 2 comments · Fixed by #1699
Labels
bug Something isn't working Task

Comments

@davep
Copy link
Contributor

davep commented Jan 30, 2023

Given the following code:

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

class InputWidthAutoApp( App[ None ] ):

    CSS = """
    Input.fixed {
        width: 30;
    }
    Input.auto {
        width: auto;
    }
    Input.pcent {
        width: 20%;
    }
    """

    def compose( self ) -> ComposeResult:
        yield Header()
        yield Vertical(
            Label( "Default width:" ), Input( placeholder="This has default width" ),
            Label( "Fixed width:" ), Input( placeholder="This has a fixed width", classes="fixed" ),
            Label( "Auto width:" ), Input( placeholder="This has auto width", classes="auto" ),
            Label( "%age width:" ), Input( placeholder="This has %age width", classes="pcent" )
        )
        yield Footer()

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

All of the inputs will show the content as you'd expect, with the exception of the one that is width: auto; where the first character will scroll off the left. It's still there and can be scrolled back to. For example, typing the same word into each Input:

Screenshot 2023-01-30 at 16 21 40

@davep davep added bug Something isn't working Task labels Jan 30, 2023
@rodrigogiraoserrao
Copy link
Contributor

I've got a feeling that a correct fix for this bug might render obsolete this code I wrote for #1548:

if width == 0:
# If the input has no width the view position can't be elsewhere.
self.view_position = 0
return

@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.

2 participants