Skip to content

Commit f5dbdc9

Browse files
Merge branch 'main' into fix-1351
2 parents 94c05aa + 9acdd70 commit f5dbdc9

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2727
- Fixed visibility not affecting children https://github.com/Textualize/textual/issues/1313
2828
- Fixed issue with auto width/height and relative children https://github.com/Textualize/textual/issues/1319
2929
- Fixed issue with offset applied to containers https://github.com/Textualize/textual/issues/1256
30+
- Fixed default CSS retrieval for widgets with no `DEFAULT_CSS` that inherited from widgets with `DEFAULT_CSS` https://github.com/Textualize/textual/issues/1335
3031

3132
## [0.5.0] - 2022-11-20
3233

src/textual/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1996,9 +1996,9 @@ async def prune_widgets_task(
19961996
await self._prune_nodes(widgets)
19971997
finally:
19981998
finished_event.set()
1999+
self.refresh(layout=True)
19992000

20002001
removed_widgets = self._detach_from_dom(widgets)
2001-
self.refresh(layout=True)
20022002

20032003
finished_event = asyncio.Event()
20042004
asyncio.create_task(prune_widgets_task(removed_widgets, finished_event))

src/textual/dom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def get_path(base: Type[DOMNode]) -> str:
266266
return f"{base.__name__}"
267267

268268
for tie_breaker, base in enumerate(self._node_bases):
269-
css = base.DEFAULT_CSS.strip()
269+
css = base.__dict__.get("DEFAULT_CSS", "").strip()
270270
if css:
271271
css_stack.append((get_path(base), css, -tie_breaker))
272272

tests/test_dom.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,43 @@ class E(D):
7878
assert list(e._bindings.keys.keys()) == ["e"]
7979

8080

81+
def test_get_default_css():
82+
class A(DOMNode):
83+
pass
84+
class B(A):
85+
pass
86+
class C(B):
87+
DEFAULT_CSS = "C"
88+
class D(C):
89+
pass
90+
class E(D):
91+
DEFAULT_CSS = "E"
92+
node = DOMNode()
93+
node_css = node.get_default_css()
94+
a = A()
95+
a_css = a.get_default_css()
96+
b = B()
97+
b_css = b.get_default_css()
98+
c = C()
99+
c_css = c.get_default_css()
100+
d = D()
101+
d_css = d.get_default_css()
102+
e = E()
103+
e_css = e.get_default_css()
104+
105+
# Descendants that don't assign to DEFAULT_CSS don't add new CSS to the stack.
106+
assert len(node_css) == len(a_css) == len(b_css) == 0
107+
assert len(c_css) == len(d_css) == 1
108+
assert len(e_css) == 2
109+
110+
# Descendants do push the priority of the ancestors' rules down.
111+
assert c_css[0][2] == d_css[0][2] + 1 == 0
112+
113+
# The CSS on the stack is the correct one.
114+
assert e_css[0][1:] == ("E", 0)
115+
assert e_css[1][1:] == ("C", -2)
116+
117+
81118
@pytest.fixture
82119
def search():
83120
"""

0 commit comments

Comments
 (0)