Skip to content

Commit

Permalink
Reset styles before applying to ensure defaults are restored
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed Jan 18, 2022
1 parent fae1663 commit ea40177
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions examples/basic.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

App > View {
docks: side=left/1;
text: on #20639b;
}

Widget:hover {
Expand All @@ -28,6 +29,10 @@ Widget:hover {
border: hkey;
}

#header.-visible {
visibility: hidden;
}

#content {
text: white on #20639b;
border-bottom: hkey #0f2b41;
Expand Down
1 change: 1 addition & 0 deletions examples/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class BasicApp(App):
def on_load(self):
"""Bind keys here."""
self.bind("tab", "toggle_class('#sidebar', '-active')")
self.bind("a", "toggle_class('#header', '-visible')")

def on_mount(self):
"""Build layout here."""
Expand Down
13 changes: 6 additions & 7 deletions src/textual/css/stylesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,14 @@ def apply(self, node: DOMNode) -> None:
rule_attributes = defaultdict(list)

_check_rule = self._check_rule

node.reset_styles()

# Get the default node CSS rules
for key, default_specificity, value in node._default_rules:
rule_attributes[key].append((default_specificity, value))

# Apply styles on top of the default node CSS rules
for rule in self.rules:
for specificity in _check_rule(rule, node):
for key, rule_specificity, value in rule.styles.extract_rules(
Expand All @@ -123,13 +129,6 @@ def apply(self, node: DOMNode) -> None:
rule_attributes[key].append((rule_specificity, value))

get_first_item = itemgetter(0)

log("")
log(node)
for key, attributes in rule_attributes.items():
log(key, key in node.styles.important)
log("\t", attributes)

node_rules = [
(name, max(specificity_rules, key=get_first_item)[1])
for name, specificity_rules in rule_attributes.items()
Expand Down

0 comments on commit ea40177

Please sign in to comment.