From de85be749d1f332da4899e71c958d2b5281c44ae Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Tue, 25 Mar 2025 10:28:10 -0400 Subject: [PATCH 1/5] fix(navbar_options): Apply attributes and `theme` Fixes #1941 --- shiny/ui/_navs.py | 7 +++++- .../components/nav/navset_bar_options/app.py | 23 +++++++++++++++++++ .../test_navset_bar_options.py | 18 +++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/playwright/shiny/components/nav/navset_bar_options/app.py create mode 100644 tests/playwright/shiny/components/nav/navset_bar_options/test_navset_bar_options.py diff --git a/shiny/ui/_navs.py b/shiny/ui/_navs.py index 700e58780..4beb2a1a0 100644 --- a/shiny/ui/_navs.py +++ b/shiny/ui/_navs.py @@ -1320,7 +1320,12 @@ def layout(self, nav: Tag, content: Tag) -> TagList: nav = div(nav, id=collapse_id, class_="collapse navbar-collapse") nav_container.append(nav) - nav_final = tags.nav({"class": "navbar navbar-expand-md"}, nav_container) + nav_final = tags.nav( + {"class": "navbar navbar-expand-md"}, + nav_container, + {"data-bs-theme": self.navbar_options.theme}, + **self.navbar_options.attrs, + ) if self.navbar_options.position != "static-top": nav_final.add_class(self.navbar_options.position) diff --git a/tests/playwright/shiny/components/nav/navset_bar_options/app.py b/tests/playwright/shiny/components/nav/navset_bar_options/app.py new file mode 100644 index 000000000..f1c2fba76 --- /dev/null +++ b/tests/playwright/shiny/components/nav/navset_bar_options/app.py @@ -0,0 +1,23 @@ +from shiny import App, ui + +app_ui = ui.page_navbar( + ui.nav_panel( + "Page 1", + ui.navset_bar( + ui.nav_panel("Inner 1", "Inner content"), + title="Inner navbar", + id="inner_navset_bar", + navbar_options=ui.navbar_options(class_="bg-light", theme="light"), + ), + ), + title="Title", + id="page_navbar", + navbar_options=ui.navbar_options(class_="bg-primary", theme="dark"), +) + + +def server(input, output, session): + pass + + +app = App(app_ui, server) diff --git a/tests/playwright/shiny/components/nav/navset_bar_options/test_navset_bar_options.py b/tests/playwright/shiny/components/nav/navset_bar_options/test_navset_bar_options.py new file mode 100644 index 000000000..1fff16971 --- /dev/null +++ b/tests/playwright/shiny/components/nav/navset_bar_options/test_navset_bar_options.py @@ -0,0 +1,18 @@ +import re + +from playwright.sync_api import Page, expect + +from shiny.playwright import controller +from shiny.run import ShinyAppProc + + +def test_navset_bar_options(page: Page, local_app: ShinyAppProc) -> None: + page.goto(local_app.url) + + page_navbar = controller.PageNavbar(page, "page_navbar") + expect(page_navbar._loc_navbar).to_have_class(re.compile(r"(^|\s)bg-primary(\s|$)")) + expect(page_navbar._loc_navbar).to_have_attribute("data-bs-theme", "dark") + + inner_navbar = controller.NavsetBar(page, "inner_navset_bar") + expect(inner_navbar._loc_navbar).to_have_class(re.compile(r"(^|\s)bg-light(\s|$)")) + expect(inner_navbar._loc_navbar).to_have_attribute("data-bs-theme", "light") From 40cdb232119a043337a1ac636fa16660f5418738 Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Tue, 25 Mar 2025 10:29:48 -0400 Subject: [PATCH 2/5] docs: Add changelog item --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24d64d85a..57c929b2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * The `.get_latest_stream_result()` method on `ui.MarkdownStream()` was deprecated in favor of the new `.latest_stream` property. Call `.result()` on the property to get the latest result, `.status` to check the status, and `.cancel()` to cancel the stream. +* `ui.page_navbar()` and `ui.navset_bar()` now correctly apply `theme` and additional attributes from `navbar_options` created with `ui.navbar_options()`. (#1942) + ### Bug fixes * Fixed an issue where the `
` areas of `ui.page_sidebar()` and `ui.page_navbar()` (with a `sidebar`) were made to be a fillable containers even when `fillable=False`. (#1816) From dcf44cdabcc973a7f6ddbd224abd22e1734009f5 Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Tue, 25 Mar 2025 10:32:06 -0400 Subject: [PATCH 3/5] docs: Fixup changelog from previous release --- CHANGELOG.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57c929b2e..56774871f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,12 +64,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Breaking changes -* The navbar-related style options of `ui.page_navbar()` and `ui.navset_bar()` have been consolidated into a single `navbar_options` argument that pairs with a new `ui.navbar_options()` helper. Using the direct `position`, `bg`, `inverse`, `collapsible`, and `underline` arguments will continue to work with a deprecation message. +* The navbar-related style options of `ui.page_navbar()` and `ui.navset_bar()` have been consolidated into a single `navbar_options` argument that pairs with a new `ui.navbar_options()` helper. Using the direct `position`, `bg`, `inverse`, `collapsible`, and `underline` arguments will continue to work with a deprecation message. (#1822) Related to this change, `ui.navset_bar()` now defaults to using `underline=True` so that it uses the same set of default `ui.navbar_options()` as the page variant. In `ui.navbar_options()`, `inverse` is replaced by `theme`, which takes values `"light"` (dark text on a **light** background), `"dark"` (light text on a **dark** background), or `"auto"` (follow page settings). -* The Shiny Core component `shiny.ui.Chat()` no longer has a `.ui()` method. This method -was never intended to be used in Shiny Core (in that case, use `shiny.ui.chat_ui()`) to create the UI element. Note that the `shiny.express.ui.Chat()` class still has a `.ui()` method. (#1840) +* The Shiny Core component `shiny.ui.Chat()` no longer has a `.ui()` method. This method was never intended to be used in Shiny Core (in that case, use `shiny.ui.chat_ui()`) to create the UI element. Note that the `shiny.express.ui.Chat()` class still has a `.ui()` method. (#1840) ### Bug fixes From e450b5e553421ee88f26543d3c8b86dfd4f23f36 Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Tue, 25 Mar 2025 10:34:16 -0400 Subject: [PATCH 4/5] chore: add types --- .../playwright/shiny/components/nav/navset_bar_options/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/playwright/shiny/components/nav/navset_bar_options/app.py b/tests/playwright/shiny/components/nav/navset_bar_options/app.py index f1c2fba76..4fdab5ed0 100644 --- a/tests/playwright/shiny/components/nav/navset_bar_options/app.py +++ b/tests/playwright/shiny/components/nav/navset_bar_options/app.py @@ -1,4 +1,4 @@ -from shiny import App, ui +from shiny import App, Inputs, Outputs, Session, ui app_ui = ui.page_navbar( ui.nav_panel( @@ -16,7 +16,7 @@ ) -def server(input, output, session): +def server(input: Inputs, output: Outputs, session: Session): pass From 160673e200dc61235f612848080e1251138d4939 Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Tue, 25 Mar 2025 10:39:04 -0400 Subject: [PATCH 5/5] tests: Update navbar markup snapshot --- tests/pytest/test_navs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pytest/test_navs.py b/tests/pytest/test_navs.py index e1e6c9f4b..d017c0355 100644 --- a/tests/pytest/test_navs.py +++ b/tests/pytest/test_navs.py @@ -157,7 +157,7 @@ def test_navset_bar_markup(): assert TagList(x).render()["html"] == textwrap.dedent( """\ -