Fixed CSS transparency bug in _style_properties.py #5890
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Please review the following checklist.
I believe I've found the fix for this issue as originally reported in the Discord help channel.
So first off, original MRE showcasing the problem since, as requested, we're going straight to PR without an attached issue:
The issue was that in the
ColorProperties
class in css/_style_properties.py, it was not accounting for the case where a named color might have alpha built into it. Which is of course only one named color, "transparency".Line in question:
textual/src/textual/css/_style_properties.py
Line 994 in 6e4f77b
In the fix, I've added an extra line:
Previously it would only get the alpha
if token.endswith("%")
, which was missing the edge case where the string is "transparent". Now after parsing the string, it extracts whatever alpha value is to re-use it for theparsed_color.with_alpha(alpha)
call.I thought this was a nice solution since its a one-line addition, which is a bit more elegant than making an extra condition just for the "transparent" string. But regardless, I'm pretty sure this is the root of the issue. Let me know if you think this is maybe not the best way to fix it.