Need help with scrollbar not reaching the last line inside a ContentSwitcher widget #3867
-
Consider this sample program: from textual.app import App
from textual.widgets import Label, Button, Footer, ContentSwitcher
from textual.containers import VerticalScroll, Horizontal
class TestApp(App):
CSS = '''
Screen {
overflow-y: hidden;
}
Button {
max-height: 1;
border: none;
width: 1fr;
}
.horz {
height: 1;
align: center middle;
}
.vert {
align: center middle;
}
'''
def compose(self):
with Horizontal(classes='horz'):
yield Button('Test App')
with ContentSwitcher(initial='foo'):
with VerticalScroll(id='foo', classes='vert'):
yield Label('1 2 3 4 5 6 7 8 9 10 11 12 13'.replace(' ', '\n'))
yield Footer()
def on_mount(self):
self.dark = False
if __name__ == "__main__":
app = TestApp()
app.run() I've tried to create a minimal working example from my actual use case. I have a If I remove But I don't want that extra entire app level scrollbar. I only need it for the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The ContentSwitcher has height auto by default, which means it will grow with the content. That's what may have changed since 0.32.0. To make the ContentSwitcher only take up the remaining space in its container, you can set its height to from textual.app import App
from textual.widgets import Label, Button, Footer, ContentSwitcher
from textual.containers import VerticalScroll, Horizontal
class TestApp(App):
CSS = """
Screen {
overflow-y: hidden;
}
Button {
max-height: 1;
border: none;
width: 1fr;
}
.horz {
height: 1;
align: center middle;
}
.vert {
align: center middle;
}
ContentSwitcher {
height: 1fr;
}
"""
def compose(self):
with Horizontal(classes="horz"):
yield Button("Test App")
with ContentSwitcher(initial="foo"):
with VerticalScroll(id="foo", classes="vert"):
yield Label("1 2 3 4 5 6 7 8 9 10 11 12 13".replace(" ", "\n"))
yield Footer()
def on_mount(self):
self.dark = False
if __name__ == "__main__":
app = TestApp()
app.run()from textual.app import App |
Beta Was this translation helpful? Give feedback.
The ContentSwitcher has height auto by default, which means it will grow with the content. That's what may have changed since 0.32.0.
To make the ContentSwitcher only take up the remaining space in its container, you can set its height to
1fr
. I think this will give you the effect you are looking for: