Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/textual/css/_style_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,9 +794,8 @@ def __set__(self, obj: StylesBase, names: str | tuple[str] | None = None):
class ColorProperty:
"""Descriptor for getting and setting color properties."""

def __init__(self, default_color: Color | str, background: bool = False) -> None:
def __init__(self, default_color: Color | str) -> None:
self._default_color = Color.parse(default_color)
self._is_background = background

def __set_name__(self, owner: StylesBase, name: str) -> None:
self.name = name
Expand Down Expand Up @@ -830,11 +829,10 @@ def __set__(self, obj: StylesBase, color: Color | str | None):
_rich_traceback_omit = True
if color is None:
if obj.clear_rule(self.name):
obj.refresh(children=self._is_background)
obj.refresh(children=True)
elif isinstance(color, Color):
if obj.set_rule(self.name, color):
obj.refresh(children=self._is_background)

obj.refresh(children=True)
elif isinstance(color, str):
alpha = 1.0
parsed_color = Color(255, 255, 255)
Expand All @@ -855,8 +853,9 @@ def __set__(self, obj: StylesBase, color: Color | str | None):
),
)
parsed_color = parsed_color.with_alpha(alpha)

if obj.set_rule(self.name, parsed_color):
obj.refresh(children=self._is_background)
obj.refresh(children=True)
else:
raise StyleValueError(f"Invalid color value {color}")

Expand Down
4 changes: 2 additions & 2 deletions src/textual/css/styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class StylesBase(ABC):

auto_color = BooleanProperty(default=False)
color = ColorProperty(Color(255, 255, 255))
background = ColorProperty(Color(0, 0, 0, 0), background=True)
background = ColorProperty(Color(0, 0, 0, 0))
text_style = StyleFlagsProperty()

opacity = FractionalProperty()
Expand Down Expand Up @@ -421,7 +421,7 @@ def refresh(self, *, layout: bool = False, children: bool = False) -> None:

Args:
layout (bool, optional): Also require a layout. Defaults to False.
children (bool, opional): Also refresh children. Defaults to False.
children (bool, optional): Also refresh children. Defaults to False.
"""

@abstractmethod
Expand Down