Skip to content

Commit

Permalink
Allow non tag() object to be used for a nav_panel()/nav_menu()
Browse files Browse the repository at this point in the history
…icon (#645)
  • Loading branch information
cpsievert authored Jul 14, 2023
1 parent 69c9db2 commit 3ce06f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
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

0 comments on commit 3ce06f0

Please sign in to comment.