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

A container with grid layout can't be set to height: auto #1597

Closed
davep opened this issue Jan 17, 2023 · 2 comments · Fixed by #3113
Closed

A container with grid layout can't be set to height: auto #1597

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

Comments

@davep
Copy link
Contributor

davep commented Jan 17, 2023

Following on from this discussion, and from checking with @willmcgugan about the intended working, it looks like there's a bug where you can't make a grid container height: auto. As a test bit of code:

from typing             import Type
from textual.app        import App, ComposeResult
from textual.containers import Container, Horizontal, Vertical, Grid
from textual.widgets    import Header, Footer, Label
from textual.binding    import Binding

class GridHeightAuto( App[ None ] ):

    CSS = """
    #test-area {
        height: auto;
        border: solid red;
        height: auto;
    }

    Grid {
        grid-size: 3;
    }
    """

    BINDINGS = [
        Binding( "g", "grid", "Grid" ),
        Binding( "v", "vertical", "Vertical" ),
        Binding( "h", "horizontal", "Horizontal" ),
        Binding( "c", "container", "Container" )
    ]

    def compose( self ) -> ComposeResult:
        yield Header()
        yield Vertical( Label( "Select a container to test (see footer)" ), id="sandbox" )
        yield Footer()

    def build( self, out_of: Type[ Container | Grid | Horizontal | Vertical ] ) -> None:
        self.query( "#sandbox > *" ).remove()
        self.query_one( "#sandbox", Vertical ).mount(
            Label( "Here is some text before the grid" ),
            out_of( *[ Label( f"Cell #{n}" ) for n in range( 9 ) ], id="test-area" ),
            Label( "Here is some text after the grid" )
        )

    def action_grid( self ):
        self.build( Grid )

    def action_vertical( self ):
        self.build( Vertical )

    def action_horizontal( self ):
        self.build( Horizontal )

    def action_container( self ):
        self.build( Container )

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

The results are, Container:

Screenshot 2023-01-17 at 15 41 40

Vertical:

Screenshot 2023-01-17 at 15 42 21

Horizontal:

Screenshot 2023-01-17 at 15 42 56

And Grid:

Screenshot 2023-01-17 at 15 43 15

It would appear that all container layouts handle height: auto fine expect for grid.

@davep davep added bug Something isn't working Task labels Jan 17, 2023
@Textualize Textualize deleted a comment from github-actions bot Jan 17, 2023
@shuckc
Copy link

shuckc commented Aug 7, 2023

I've run into this issue where a grid layout with a dynamic number of rows is problematic to handle, as height: auto collapses it. In my case and with a hand from @davep I calculated a desired height dynamically and applied it to the grid in python code. https://gist.github.com/shuckc/5ec3c4fed5844252fb2f9bb91d63bf88

@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