Skip to content

Commit 8cccd7d

Browse files
authored
Merge pull request #5360 from Textualize/fix-auto-alignment
Fix alignment in auto container
2 parents 5c65cb9 + 455c085 commit 8cccd7d

File tree

5 files changed

+205
-17
lines changed

5 files changed

+205
-17
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1818
- Change default quit key to `ctrl+q` https://github.com/Textualize/textual/pull/5352
1919
- Changed delete line binding on TextArea to use `ctrl+shift+x` https://github.com/Textualize/textual/pull/5352
2020

21+
### Fixed
22+
23+
- Fixed issue with alignment in auto containers https://github.com/Textualize/textual/pull/5360
24+
2125
## [0.89.1] - 2024-11-05
2226

2327
### Fixed

src/textual/layout.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -256,22 +256,11 @@ def get_content_height(
256256
Returns:
257257
Content height (in lines).
258258
"""
259-
if not widget._nodes:
260-
height = 0
261-
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))
259+
if widget._nodes:
260+
arrangement = widget._arrange(Size(width, 0))
274261
height = arrangement.total_region.bottom
262+
else:
263+
height = 0
275264

276265
return height
277266

Lines changed: 155 additions & 0 deletions
Loading

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; # Not strictly required to replicate the issue
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)