From 9a142d22caafb44e454287b37422df0c1a317b30 Mon Sep 17 00:00:00 2001 From: kaygo Date: Mon, 13 Nov 2023 14:39:05 +0000 Subject: [PATCH] accessibility radio button and action link update --- R/utils_accessibility.R | 55 ++++++++++++++++++++++++ inst/app/www/assets/favicons/favicon.svg | 3 -- man/nhs_selectizeInput.Rd | 2 +- 3 files changed, 56 insertions(+), 4 deletions(-) delete mode 100644 inst/app/www/assets/favicons/favicon.svg diff --git a/R/utils_accessibility.R b/R/utils_accessibility.R index 6c3b075..09e2f36 100644 --- a/R/utils_accessibility.R +++ b/R/utils_accessibility.R @@ -124,3 +124,58 @@ nhs_card_tabstop <- function(header, tabindex = 0, ...) { nhs_card_tabstop <- div(nhs_card(header, ...)) %>% htmltools::tagAppendAttributes(`tabindex` = tabindex) } + + + + + + + +#' accessible_radio_button +#' +#' @param ... radio content +#' +#' @noRd +#' +accessible_radio_button <- function(inputId, label, choices = NULL, selected = NULL, + inline = FALSE, width = NULL, choiceNames = NULL, + choiceValues = NULL) { + args <- shiny:::normalizeChoicesArgs(choices, choiceNames, choiceValues) + + selected <- shiny::restoreInput(id = inputId, default = selected) + + selected <- if (is.null(selected)) args$choiceValues[[1]] else as.character(selected) + if (length(selected) > 1) stop("The 'selected' argument must be of length 1") + + options <- shiny:::generateOptions( + inputId, selected, inline, "radio", args$choiceNames, args$choiceValues + ) + + divClass <- "form-group shiny-input-radiogroup shiny-input-container" + if (inline) divClass <- paste(divClass, "shiny-input-container-inline") + + tags$fieldset( + tags$legend(label), + tags$div( + id = inputId, + style = htmltools::css(width = validateCssUnit(width)), + class = divClass, + role = "radiogroup", + options + ) + ) +} + +#' accessible_action_link +#' +#' @param ... action link text +#' +#' @noRd +#' +accessible_action_link <- function(inputId, label, icon = NULL, ...) { + value <- restoreInput(id = inputId, default = NULL) + tags$a(id = inputId, href = "#", class = "action-button", + `data-val` = value, style = "color: #004280; text-decoration: underline;", + list(shiny:::validateIcon(icon), label), + ...) +} diff --git a/inst/app/www/assets/favicons/favicon.svg b/inst/app/www/assets/favicons/favicon.svg deleted file mode 100644 index f5185f2..0000000 --- a/inst/app/www/assets/favicons/favicon.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/man/nhs_selectizeInput.Rd b/man/nhs_selectizeInput.Rd index de1ab9f..fe0b0e1 100644 --- a/man/nhs_selectizeInput.Rd +++ b/man/nhs_selectizeInput.Rd @@ -24,7 +24,7 @@ from the server. For example, long lists of organisations or drugs. It allows to search for options by typing as well as dropdown. } \examples{ -# In module UI function +# In module UI function nhs_selectizeInput( "fruit", "Choose some fruit",