Skip to content

Commit 02a5735

Browse files
authored
Add missing sidebar stylesheet dep (#667)
1 parent 422e745 commit 02a5735

File tree

5 files changed

+75
-0
lines changed

5 files changed

+75
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
### Bug fixes
1414

15+
* Fixed #666: Added missing sidebar stylesheet dependency. (#667)
16+
1517
### Other changes
1618

1719

e2e/bugs/0666-sidebar/app.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from colors import bg_color, fg_color
2+
3+
from shiny import App, ui
4+
5+
app_ui = ui.page_fluid(
6+
ui.tags.style(
7+
f"""
8+
:root .bslib-sidebar-layout {{
9+
--bslib-sidebar-bg: {bg_color};
10+
--bslib-sidebar-fg: {fg_color};
11+
}}
12+
"""
13+
),
14+
ui.layout_sidebar(
15+
ui.panel_sidebar("`main` - Sidebar content", id="main-sidebar"),
16+
ui.panel_main("`main` - Main content", id="main-content"),
17+
),
18+
# # Can not use X sidebar as only one htmldependency wins.
19+
# import shiny.experimental as x
20+
# x.ui.layout_sidebar(
21+
# x.ui.sidebar(
22+
# "`x` - Sidebar content",
23+
# open="always",
24+
# width=f"{int(4 / 12 * 100)}%",
25+
# id="x-sidebar",
26+
# ),
27+
# "`x` - Main content",
28+
# id="x-content",
29+
# ),
30+
)
31+
32+
app = App(app_ui, None)

e2e/bugs/0666-sidebar/colors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Must use resolved rgb colors
2+
3+
bg_color: str = "rgb(0, 100, 0)" # `darkgreen`
4+
fg_color: str = "rgb(254, 254, 254)" # ~`white` - 1
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from __future__ import annotations
2+
3+
from colors import bg_color, fg_color
4+
from conftest import ShinyAppProc
5+
from playwright.sync_api import Page, expect
6+
7+
8+
def test_colors_are_rgb() -> None:
9+
assert bg_color.startswith("rgb(")
10+
assert fg_color.startswith("rgb(")
11+
12+
13+
def test_sidebar_bg_colors(page: Page, local_app: ShinyAppProc) -> None:
14+
page.goto(local_app.url)
15+
16+
main_content = page.locator("#main-content")
17+
main_sidebar = page.locator("#main-sidebar")
18+
main_layout = main_sidebar.locator("..")
19+
20+
# x_content = page.locator("#x-content")
21+
# x_sidebar = page.locator("#x-sidebar")
22+
# x_layout = x_sidebar.locator("..")
23+
24+
expect(main_layout).to_have_attribute("data-bslib-sidebar-open", "always")
25+
# expect(x_layout).to_have_attribute("data-bslib-sidebar-open", "always")
26+
27+
expect(main_content).to_have_text("`main` - Main content")
28+
# expect(x_content).to_have_text("`x` - Main content")
29+
expect(main_sidebar).to_have_text("`main` - Sidebar content")
30+
# expect(x_sidebar).to_have_text("`x` - Sidebar content")
31+
32+
# Only works if css file is loaded
33+
expect(main_sidebar).to_have_css("background-color", bg_color)
34+
# expect(x_sidebar).to_have_css("background-color", bg_color)
35+
expect(main_sidebar).to_have_css("color", fg_color)
36+
# expect(x_sidebar).to_have_css("color", fg_color)

shiny/ui/_x/_htmldeps.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def sidebar_dependency() -> HTMLDependency:
3434
"subdir": _x_sidebar_path,
3535
},
3636
script={"src": "sidebar.min.js"},
37+
stylesheet={"href": "sidebar.css"},
3738
all_files=True,
3839
)
3940

0 commit comments

Comments
 (0)