Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Labeled inputs ability to set label position #416

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions R/input.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)
}
)
}

Expand Down
38 changes: 38 additions & 0 deletions examples/form_inputs/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
23 changes: 22 additions & 1 deletion tests/testthat/test_input.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,28 @@ test_that("test textInput", {
si_str <- as.character(textInput("text_input", "Text Input"))
expect_true(any(grepl("<div class=\"ui form\">\n <div class=\"field\">",
si_str, fixed = TRUE)))

#input label
si_str <- as.character(
textInput(
"text_ex",
value = "",
type = "text",
placeholder = "Enter Text...",
label = "Text",
class = "ui right labeled input",
label_class = "ui blue label"
)
)
expect_true(any(
grepl(
"<div class=\"ui form\">\n <div class=\"ui right labeled input\">\n",
si_str,
fixed = TRUE
)
) &&
any(grepl(
"<div class=\"ui blue label\">\n", si_str, fixed = TRUE
)))
})

test_that("test textAreaInput", {
Expand Down