Skip to content

Commit f2b4764

Browse files
authored
Merge pull request #5462 from TomJGooding/fix-scrollbar-fix-scrollbar-background-opacity
fix(scrollbar): fix scrollbar background opacity
2 parents f5be1b7 + 8bb2291 commit f2b4764

File tree

4 files changed

+182
-0
lines changed

4 files changed

+182
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
4444
- Fixed select refocusing itself too late https://github.com/Textualize/textual/pull/5420
4545
- Fixed Log widget not refreshing on resize https://github.com/Textualize/textual/pull/5460
4646
- Fixed special case with calculating the height of a container where all children have dynamic heights https://github.com/Textualize/textual/pull/5463
47+
- Fixed scrollbars ignoring background opacity https://github.com/Textualize/textual/issues/5458
4748

4849

4950
## [1.0.0] - 2024-12-12

src/textual/scrollbar.py

+3
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ def render(self) -> RenderableType:
286286
else:
287287
background = styles.scrollbar_background
288288
color = styles.scrollbar_color
289+
if background.a < 1:
290+
base_background, _ = self.parent._opacity_background_colors
291+
background = base_background + background
289292
color = background + color
290293
scrollbar_style = Style.from_color(color.rich_color, background.rich_color)
291294
if self.screen.styles.scrollbar_color.a == 0:

tests/snapshot_tests/test_snapshots.py

+27
Original file line numberDiff line numberDiff line change
@@ -3284,3 +3284,30 @@ def on_mount(self) -> None:
32843284
t1.add_row(str(number) + " " * 200)
32853285

32863286
snap_compare(MyApp())
3287+
3288+
3289+
def test_scrollbar_background_with_opacity(snap_compare):
3290+
"""Regression test for https://github.com/Textualize/textual/issues/5458
3291+
The scrollbar background should match the background of the widget."""
3292+
3293+
class ScrollbarOpacityApp(App):
3294+
CSS = """
3295+
Screen {
3296+
align: center middle;
3297+
}
3298+
3299+
VerticalScroll {
3300+
width: 50%;
3301+
height: 50%;
3302+
background: blue 10%;
3303+
scrollbar-background: blue 10%;
3304+
scrollbar-color: cyan;
3305+
scrollbar-size-vertical: 10;
3306+
}
3307+
"""
3308+
3309+
def compose(self) -> ComposeResult:
3310+
with VerticalScroll():
3311+
yield Static("\n".join(f"This is some text {n}" for n in range(100)))
3312+
3313+
assert snap_compare(ScrollbarOpacityApp())

0 commit comments

Comments
 (0)