Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow non tag() object to be used for a nav_panel()/nav_menu() icon #645

Merged
merged 4 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

* Closed #636: Outputs in sidebars now work as expected when an initially-closed sidebar is opened. (#624)
* Closed #640: `accordion()` no longer errors when an `id` isn't supplied inside a Shiny `session` context. (#646)
* Closed #639: `nav_panel()`'s `icon` argument now supports generic `HTML()`, meaning that things like `bsicons::bs_icon()` and `fontawesome::fa()` can be used as values. (#645)

# bslib 0.5.0

Expand Down
19 changes: 5 additions & 14 deletions R/navs-legacy.R
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ navbarMenu_ <- function(title, ..., menuName = title, icon = NULL, align) {
tabs = list2(...),
# Here for legacy reasons
# https://github.com/cran/miniUI/blob/74c87d3/R/layout.R#L369
iconClass = tagGetAttribute(icon, "class"),
iconClass = if (inherits(icon, "shiny.tag")) tagGetAttribute(icon, "class"),
icon = icon,
align = align
),
Expand All @@ -315,7 +315,7 @@ tabPanel_ <- function(title, ..., value = title, icon = NULL) {
`data-value` = value,
# Here for legacy reasons
# https://github.com/cran/miniUI/blob/74c87d/R/layout.R#L395
`data-icon-class` = tagGetAttribute(icon, "class"),
`data-icon-class` = if (inherits(icon, "shiny.tag")) tagGetAttribute(icon, "class"),
...
)
attr(pane, "_shiny_icon") <- icon
Expand Down Expand Up @@ -440,21 +440,12 @@ findAndMarkSelectedTab <- function(tabs, selected, foundSelected) {
}

prepTabIcon <- function(x = NULL) {
if (is.null(x)) return(NULL)
if (!inherits(x, "shiny.tag")) {
stop(
"`icon` must be a `shiny.tag` object. ",
"Try passing `icon()` (or `tags$i()`) to the `icon` parameter.",
call. = FALSE
)
}
if (!inherits(x, "shiny.tag")) return(x)

is_fa <- grepl("fa-", tagGetAttribute(x, "class") %||% "", fixed = TRUE)
if (!is_fa) {
return(x)
}
if (!is_fa) return(x)

# for font-awesome we specify fixed-width
# specify fixed-width for font-awesome
tagAppendAttributes(x, class = "fa-fw")
}

Expand Down
Loading