Skip to content

Commit de85be7

Browse files
committed
fix(navbar_options): Apply attributes and theme
Fixes #1941
1 parent 24ef875 commit de85be7

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

shiny/ui/_navs.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,12 @@ def layout(self, nav: Tag, content: Tag) -> TagList:
13201320
nav = div(nav, id=collapse_id, class_="collapse navbar-collapse")
13211321

13221322
nav_container.append(nav)
1323-
nav_final = tags.nav({"class": "navbar navbar-expand-md"}, nav_container)
1323+
nav_final = tags.nav(
1324+
{"class": "navbar navbar-expand-md"},
1325+
nav_container,
1326+
{"data-bs-theme": self.navbar_options.theme},
1327+
**self.navbar_options.attrs,
1328+
)
13241329

13251330
if self.navbar_options.position != "static-top":
13261331
nav_final.add_class(self.navbar_options.position)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from shiny import App, ui
2+
3+
app_ui = ui.page_navbar(
4+
ui.nav_panel(
5+
"Page 1",
6+
ui.navset_bar(
7+
ui.nav_panel("Inner 1", "Inner content"),
8+
title="Inner navbar",
9+
id="inner_navset_bar",
10+
navbar_options=ui.navbar_options(class_="bg-light", theme="light"),
11+
),
12+
),
13+
title="Title",
14+
id="page_navbar",
15+
navbar_options=ui.navbar_options(class_="bg-primary", theme="dark"),
16+
)
17+
18+
19+
def server(input, output, session):
20+
pass
21+
22+
23+
app = App(app_ui, server)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import re
2+
3+
from playwright.sync_api import Page, expect
4+
5+
from shiny.playwright import controller
6+
from shiny.run import ShinyAppProc
7+
8+
9+
def test_navset_bar_options(page: Page, local_app: ShinyAppProc) -> None:
10+
page.goto(local_app.url)
11+
12+
page_navbar = controller.PageNavbar(page, "page_navbar")
13+
expect(page_navbar._loc_navbar).to_have_class(re.compile(r"(^|\s)bg-primary(\s|$)"))
14+
expect(page_navbar._loc_navbar).to_have_attribute("data-bs-theme", "dark")
15+
16+
inner_navbar = controller.NavsetBar(page, "inner_navset_bar")
17+
expect(inner_navbar._loc_navbar).to_have_class(re.compile(r"(^|\s)bg-light(\s|$)"))
18+
expect(inner_navbar._loc_navbar).to_have_attribute("data-bs-theme", "light")

0 commit comments

Comments
 (0)