Skip to content

Commit

Permalink
fix for datatable in collapsible
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Jan 8, 2025
1 parent 6d483fb commit 80175f0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/textual/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,14 @@ def get_content_height(
Content height (in lines).
"""
if widget._nodes:
arrangement = widget._arrange(Size(width, 0))
if not widget.styles.is_docked and all(
child.styles.is_dynamic_height for child in widget.displayed_children
):
arrangement = widget._arrange(
Size(width, container.height - widget.gutter.height)
)
else:
arrangement = widget._arrange(Size(width, 0))
height = arrangement.total_region.bottom
else:
height = 0
Expand Down
4 changes: 3 additions & 1 deletion src/textual/layouts/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def arrange(
parent.pre_layout(self)
styles = parent.styles
row_scalars = styles.grid_rows or (
[Scalar.parse("1fr")] if size.height else [Scalar.parse("auto")]
[Scalar.parse("1fr")]
if (size.height and not parent.styles.is_auto_height)
else [Scalar.parse("auto")]
)
column_scalars = styles.grid_columns or [Scalar.parse("1fr")]
gutter_horizontal = styles.grid_gutter_horizontal
Expand Down
33 changes: 33 additions & 0 deletions tests/snapshot_tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from textual.screen import ModalScreen, Screen
from textual.widgets import (
Button,
Collapsible,
DataTable,
Footer,
Header,
Expand Down Expand Up @@ -3251,3 +3252,35 @@ async def run_before(pilot: Pilot) -> None:
terminal_size=(175, 50),
run_before=run_before,
)


def test_collapsible_datatable(snap_compare):
"""Regression test for https://github.com/Textualize/textual/issues/5407
You should see two collapsibles, where the first is expanded.
In the expanded coillapsible, you should see a DataTable filling the space,
with all borders and both scrollbars visible.
"""

class MyApp(App):
CSS = """
DataTable {
}
"""

def compose(self) -> ComposeResult:
yield Collapsible(DataTable(id="t1"), id="c1", collapsed=False)
yield Collapsible(Label("hello"), id="c2")

def on_mount(self) -> None:
self.query_one("#c1", Collapsible).styles.max_height = "50%"
self.query_one("#c2", Collapsible).styles.max_height = "50%"

t1 = self.query_one("#t1", DataTable)
t1.styles.border = "heavy", "black"
t1.add_column("A")
for number in range(1, 100):
t1.add_row(str(number) + " " * 200)

snap_compare(MyApp())

0 comments on commit 80175f0

Please sign in to comment.