| 1 |
#' Create a textarea input control |
| 2 |
#' |
| 3 |
#' Create a textarea input control for entry of unstructured text values. |
| 4 |
#' |
| 5 |
#' @inheritParams textInput |
| 6 |
#' @param height The height of the input, e.g. `'400px'`, or `'100%'`; see |
| 7 |
#' [validateCssUnit()]. |
| 8 |
#' @param cols Value of the visible character columns of the input, e.g. `80`. |
| 9 |
#' This argument will only take effect if there is not a CSS `width` rule |
| 10 |
#' defined for this element; such a rule could come from the `width` argument |
| 11 |
#' of this function or from a containing page layout such as |
| 12 |
#' [fluidPage()]. |
| 13 |
#' @param rows The value of the visible character rows of the input, e.g. `6`. |
| 14 |
#' If the `height` argument is specified, `height` will take precedence in the |
| 15 |
#' browser's rendering. |
| 16 |
#' @param resize Which directions the textarea box can be resized. Can be one of |
| 17 |
#' `"both"`, `"none"`, `"vertical"`, and `"horizontal"`. The default, `NULL`, |
| 18 |
#' will use the client browser's default setting for resizing textareas. |
| 19 |
#' @param autoresize If `TRUE`, the textarea will automatically resize to fit |
| 20 |
#' the input text. |
| 21 |
#' @return A textarea input control that can be added to a UI definition. |
| 22 |
#' |
| 23 |
#' @family input elements |
| 24 |
#' @seealso [updateTextAreaInput()] |
| 25 |
#' |
| 26 |
#' @examples |
| 27 |
#' ## Only run examples in interactive R sessions |
| 28 |
#' if (interactive()) { |
| 29 |
#' |
| 30 |
#' ui <- fluidPage( |
| 31 |
#' textAreaInput("caption", "Caption", "Data Summary", width = "1000px"), |
| 32 |
#' verbatimTextOutput("value") |
| 33 |
#' ) |
| 34 |
#' server <- function(input, output) { |
| 35 |
#' output$value <- renderText({ input$caption }) |
| 36 |
#' } |
| 37 |
#' shinyApp(ui, server) |
| 38 |
#' |
| 39 |
#' } |
| 40 |
#' |
| 41 |
#' @section Server value: |
| 42 |
#' A character string of the text input. The default value is `""` |
| 43 |
#' unless `value` is provided. |
| 44 |
#' |
| 45 |
#' @export |
| 46 |
textAreaInput <- function( |
| 47 |
inputId, |
| 48 |
label, |
| 49 |
value = "", |
| 50 |
width = NULL, |
| 51 |
height = NULL, |
| 52 |
cols = NULL, |
| 53 |
rows = NULL, |
| 54 |
placeholder = NULL, |
| 55 |
resize = NULL, |
| 56 |
..., |
| 57 |
autoresize = FALSE, |
| 58 |
updateOn = c("change", "blur") |
| 59 |
) { |
| 60 |
rlang::check_dots_empty() |
| 61 |
updateOn <- rlang::arg_match(updateOn) |
| 62 |
|
| 63 |
value <- restoreInput(id = inputId, default = value) |
| 64 |
|
| 65 |
if (!is.null(resize)) { |
| 66 |
resize <- match.arg(resize, c("both", "none", "vertical", "horizontal")) |
| 67 |
} |
| 68 |
|
| 69 |
classes <- "form-control" |
| 70 |
if (autoresize) { |
| 71 |
classes <- c(classes, "textarea-autoresize") |
| 72 |
if (is.null(rows)) { |
| 73 |
rows <- 1 |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
div( |
| 78 |
class = "shiny-input-textarea form-group shiny-input-container", |
| 79 |
style = css(width = validateCssUnit(width)), |
| 80 |
shinyInputLabel(inputId, label), |
| 81 |
tags$textarea( |
| 82 |
id = inputId, |
| 83 |
class = classes, |
| 84 |
placeholder = placeholder, |
| 85 |
style = css( |
| 86 |
width = if (!is.null(width)) "100%", |
| 87 |
height = validateCssUnit(height), |
| 88 |
resize = resize |
| 89 |
), |
| 90 |
rows = rows, |
| 91 |
cols = cols, |
| 92 |
`data-update-on` = updateOn, |
| 93 |
value |
| 94 |
) |
| 95 |
) |
| 96 |
} |