diff --git a/CHANGELOG.md b/CHANGELOG.md index a52f8df41d..564e8a321b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/textual/css/_style_properties.py b/src/textual/css/_style_properties.py index 658932165e..9667e97c65 100644 --- a/src/textual/css/_style_properties.py +++ b/src/textual/css/_style_properties.py @@ -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: diff --git a/tests/css/test_styles.py b/tests/css/test_styles.py index e21572478a..b31ad46548 100644 --- a/tests/css/test_styles.py +++ b/tests/css/test_styles.py @@ -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", [