Skip to content

Commit 48b4ad8

Browse files
committed
grow height for scrollbar
1 parent 5472c18 commit 48b4ad8

File tree

5 files changed

+206
-2
lines changed

5 files changed

+206
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
- Input cursor will no longer jump to the end on focus https://github.com/Textualize/textual/pull/4773
1313
- Removed `Size.cip_size`, which was a clone of `crop_size`
14+
- Widgets with auto dimensions will now grow if there is a scrollbar
1415

1516
### Fixed
1617

src/textual/widget.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,9 @@ def _get_box_model(
12361236
content_width = Fraction(
12371237
self.get_content_width(content_container - margin.totals, viewport)
12381238
)
1239-
if styles.scrollbar_gutter == "stable" and styles.overflow_x == "auto":
1239+
if styles.overflow_x == "auto" and (
1240+
styles.scrollbar_gutter == "stable" or self.show_vertical_scrollbar
1241+
):
12401242
content_width += styles.scrollbar_size_vertical
12411243
if (
12421244
content_width < content_container.width
@@ -1286,8 +1288,11 @@ def _get_box_model(
12861288
content_height = Fraction(
12871289
self.get_content_height(content_container, viewport, int(content_width))
12881290
)
1289-
if styles.scrollbar_gutter == "stable" and styles.overflow_y == "auto":
1291+
if styles.overflow_y == "auto" and (
1292+
styles.scrollbar_gutter == "stable" or self.show_horizontal_scrollbar
1293+
):
12901294
content_height += styles.scrollbar_size_horizontal
1295+
12911296
if (
12921297
content_height < content_container.height
12931298
and self._has_relative_children_height
Lines changed: 155 additions & 0 deletions
Loading
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from textual.app import App, ComposeResult
2+
from textual.widgets import DataTable, Label
3+
4+
LORUM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
5+
6+
7+
class ExampleApp(App):
8+
CSS = """
9+
Screen {
10+
11+
DataTable {
12+
border: solid white;
13+
}
14+
}
15+
16+
"""
17+
18+
def compose(self) -> ComposeResult:
19+
yield Label("automatic scrollbar")
20+
yield DataTable(id="table1")
21+
yield Label("no automatic scrollbar")
22+
yield DataTable(id="table2")
23+
24+
def on_mount(self) -> None:
25+
table = self.query_one("#table1", DataTable)
26+
table.add_column("Column 1")
27+
table.add_column("Column 2")
28+
table.add_row(LORUM_IPSUM, LORUM_IPSUM)
29+
30+
table = self.query_one("#table2", DataTable)
31+
table.add_column("Column 1")
32+
table.add_column("Column 2")
33+
table.add_row("Paul", "Jessica")
34+
35+
36+
if __name__ == "__main__":
37+
app = ExampleApp()
38+
app.run()

tests/snapshot_tests/test_snapshots.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,3 +1400,8 @@ async def run_before(pilot: Pilot):
14001400
def test_remove_tab_no_animation(snap_compare):
14011401
"""Regression test for https://github.com/Textualize/textual/issues/4814"""
14021402
assert snap_compare(SNAPSHOT_APPS_DIR / "remove_tab.py", press=["space"])
1403+
1404+
1405+
def test_auto_height_scrollbar(snap_compare):
1406+
"""Regression test for https://github.com/Textualize/textual/issues/4778"""
1407+
assert snap_compare(SNAPSHOT_APPS_DIR / "data_table_auto_height.py")

0 commit comments

Comments
 (0)