Skip to content

Commit 32b7308

Browse files
committed
fox for nested heights
1 parent c20bf66 commit 32b7308

File tree

3 files changed

+80
-3
lines changed

3 files changed

+80
-3
lines changed

src/textual/widget.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,8 +2175,14 @@ def refresh(
21752175

21762176
if layout:
21772177
self._layout_required = True
2178-
if isinstance(self._parent, Widget):
2179-
self._parent._clear_arrangement_cache()
2178+
for ancestor in self.ancestors:
2179+
if not isinstance(ancestor, Widget):
2180+
break
2181+
if ancestor.styles.auto_dimensions:
2182+
for ancestor in self.ancestors_with_self:
2183+
if isinstance(ancestor, Widget):
2184+
ancestor._clear_arrangement_cache()
2185+
break
21802186

21812187
if repaint:
21822188
self._set_dirty(*regions)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python3
2+
3+
from __future__ import annotations
4+
5+
from textual.app import App, ComposeResult
6+
from textual.containers import Vertical
7+
from textual.widgets import Static
8+
9+
10+
class NestedAutoApp(App[None]):
11+
CSS = """
12+
Screen {
13+
background: red;
14+
}
15+
16+
#my-static-container {
17+
border: heavy lightgreen;
18+
background: green;
19+
height: auto;
20+
max-height: 10;
21+
}
22+
23+
#my-static-wrapper {
24+
border: heavy lightblue;
25+
background: blue;
26+
width: auto;
27+
height: auto;
28+
}
29+
30+
#my-static {
31+
border: heavy gray;
32+
background: black;
33+
width: auto;
34+
height: auto;
35+
}
36+
"""
37+
BINDINGS = [
38+
("1", "1", "1"),
39+
("2", "2", "2"),
40+
("q", "quit", "Quit"),
41+
]
42+
43+
def compose(self) -> ComposeResult:
44+
self._static = Static("", id="my-static")
45+
yield Vertical(
46+
Vertical(
47+
self._static,
48+
id="my-static-wrapper",
49+
),
50+
id="my-static-container",
51+
)
52+
53+
def action_1(self) -> None:
54+
self._static.update(
55+
"\n".join(f"Lorem {i} Ipsum {i} Sit {i}" for i in range(1, 21))
56+
)
57+
58+
def action_2(self) -> None:
59+
self._static.update("JUST ONE LINE")
60+
61+
62+
if __name__ == "__main__":
63+
app = NestedAutoApp()
64+
app.run()

tests/snapshot_tests/test_snapshots.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ def test_header_render(snap_compare):
101101

102102

103103
def test_list_view(snap_compare):
104-
assert snap_compare(WIDGET_EXAMPLES_DIR / "list_view.py", press=["tab", "down", "down", "up"])
104+
assert snap_compare(
105+
WIDGET_EXAMPLES_DIR / "list_view.py", press=["tab", "down", "down", "up"]
106+
)
105107

106108

107109
def test_textlog_max_lines(snap_compare):
@@ -160,6 +162,11 @@ def test_offsets(snap_compare):
160162
assert snap_compare("snapshot_apps/offsets.py")
161163

162164

165+
def test_nested_auto_heights(snap_compare):
166+
"""Test refreshing widget within a auto sized container"""
167+
assert snap_compare("snapshot_apps/nested_auto_heights.py", press=["1", "2"])
168+
169+
163170
# --- Other ---
164171

165172

0 commit comments

Comments
 (0)