diff --git a/R/input.R b/R/input.R index 3b345152..8bb2211e 100644 --- a/R/input.R +++ b/R/input.R @@ -134,15 +134,41 @@ textAreaInput <- function(inputId, label, value = "", width = NULL, placeholder #' @param inputId Input name. The same as \code{input_id}. #' @rdname text_input #' @export -textInput <- function(inputId, label, value = "", width = NULL, - placeholder = NULL, type = "text") { +textInput <- function(inputId, label, value = "", width = NULL, placeholder = NULL, + type = "text", class = "field", label_class = "ui label") { shiny::div( class = "ui form", - style = if (!is.null(width)) glue::glue("width: {shiny::validateCssUnit(width)};"), - shiny::div(class = "field", - if (!is.null(label)) tags$label(label, `for` = inputId), - text_input(inputId, value = value, placeholder = placeholder, type = type) - ) + style = if (!is.null(width)) + glue::glue("width: {shiny::validateCssUnit(width)};"), + if (label_class == "ui label" || + grepl("below", label_class, fixed = TRUE) || + grepl("right", label_class, fixed = TRUE)) { + shiny::div( + class = class, + shiny::div(class = label_class, + if (!is.null(label)) + tags$label(label, `for` = inputId)), + text_input( + inputId, + value = value, + placeholder = placeholder, + type = type + ) + ) + } else { + shiny::div( + class = class, + text_input( + inputId, + value = value, + placeholder = placeholder, + type = type + ), + shiny::div(class = label_class, + if (!is.null(label)) + tags$label(label, `for` = inputId)) + ) + } ) } diff --git a/examples/form_inputs/app.R b/examples/form_inputs/app.R index 744dec38..9a8e2d6b 100644 --- a/examples/form_inputs/app.R +++ b/examples/form_inputs/app.R @@ -19,6 +19,44 @@ ui <- shinyUI( tags$label("Text"), text_input("text_ex", value = "", type = "text", placeholder = "Enter Text...") ), + field( + textInput("text_ex", + value = "", + type = "text", + placeholder = "Enter Text...", + label = "Text", + class = "ui right labeled input" + ) + ), + field( + textInput("text_ex", + value = "", + type = "text", + placeholder = "Enter Text...", + label = "Text", + label_class = "ui pointing below blue label", + ) + ), + field( + textInput("text_ex", + value = "", + type = "text", + placeholder = "Enter Text...", + label = "Text", + class = "inline field", + label_class = "ui left purple basic tag label", + ) + ), + field( + textInput("text_ex", + value = "", + type = "text", + placeholder = "Enter Text...", + label = "Text", + class = "inline field", + label_class = "ui right pointing label", + ) + ), field( tags$label("Text Area"), text_input( diff --git a/tests/testthat/test_input.R b/tests/testthat/test_input.R index c27c92c9..a9ced03c 100644 --- a/tests/testthat/test_input.R +++ b/tests/testthat/test_input.R @@ -32,7 +32,28 @@ test_that("test textInput", { si_str <- as.character(textInput("text_input", "Text Input")) expect_true(any(grepl("