textual
textual copied to clipboard
`grid-rows: auto` does not consider height for rows that are spanned
In a situation where a grid-cell is spanned across multiple rows, it is possible for that row to require more height than neighbouring regular cells. grid-rows: auto
seems to currently ignore spanned rows, and as result the grid is sized too small.
MRE:
from textual.app import App, ComposeResult
from textual.containers import Grid, Container
from textual.widgets import Placeholder, Static
class MyGrid(Grid):
DEFAULT_CSS = """
MyGrid {
border: solid cornflowerblue;
grid-size: 2 4;
grid-rows: auto;
height: auto;
#grid-header {
column-span: 2;
background: darkred;
Static {
text-align: center;
text-style: bold;
}
}
#block-1 {
row-span: 2;
background: cornflowerblue;
}
#block-2 {
background: lightsalmon;
}
Container {
height: auto;
}
}
"""
def compose(self) -> ComposeResult:
with Container(id="grid-header"):
yield Static("Header (column-span: 2)")
with Container(id="block-1", classes="block"):
yield Static("Block 1 (row-span 2, 16 lines height, but not showing)")
for i in range(15):
yield Static(f" - line {i+1:02} / 15")
with Container(id="block-2", classes="block"):
yield Static("Block 2 (single cell, total of 4 lines height)")
for i in range(3):
yield Static(f" - line {i+1} / 3")
with Container(id="block-3", classes="block"):
yield Static("Block 3 (single cell, total of 4 lines height)")
for i in range(3):
yield Static(f" - line {i+1} / 3")
class GridSizeApp(App[None]):
CSS = """
Placeholder {
height: 5;
}
"""
def compose(self) -> ComposeResult:
with Container():
yield Placeholder()
yield MyGrid()
yield Placeholder()
if __name__ == "__main__":
GridSizeApp().run()