Package with an initial set of functions added

NOTE: Not all tests have been written yet!
This commit is contained in:
2026-01-22 15:59:54 +00:00
parent c94ca1549a
commit 6d3843a92b
25 changed files with 711 additions and 4 deletions

35
R/htmlMarkOptional.R Normal file
View File

@@ -0,0 +1,35 @@
#' Explicitly mark a Shiny input as optional
#'
#' @param input The Shiny input to mark as optional
#' @param optClass The classes to add to the indicator text
#'
#' @return The modified input
#' @export
#'
#' @examples
#' x <- shiny::textInput("input_id", "Some text input")
#' htmlMarkOptional(x)
htmlMarkOptional <- function(input, optClass = "text-muted font-italic") {
opt_span <- htmltools::tags$span(class = optClass, " (optional)")
tq <- htmltools::tagQuery(input)
if (tq$hasClass("shiny-input-checkboxgroup")) {
tq <- tq$
children("label")$append(opt_span)$
reset()
} else if (tq$find(".shiny-options-group")$length() > 0) {
tq <- tq$
children("label")$append(opt_span)$
reset()
} else if (tq$find(".btn-file")$length() > 0) {
tq <- tq$
children("label")$append(opt_span)$
reset()
} else {
tq <- tq$
children(".checkbox")$find("label span")$append(opt_span)$
reset()$
find("label.control-label")$append(opt_span)$
reset()
}
tq$allTags()
}