Skip to content

Commit 8b2f056

Browse files
committed
Fix alignment in auto container
1 parent 5c65cb9 commit 8b2f056

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
lines changed

src/textual/layout.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -259,18 +259,7 @@ def get_content_height(
259259
if not widget._nodes:
260260
height = 0
261261
else:
262-
# Use a height of zero to ignore relative heights
263-
styles_height = widget.styles.height
264-
if widget._parent and len(widget._nodes) == 1:
265-
# If it is an only child with height auto we want it to expand
266-
height = (
267-
container.height
268-
if styles_height is not None and styles_height.is_auto
269-
else 0
270-
)
271-
else:
272-
height = 0
273-
arrangement = widget._arrange(Size(width, height))
262+
arrangement = widget._arrange(Size(width, 0))
274263
height = arrangement.total_region.bottom
275264

276265
return height

tests/snapshot_tests/snapshot_apps/max_height_100.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33

44

55
class HappyDataTableFunApp(App[None]):
6-
"""The DataTable should expand as if it has height 1fr."""
6+
"""The DataTable should expand to full the screen and show a horizontal scrollbar."""
77

88
CSS = """
9+
#s {
10+
max-height: 100%;
11+
}
912
DataTable {
1013
max-height: 100%;
1114
}

tests/snapshot_tests/test_snapshots.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ def test_vertical_max_height(snap_compare):
13851385

13861386

13871387
def test_max_height_100(snap_compare):
1388-
"""Test vertical max height takes border in to account."""
1388+
"""Test a datatable with max height 100%."""
13891389
assert snap_compare(SNAPSHOT_APPS_DIR / "max_height_100.py")
13901390

13911391

@@ -3074,3 +3074,40 @@ def compose(self):
30743074
yield MainContainer()
30753075

30763076
snap_compare(Test1())
3077+
3078+
3079+
def test_auto_parent_with_alignment(snap_compare):
3080+
class Sidebar(Vertical):
3081+
DEFAULT_CSS = """
3082+
Sidebar {
3083+
dock: right;
3084+
width: auto;
3085+
height: auto;
3086+
background: blue;
3087+
align-vertical: bottom;
3088+
3089+
#contents {
3090+
width: auto;
3091+
height: auto;
3092+
background: red;
3093+
border: white;
3094+
}
3095+
}
3096+
"""
3097+
3098+
def compose(self) -> ComposeResult:
3099+
with Vertical(id="contents"):
3100+
yield Button("Start")
3101+
yield Button("Stop")
3102+
3103+
class FloatSidebarApp(App):
3104+
CSS = """
3105+
Screen {
3106+
layers: base sidebar;
3107+
}
3108+
"""
3109+
3110+
def compose(self) -> ComposeResult:
3111+
yield Sidebar()
3112+
3113+
snap_compare(FloatSidebarApp())

0 commit comments

Comments
 (0)