diff --git a/CHANGELOG.md b/CHANGELOG.md index dca4cd7425..183d8dddf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fixed `Pilot.click` not working with `times` parameter https://github.com/Textualize/textual/pull/5398 - Fixed select refocusing itself too late https://github.com/Textualize/textual/pull/5420 - Fixed Log widget not refreshing on resize https://github.com/Textualize/textual/pull/5460 +- Fixed special case with calculating the height of a container where all children have dynamic heights https://github.com/Textualize/textual/pull/5463 - Fixed scrollbars ignoring background opacity https://github.com/Textualize/textual/issues/5458 diff --git a/src/textual/layout.py b/src/textual/layout.py index 97d5019c93..4f16787d45 100644 --- a/src/textual/layout.py +++ b/src/textual/layout.py @@ -257,7 +257,15 @@ 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 + ): + # An exception for containers with all dynamic height widgets + 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 diff --git a/src/textual/layouts/grid.py b/src/textual/layouts/grid.py index 30cfbb7ab4..5f6b934a74 100644 --- a/src/textual/layouts/grid.py +++ b/src/textual/layouts/grid.py @@ -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 diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots/test_collapsible_datatable.svg b/tests/snapshot_tests/__snapshots__/test_snapshots/test_collapsible_datatable.svg new file mode 100644 index 0000000000..a95f37f953 --- /dev/null +++ b/tests/snapshot_tests/__snapshots__/test_snapshots/test_collapsible_datatable.svg @@ -0,0 +1,156 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MyApp + + + + + + + + + + ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ +▼ Toggle + +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + A                                                                       + 1                                                                       + 2                                                                       + 3                                                                       + 4                                                                       + +┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + +▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ +▶ Toggle + + + + + + + + + + + + + diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index abaf0d35db..878da6a45d 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -26,6 +26,7 @@ from textual.screen import ModalScreen, Screen from textual.widgets import ( Button, + Collapsible, DataTable, Footer, Header, @@ -3253,6 +3254,38 @@ async def run_before(pilot: Pilot) -> None: ) +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()) + + def test_scrollbar_background_with_opacity(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5458 The scrollbar background should match the background of the widget."""