Skip to content

Commit

Permalink
Close #639: allow non tag() object to be used for a nav_panel()/nav_m…
Browse files Browse the repository at this point in the history
…enu() icon
  • Loading branch information
cpsievert committed Jun 20, 2023
1 parent 6abfd6c commit 3574379
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions R/navs-legacy.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3574379

Please sign in to comment.