Skip to content

Commit fadefaf

Browse files
committed
Fix for auto height in collapsible
1 parent 87d0cd7 commit fadefaf

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/textual/layout.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,8 @@ def get_content_height(
261261
child.styles.is_dynamic_height for child in widget.displayed_children
262262
):
263263
# An exception for containers with all dynamic height widgets
264-
arrangement = widget._arrange(
265-
Size(width, container.height - widget.gutter.height)
266-
)
264+
arrangement = widget._arrange(Size(width, container.height))
265+
return arrangement.total_region.bottom
267266
else:
268267
arrangement = widget._arrange(Size(width, 0))
269268
height = arrangement.total_region.bottom

src/textual/widget.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,11 @@ def _get_box_model(
15901590
elif is_auto_height:
15911591
# Calculate dimensions based on content
15921592
content_height = Fraction(
1593-
self.get_content_height(content_container, viewport, int(content_width))
1593+
self.get_content_height(
1594+
content_container - margin.totals,
1595+
viewport,
1596+
int(content_width),
1597+
)
15941598
)
15951599
if (
15961600
styles.overflow_y == "auto" and styles.scrollbar_gutter == "stable"

tests/snapshot_tests/test_snapshots.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3285,7 +3285,11 @@ def test_collapsible_datatable(snap_compare):
32853285
class MyApp(App):
32863286
CSS = """
32873287
DataTable {
3288-
3288+
3289+
}
3290+
Collapsible {
3291+
max-height: 50%;
3292+
# height: 1fr;
32893293
}
32903294
"""
32913295

@@ -3294,8 +3298,8 @@ def compose(self) -> ComposeResult:
32943298
yield Collapsible(Label("hello"), id="c2")
32953299

32963300
def on_mount(self) -> None:
3297-
self.query_one("#c1", Collapsible).styles.max_height = "50%"
3298-
self.query_one("#c2", Collapsible).styles.max_height = "50%"
3301+
# self.query_one("#c1", Collapsible).styles.max_height = "50%"
3302+
# self.query_one("#c2", Collapsible).styles.max_height = "50%"
32993303

33003304
t1 = self.query_one("#t1", DataTable)
33013305
t1.styles.border = "heavy", "black"

0 commit comments

Comments
 (0)