Skip to content

Commit

Permalink
fix: allow integer for fractional styles
Browse files Browse the repository at this point in the history
  • Loading branch information
TomJGooding committed Sep 29, 2023
1 parent 92abb57 commit b27f7d2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- `Pilot.click`/`Pilot.hover` can't use `Screen` as a selector https://github.com/Textualize/textual/issues/3395
- App exception when a `Tree` is initialized/mounted with `disabled=True` https://github.com/Textualize/textual/issues/3407
- Fixed fractional styles to allow integer values https://github.com/Textualize/textual/issues/3414

### Added

Expand Down
4 changes: 2 additions & 2 deletions src/textual/css/_style_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,8 +1063,8 @@ def __set__(self, obj: StylesBase, value: float | str | None) -> None:
obj.refresh(children=self.children)
return

if isinstance(value, float):
float_value = value
if isinstance(value, (int, float)):
float_value = float(value)
elif isinstance(value, str) and value.endswith("%"):
float_value = float(Scalar.parse(value).value) / 100
else:
Expand Down
7 changes: 7 additions & 0 deletions tests/css/test_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ def test_opacity_set_invalid_type_error():
styles.text_opacity = "invalid value"


def test_opacity_set_allows_integer_value():
"""Regression test for https://github.com/Textualize/textual/issues/3414"""
styles = RenderStyles(DOMNode(), Styles(), Styles())
styles.text_opacity = 0
assert styles.text_opacity == 0.0


@pytest.mark.parametrize(
"size_dimension_input,size_dimension_expected_output",
[
Expand Down

0 comments on commit b27f7d2

Please sign in to comment.