From e28403929d0d96b91583f623df3da8b0e556bb09 Mon Sep 17 00:00:00 2001 From: Craig Williams Date: Tue, 3 Feb 2026 14:50:18 +0000 Subject: [PATCH] Fixed lintr & complexity issues --- R/a11yCheckboxGroupInput.R | 88 ++++++++++++++-------------- R/a11yFileInput.R | 114 +++++++++++++++++++------------------ R/a11yRadioButtons.R | 54 +++++++++--------- R/deps.R | 2 +- 4 files changed, 130 insertions(+), 128 deletions(-) diff --git a/R/a11yCheckboxGroupInput.R b/R/a11yCheckboxGroupInput.R index ce29f25..a34787c 100644 --- a/R/a11yCheckboxGroupInput.R +++ b/R/a11yCheckboxGroupInput.R @@ -10,55 +10,55 @@ #' #' @export a11yCheckboxGroupInput <- function( - inputId, label, choices = NULL, selected = NULL, inline = FALSE, - width = NULL, choiceNames = NULL, choiceValues = NULL, withSelectAll = FALSE + inputId, label, choices = NULL, selected = NULL, inline = FALSE, + width = NULL, choiceNames = NULL, choiceValues = NULL, withSelectAll = FALSE ) { - args <- shiny:::normalizeChoicesArgs( - choices, choiceNames, choiceValues, FALSE - ) + args <- shiny:::normalizeChoicesArgs( + choices, choiceNames, choiceValues, FALSE + ) - selected <- shiny::restoreInput(id = inputId, default = selected) - if (!is.null(selected)) { - selected <- as.character(selected) - } + selected <- shiny::restoreInput(id = inputId, default = selected) + if (!is.null(selected)) { + selected <- as.character(selected) + } - options <- shiny:::generateOptions( - inputId, selected, inline, "checkbox", args$choiceNames, - args$choiceValues - ) + options <- shiny:::generateOptions( + inputId, selected, inline, "checkbox", args$choiceNames, + args$choiceValues + ) - ctnrClass <- "form-group shiny-input-a11ycheckboxgroup shiny-input-container" - if (inline) { - ctnrClass <- paste(ctnrClass, "shiny-input-container-inline") - } + ctnrClass <- "form-group shiny-input-a11ycheckboxgroup shiny-input-container" + if (inline) { + ctnrClass <- paste(ctnrClass, "shiny-input-container-inline") + } - selectAll <- NULL - if (withSelectAll) { - sa <- htmltools::tags$a( - href = "#", - onclick = "return checkAll(event)", - "select all", - class = "link select-all" - ) - sn <- htmltools::tags$a( - href = "#", - onclick = "return clearAll(event)", - "clear all", - class = "link select-none" - ) - selectAll <- htmltools::tags$div( - "(", sa, "/", sn, ")", class = "select-all-container" - ) - } - - fieldset <- htmltools::tags$fieldset( - id = inputId, - style = htmltools::css(width = htmltools::validateCssUnit(width)), - class = ctnrClass, - htmltools::tags$legend(label), - options, - selectAll + selectAll <- NULL + if (withSelectAll) { + sa <- htmltools::tags$a( + href = "#", + onclick = "return checkAll(event)", + "select all", + class = "link select-all" ) + sn <- htmltools::tags$a( + href = "#", + onclick = "return clearAll(event)", + "clear all", + class = "link select-none" + ) + selectAll <- htmltools::tags$div( + "(", sa, "/", sn, ")", class = "select-all-container" + ) + } - htmltools::attachDependencies(fieldset, accessibleShinyInputsDependency()) + fieldset <- htmltools::tags$fieldset( + id = inputId, + style = htmltools::css(width = htmltools::validateCssUnit(width)), + class = ctnrClass, + htmltools::tags$legend(label), + options, + selectAll + ) + + htmltools::attachDependencies(fieldset, a11yShinyInputsDependency()) } diff --git a/R/a11yFileInput.R b/R/a11yFileInput.R index 38c49cb..80c1ba2 100644 --- a/R/a11yFileInput.R +++ b/R/a11yFileInput.R @@ -8,65 +8,67 @@ #' #' @export a11yFileInput <- function( - inputId, label, multiple = FALSE, accept = NULL, width = NULL, - buttonLabel = "Browse...", placeholder = "No file selected", - capture = NULL + inputId, label, multiple = FALSE, accept = NULL, width = NULL, + buttonLabel = "Browse...", placeholder = "No file selected", + capture = NULL ) { - restoredValue <- shiny::restoreInput(id = inputId, default = NULL) - if (!is.null(restoredValue) && !is.data.frame(restoredValue)) { - warning("Restored value for ", inputId, " has incorrect format.") - restoredValue <- NULL - } - if (!is.null(restoredValue)) { - restoredValue <- jsonlite::toJSON(restoredValue, strict_atomic = FALSE) - } + restoredValue <- shiny::restoreInput(id = inputId, default = NULL) + if (!is.null(restoredValue) && !is.data.frame(restoredValue)) { + warning("Restored value for ", inputId, " has incorrect format.") + restoredValue <- NULL + } + if (!is.null(restoredValue)) { + restoredValue <- jsonlite::toJSON(restoredValue, strict_atomic = FALSE) + } - inputTag <- htmltools::tags$input( - id = inputId, - class = "shiny-input-file", - name = inputId, - type = "file", - style = "position: absolute !important; top: -99999px !important; left: -99999px !important;", - `data-restore` = restoredValue - ) - if (multiple) { - inputTag$attribs$multiple <- "multiple" - } - if (length(accept) > 0) { - inputTag$attribs$accept <- paste(accept, collapse = ",") - } - if (!is.null(capture)) { - inputTag$attribs$capture <- capture - } + inputTag <- htmltools::tags$input( + id = inputId, + class = "shiny-input-file", + name = inputId, + type = "file", + style = "position: absolute !important; top: -99999px !important; \ + left: -99999px !important;", + `data-restore` = restoredValue + ) + if (multiple) { + inputTag$attribs$multiple <- "multiple" + } + if (length(accept) > 0) { + inputTag$attribs$accept <- paste(accept, collapse = ",") + } + if (!is.null(capture)) { + inputTag$attribs$capture <- capture + } + htmltools::tags$div( + class = "form-group shiny-input-container", + style = htmltools::css(width = htmltools::validateCssUnit(width)), + htmltools::tags$label( + label, + class = "control-label", + class = if (is.null(label)) "shiny-label-null", + id = paste0(inputId, "-label"), + `for` = inputId + ), htmltools::tags$div( - class = "form-group shiny-input-container", - style = htmltools::css(width = htmltools::validateCssUnit(width)), - htmltools::tags$label( - label, - class = "control-label", - class = if (is.null(label)) "shiny-label-null", - id = paste0(inputId, "-label"), - `for` = inputId - ), - htmltools::tags$div( - class = "input-group", - htmltools::tags$label( - class = "input-group-btn input-group-prepend", - htmltools::tags$span( - class = "btn btn-default btn-file", buttonLabel, inputTag - )), - htmltools::tags$input( - type = "text", - class = "form-control", - placeholder = placeholder, - readonly = "readonly", - `aria-label` = "Uploaded file name" - ) - ), - htmltools::tags$div( - id = paste(inputId, "_progress", sep = ""), - class = "progress active shiny-file-input-progress", - htmltools::tags$div(class = "progress-bar") + class = "input-group", + htmltools::tags$label( + class = "input-group-btn input-group-prepend", + htmltools::tags$span( + class = "btn btn-default btn-file", buttonLabel, inputTag ) + ), + htmltools::tags$input( + type = "text", + class = "form-control", + placeholder = placeholder, + readonly = "readonly", + `aria-label` = "Uploaded file name" + ) + ), + htmltools::tags$div( + id = paste(inputId, "_progress", sep = ""), + class = "progress active shiny-file-input-progress", + htmltools::tags$div(class = "progress-bar") ) + ) } diff --git a/R/a11yRadioButtons.R b/R/a11yRadioButtons.R index 5bc5fd9..7d06f87 100644 --- a/R/a11yRadioButtons.R +++ b/R/a11yRadioButtons.R @@ -8,37 +8,37 @@ #' #' @export a11yRadioButtons <- function( - inputId, label, choices = NULL, selected = NULL, inline = FALSE, - width = NULL, choiceNames = NULL, choiceValues = NULL + inputId, label, choices = NULL, selected = NULL, inline = FALSE, + width = NULL, choiceNames = NULL, choiceValues = NULL ) { - args <- shiny:::normalizeChoicesArgs(choices, choiceNames, choiceValues) + args <- shiny:::normalizeChoicesArgs(choices, choiceNames, choiceValues) - selected <- shiny::restoreInput(id = inputId, default = selected) - if (is.null(selected)) { - selected <- args$choiceValues[[1]] - } else { - selected <- as.character(selected) - } - if (length(selected) > 1) { - stop("The 'selected' argument must be of length 1") - } + selected <- shiny::restoreInput(id = inputId, default = selected) + if (is.null(selected)) { + selected <- args$choiceValues[[1]] + } else { + selected <- 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 - ) + options <- shiny:::generateOptions( + inputId, selected, inline, "radio", args$choiceNames, args$choiceValues + ) - ctnrClass <- "form-group shiny-input-radiogroup shiny-input-container" - if (inline) { - ctnrClass <- paste(ctnrClass, "shiny-input-container-inline") - } + ctnrClass <- "form-group shiny-input-radiogroup shiny-input-container" + if (inline) { + ctnrClass <- paste(ctnrClass, "shiny-input-container-inline") + } - fieldset <- htmltools::tags$fieldset( - id = inputId, - style = htmltools::css(width = htmltools::validateCssUnit(width)), - class = ctnrClass, - htmltools::tags$legend(label), - options - ) + fieldset <- htmltools::tags$fieldset( + id = inputId, + style = htmltools::css(width = htmltools::validateCssUnit(width)), + class = ctnrClass, + htmltools::tags$legend(label), + options + ) - htmltools::attachDependencies(fieldset, accessibleShinyInputsDependency()) + htmltools::attachDependencies(fieldset, a11yShinyInputsDependency()) } diff --git a/R/deps.R b/R/deps.R index 3ef7f4f..65b996a 100644 --- a/R/deps.R +++ b/R/deps.R @@ -1,4 +1,4 @@ -accessibleShinyInputsDependency <- function() { +a11yShinyInputsDependency <- function() { if (getOption("shiny.minified", TRUE)) { js <- c("js/a11yShinyInputs.min.js", "js/a11yCheckboxGroupInput.min.js") css <- "css/a11yShinyInputs.min.css"