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

If you remove a child from a Vertical that is height: auto the Vertical doesn't shrink in heigh #2007

Closed
davep opened this issue Mar 9, 2023 · 1 comment · Fixed by #2008
Labels
bug Something isn't working Task

Comments

@davep
Copy link
Contributor

davep commented Mar 9, 2023

Given this example code:

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

class VerticalRemoveApp( App[ None ] ):

    CSS = """
    Vertical {
        border: round green;
        height: auto;
    }

    Label {
        border: round yellow;
        background: red;
        color: yellow;
    }
    """
    BINDINGS = [
        ( "a", "add", "Add" ),
        ( "d", "del", "Delete" ),
    ]

    def compose( self ) -> ComposeResult:
        yield Header()
        yield Vertical()
        yield Footer()

    def action_add( self ) -> None:
        self.query_one( Vertical ).mount( Label( "This is a test label" ) )

    def action_del( self ) -> None:
        if self.query_one( Vertical ).children:
            self.query_one( Vertical ).children[ -1 ].remove()

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

You can see that the Vertical will grow in hight fine as you add items, but as you remove them it doesn't shrink again. Doing a refresh( layout=True ) on the Vertical after the remove on the child makes it work as expected. For example:

diff --git a/vertical_remove.py b/vertical_remove.py
index f252456..4195abe 100644
--- a/vertical_remove.py
+++ b/vertical_remove.py
@@ -34,6 +34,7 @@ class VerticalRemoveApp( App[ None ] ):
     def action_del( self ) -> None:
         if self.query_one( Vertical ).children:
             self.query_one( Vertical ).children[ -1 ].remove()
+            self.query_one( Vertical ).refresh( layout=True )

 if __name__ == "__main__":
     VerticalRemoveApp().run()
@davep davep added bug Something isn't working Task labels Mar 9, 2023
davep added a commit to davep/textual-sandbox that referenced this issue Mar 9, 2023
@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.

1 participant