From fa53f3df61663c749ba8a60549154a40682cfc19 Mon Sep 17 00:00:00 2001 From: Carson Date: Tue, 20 Jun 2023 15:06:50 -0500 Subject: [PATCH 1/3] Close #639: allow non tag() object to be used for a nav_panel()/nav_menu() icon --- R/navs-legacy.R | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/R/navs-legacy.R b/R/navs-legacy.R index 069ecf729..67afb61d4 100644 --- a/R/navs-legacy.R +++ b/R/navs-legacy.R @@ -294,7 +294,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 ), @@ -314,7 +314,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 @@ -439,22 +439,16 @@ 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 - ) - } - is_fa <- grepl("fa-", tagGetAttribute(x, "class") %||% "", fixed = TRUE) - if (!is_fa) { - return(x) + if (inherits(x, "shiny.tag")) { + is_fa <- grepl("fa-", tagGetAttribute(x, "class") %||% "", fixed = TRUE) + if (is_fa) { + # specify fixed-width for font-awesome + x <- tagAppendAttributes(x, class = "fa-fw") + } } - # for font-awesome we specify fixed-width - tagAppendAttributes(x, class = "fa-fw") + x } # Text filter for navbarMenu's (plain text) separators From b6c58a0e0d7508aa9c67143589fae153787ce055 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 14 Jul 2023 16:47:36 -0500 Subject: [PATCH 2/3] Code review --- R/navs-legacy.R | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/R/navs-legacy.R b/R/navs-legacy.R index 67afb61d4..42e78018f 100644 --- a/R/navs-legacy.R +++ b/R/navs-legacy.R @@ -439,16 +439,13 @@ findAndMarkSelectedTab <- function(tabs, selected, foundSelected) { } prepTabIcon <- function(x = NULL) { + if (!inherits(x, "shiny.tag")) return(x) - if (inherits(x, "shiny.tag")) { - is_fa <- grepl("fa-", tagGetAttribute(x, "class") %||% "", fixed = TRUE) - if (is_fa) { - # specify fixed-width for font-awesome - x <- tagAppendAttributes(x, class = "fa-fw") - } - } + is_fa <- grepl("fa-", tagGetAttribute(x, "class") %||% "", fixed = TRUE) + if (!is_fa) return(x) - x + # specify fixed-width for font-awesome + tagAppendAttributes(x, class = "fa-fw") } # Text filter for navbarMenu's (plain text) separators From fe329a4d08c11d8f0b1f4bd2021d6674448006ca Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 14 Jul 2023 16:52:38 -0500 Subject: [PATCH 3/3] Update news --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 4cde02346..6297735ee 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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