diff --git a/CHANGELOG.md b/CHANGELOG.md
index eca5e3c55a..579ad68fd7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Input cursor will no longer jump to the end on focus https://github.com/Textualize/textual/pull/4773
- Removed `Size.cip_size`, which was a clone of `crop_size`
+- Widgets with auto dimensions will now grow if there is a scrollbar https://github.com/Textualize/textual/pull/4844
### Fixed
diff --git a/src/textual/widget.py b/src/textual/widget.py
index ae3b042597..f3f8196aed 100644
--- a/src/textual/widget.py
+++ b/src/textual/widget.py
@@ -1236,7 +1236,9 @@ def _get_box_model(
content_width = Fraction(
self.get_content_width(content_container - margin.totals, viewport)
)
- if styles.scrollbar_gutter == "stable" and styles.overflow_x == "auto":
+ if (
+ styles.overflow_x == "auto" and styles.scrollbar_gutter == "stable"
+ ) or self.show_vertical_scrollbar:
content_width += styles.scrollbar_size_vertical
if (
content_width < content_container.width
@@ -1286,7 +1288,9 @@ def _get_box_model(
content_height = Fraction(
self.get_content_height(content_container, viewport, int(content_width))
)
- if styles.scrollbar_gutter == "stable" and styles.overflow_y == "auto":
+ if (
+ styles.overflow_y == "auto" and styles.scrollbar_gutter == "stable"
+ ) or self.show_horizontal_scrollbar:
content_height += styles.scrollbar_size_horizontal
if (
content_height < content_container.height
diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots/test_auto_height_scrollbar.svg b/tests/snapshot_tests/__snapshots__/test_snapshots/test_auto_height_scrollbar.svg
new file mode 100644
index 0000000000..2b8d74e110
--- /dev/null
+++ b/tests/snapshot_tests/__snapshots__/test_snapshots/test_auto_height_scrollbar.svg
@@ -0,0 +1,155 @@
+
diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots/test_auto_table.svg b/tests/snapshot_tests/__snapshots__/test_snapshots/test_auto_table.svg
index ccfb82f1cb..3f8165023c 100644
--- a/tests/snapshot_tests/__snapshots__/test_snapshots/test_auto_table.svg
+++ b/tests/snapshot_tests/__snapshots__/test_snapshots/test_auto_table.svg
@@ -19,202 +19,202 @@
font-weight: 700;
}
- .terminal-1765028414-matrix {
+ .terminal-3267243469-matrix {
font-family: Fira Code, monospace;
font-size: 20px;
line-height: 24.4px;
font-variant-east-asian: full-width;
}
- .terminal-1765028414-title {
+ .terminal-3267243469-title {
font-size: 18px;
font-weight: bold;
font-family: arial;
}
- .terminal-1765028414-r1 { fill: #c5c8c6 }
-.terminal-1765028414-r2 { fill: #e3e3e3 }
-.terminal-1765028414-r3 { fill: #004578 }
-.terminal-1765028414-r4 { fill: #e1e1e1 }
-.terminal-1765028414-r5 { fill: #632ca6 }
-.terminal-1765028414-r6 { fill: #dde6ed;font-weight: bold }
-.terminal-1765028414-r7 { fill: #14191f }
-.terminal-1765028414-r8 { fill: #23568b }
+ .terminal-3267243469-r1 { fill: #c5c8c6 }
+.terminal-3267243469-r2 { fill: #e3e3e3 }
+.terminal-3267243469-r3 { fill: #004578 }
+.terminal-3267243469-r4 { fill: #e1e1e1 }
+.terminal-3267243469-r5 { fill: #632ca6 }
+.terminal-3267243469-r6 { fill: #dde6ed;font-weight: bold }
+.terminal-3267243469-r7 { fill: #14191f }
+.terminal-3267243469-r8 { fill: #23568b }
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
- MyApp
+ MyApp
-
-
-
- ⭘MyApp
-╭──────────────────╮╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
-│ok ││test │
-│╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍││╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍│
-│││╭─ 0 ──────────────────────────────────────╮╭─ 1 ──────────────────────────────────────╮╭─ 2 ─────│
-│││││││││
-││││ Foo Bar Baz ││ Foo Bar Baz ││ Foo │
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY▁▁││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY▁▁││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXY││ ABCDEFGH│
-│││╰──────────────────────────────────────────╯╰──────────────────────────────────────────╯╰─────────│
-│││▋│
-╰──────────────────╯╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
+
+
+
+ ⭘MyApp
+╭──────────────────╮╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
+│ok ││test │
+│╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍││╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍│
+│││╭─ 0 ────────────────────────────────────────╮╭─ 1 ────────────────────────────────────────╮╭─ 2 ─│
+│││││││││
+││││ Foo Bar Baz ││ Foo Bar Baz ││ Foo │
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ▁▁││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ▁▁││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+││││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCDEFGH 0123456789 IJKLMNOPQRSTUVWXYZ ││ ABCD│
+│││╰────────────────────────────────────────────╯╰────────────────────────────────────────────╯╰─────│
+│││▎│
+╰──────────────────╯╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
diff --git a/tests/snapshot_tests/snapshot_apps/data_table_auto_height.py b/tests/snapshot_tests/snapshot_apps/data_table_auto_height.py
new file mode 100644
index 0000000000..0801b86ca6
--- /dev/null
+++ b/tests/snapshot_tests/snapshot_apps/data_table_auto_height.py
@@ -0,0 +1,38 @@
+from textual.app import App, ComposeResult
+from textual.widgets import DataTable, Label
+
+LORUM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
+
+
+class ExampleApp(App):
+ CSS = """
+ Screen {
+
+ DataTable {
+ border: solid white;
+ }
+ }
+
+ """
+
+ def compose(self) -> ComposeResult:
+ yield Label("automatic scrollbar")
+ yield DataTable(id="table1")
+ yield Label("no automatic scrollbar")
+ yield DataTable(id="table2")
+
+ def on_mount(self) -> None:
+ table = self.query_one("#table1", DataTable)
+ table.add_column("Column 1")
+ table.add_column("Column 2")
+ table.add_row(LORUM_IPSUM, LORUM_IPSUM)
+
+ table = self.query_one("#table2", DataTable)
+ table.add_column("Column 1")
+ table.add_column("Column 2")
+ table.add_row("Paul", "Jessica")
+
+
+if __name__ == "__main__":
+ app = ExampleApp()
+ app.run()
diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py
index ab6b1b249c..895bd4a1bf 100644
--- a/tests/snapshot_tests/test_snapshots.py
+++ b/tests/snapshot_tests/test_snapshots.py
@@ -1400,3 +1400,8 @@ async def run_before(pilot: Pilot):
def test_remove_tab_no_animation(snap_compare):
"""Regression test for https://github.com/Textualize/textual/issues/4814"""
assert snap_compare(SNAPSHOT_APPS_DIR / "remove_tab.py", press=["space"])
+
+
+def test_auto_height_scrollbar(snap_compare):
+ """Regression test for https://github.com/Textualize/textual/issues/4778"""
+ assert snap_compare(SNAPSHOT_APPS_DIR / "data_table_auto_height.py")