R/wa_input.R

Defines functions update_wa_input wa_input

Documented in update_wa_input wa_input

# Generated by tools/generate_components.R. Do not edit by hand.
# nolint start: object_usage_linter.

#' Create a `wa-input` component
#'
#' Generated wrapper for the Web Awesome `wa-input` component. When used
#' as a Shiny input, `input$<input_id>` reflects the component's current
#' `value` value.
#' Generated from Web Awesome metadata.
#'
#' @param ... Child content for the component's default slot.
#' @param input_id Shiny input id for the component. This is also used as
#' the rendered DOM `id` attribute.
#' @param class Optional CSS class string.
#' @param style Optional inline CSS style string.
#' @param value String. The default value of the form control. Primarily
#' used for resetting the form control. This wrapper argument sets the
#' HTML `value` attribute, which maps to the component's `defaultValue`
#' field/property rather than its live `value` property.
#' @param disabled Boolean. Default: `FALSE`. Disables the form control.
#' @param label String. Default: `""`. The input's label. If you need to
#' display HTML, use the `label` slot instead.
#' @param hint String. Default: `""`. The input's hint. If you need to
#' display HTML, use the `hint` slot instead.
#' @param name String. Default: `null`. The name of the input, submitted
#' as a name/value pair with form data.
#' @param appearance Enumerated string. Allowed values: `filled`,
#' `filled-outlined`, `outlined`. Default: `outlined`. The input's visual
#' appearance.
#' @param autocapitalize Enumerated string. Allowed values: `characters`,
#' `none`, `off`, `on`, `sentences`, `words`. Controls whether and how
#' text input is automatically capitalized as it is entered by the user.
#' @param autocomplete String. Specifies what permission the browser has
#' to provide assistance in filling out form field values. Refer to this
#' page on MDN for available values.
#' @param autocorrect Boolean. Default: `FALSE`. Indicates whether the
#' browser's autocorrect feature is on or off. When set as an attribute,
#' use `"off"` or `"on"`. When set as a property, use `TRUE` or `FALSE`.
#' Because the upstream implementation treats attributes and properties
#' differently for this field, this argument accepts `TRUE`, `FALSE`,
#' `"on"`, `"off"`, `NULL`. `TRUE` emits `autocorrect="on"` and `FALSE`
#' emits `autocorrect="off"`. `NULL` omits the attribute. Accepted string
#' values: `"on"` is emitted unchanged; `"off"` is emitted unchanged.
#' @param autofocus Boolean. Default: `FALSE`. Indicates that the input
#' should receive focus on page load.
#' @param custom_error String. Default: `null`. Optional Web Awesome
#' attribute.
#' @param dir String. Optional Web Awesome attribute.
#' @param enterkeyhint Enumerated string. Allowed values: `done`, `enter`,
#' `go`, `next`, `previous`, `search`, `send`. Used to customize the label
#' or icon of the Enter key on virtual keyboards.
#' @param inputmode Enumerated string. Allowed values: `decimal`, `email`,
#' `none`, `numeric`, `search`, `tel`, `text`, `url`. Tells the browser
#' what type of data will be entered by the user, allowing it to display
#' the appropriate virtual keyboard on supportive devices.
#' @param lang String. Optional Web Awesome attribute.
#' @param max The input's maximum value. Only applies to date and number
#' input types.
#' @param maxlength Number. The maximum length of input that will be
#' considered valid.
#' @param min The input's minimum value. Only applies to date and number
#' input types.
#' @param minlength Number. The minimum length of input that will be
#' considered valid.
#' @param password_toggle Boolean. Default: `FALSE`. Adds a button to
#' toggle the password's visibility. Only applies to password types.
#' @param password_visible Boolean. Default: `FALSE`. Determines whether
#' or not the password is currently visible. Only applies to password
#' input types.
#' @param pattern String. A regular expression pattern to validate input
#' against.
#' @param pill Boolean. Default: `FALSE`. Draws a pill-style input with
#' rounded edges.
#' @param placeholder String. Default: `""`. Placeholder text to show as a
#' hint when the input is empty.
#' @param readonly Boolean. Default: `FALSE`. Makes the input readonly.
#' @param required Boolean. Default: `FALSE`. Makes the input a required
#' field.
#' @param size Enumerated string. Allowed values: `large`, `medium`,
#' `small`. Default: `medium`. The input's size.
#' @param spellcheck Boolean. Default: `TRUE`. Enables spell checking on
#' the input.
#' @param step Specifies the granularity that the value must adhere to, or
#' the special value `any` which means no stepping is implied, allowing
#' any numeric value. Only applies to date and number input types.
#' @param title String. Default: `""`. Optional Web Awesome attribute.
#' @param type Enumerated string. Allowed values: `date`,
#' `datetime-local`, `email`, `number`, `password`, `search`, `tel`,
#' `text`, `time`, `url`. Default: `text`. The type of input. Works the
#' same as a native `<input>` element, but only a subset of types are
#' supported. Defaults to `text`.
#' @param with_clear Boolean. Default: `FALSE`. Adds a clear button when
#' the input is not empty.
#' @param with_hint Boolean. Default: `FALSE`. Only required for SSR. Set
#' to `TRUE` if you're slotting in a `hint` element so the server-rendered
#' markup includes the hint before the component hydrates on the client.
#' @param with_label Boolean. Default: `FALSE`. Only required for SSR. Set
#' to `TRUE` if you're slotting in a `label` element so the
#' server-rendered markup includes the label before the component hydrates
#' on the client.
#' @param without_spin_buttons Boolean. Default: `FALSE`. Hides the
#' browser's built-in increment/decrement spin buttons for number inputs.
#' @param clear_icon An icon to use in lieu of the default clear icon.
#' @param end An element, such as `<wa-icon>`, placed at the end of the
#' input control.
#' @param hide_password_icon An icon to use in lieu of the default hide
#' password icon.
#' @param hint_slot Text that describes how to use the input.
#' Alternatively, you can use the `hint` attribute.
#' @param label_slot The input's label. Alternatively, you can use the
#' `label` attribute.
#' @param show_password_icon An icon to use in lieu of the default show
#' password icon.
#' @param start An element, such as `<wa-icon>`, placed at the start of
#' the input control.
#'
#' @section Shiny Bindings:
#' `input$<input_id>` reflects the component's current `value` value.
#'
#' @return An HTML tag for the component.
#'
#' @export
wa_input <- function(
  input_id,
  ...,
  class = NULL,
  style = NULL,
  value = NULL,
  disabled = NULL,
  label = NULL,
  hint = NULL,
  name = NULL,
  appearance = NULL,
  autocapitalize = NULL,
  autocomplete = NULL,
  autocorrect = NULL,
  autofocus = NULL,
  custom_error = NULL,
  dir = NULL,
  enterkeyhint = NULL,
  inputmode = NULL,
  lang = NULL,
  max = NULL,
  maxlength = NULL,
  min = NULL,
  minlength = NULL,
  password_toggle = NULL,
  password_visible = NULL,
  pattern = NULL,
  pill = NULL,
  placeholder = NULL,
  readonly = NULL,
  required = NULL,
  size = NULL,
  spellcheck = NULL,
  step = NULL,
  title = NULL,
  type = NULL,
  with_clear = NULL,
  with_hint = NULL,
  with_label = NULL,
  without_spin_buttons = NULL,
  clear_icon = NULL,
  end = NULL,
  hide_password_icon = NULL,
  hint_slot = NULL,
  label_slot = NULL,
  show_password_icon = NULL,
  start = NULL
) {
  children <- list(...)
  children <- c(
    children,
    list(
      .wa_slot(clear_icon, "clear-icon")
    )
  )
  children <- c(
    children,
    list(
      .wa_slot(end, "end")
    )
  )
  children <- c(
    children,
    list(
      .wa_slot(hide_password_icon, "hide-password-icon")
    )
  )
  children <- c(
    children,
    list(
      .wa_slot(hint_slot, "hint")
    )
  )
  children <- c(
    children,
    list(
      .wa_slot(label_slot, "label")
    )
  )
  children <- c(
    children,
    list(
      .wa_slot(show_password_icon, "show-password-icon")
    )
  )
  children <- c(
    children,
    list(
      .wa_slot(start, "start")
    )
  )

  autocorrect <- .wa_match_constructor_attr(
    autocorrect,
    "autocorrect",
    true_value = "on",
    false_value = "off",
    string_map = c(
      "on" = "on",
      "off" = "off"
    )
  )

  if (!is.null(appearance)) {
    appearance <- .wa_match_arg(
      appearance,
      "appearance",
      c(
        "filled",
        "filled-outlined",
        "outlined"
      )
    )
  }

  if (!is.null(autocapitalize)) {
    autocapitalize <- .wa_match_arg(
      autocapitalize,
      "autocapitalize",
      c(
        "characters",
        "none",
        "off",
        "on",
        "sentences",
        "words"
      )
    )
  }

  if (!is.null(enterkeyhint)) {
    enterkeyhint <- .wa_match_arg(
      enterkeyhint,
      "enterkeyhint",
      c(
        "done",
        "enter",
        "go",
        "next",
        "previous",
        "search",
        "send"
      )
    )
  }

  if (!is.null(inputmode)) {
    inputmode <- .wa_match_arg(
      inputmode,
      "inputmode",
      c(
        "decimal",
        "email",
        "none",
        "numeric",
        "search",
        "tel",
        "text",
        "url"
      )
    )
  }

  if (!is.null(size)) {
    size <- .wa_match_arg(
      size,
      "size",
      c(
        "large",
        "medium",
        "small"
      )
    )
  }

  if (!is.null(type)) {
    type <- .wa_match_arg(
      type,
      "type",
      c(
        "date",
        "datetime-local",
        "email",
        "number",
        "password",
        "search",
        "tel",
        "text",
        "time",
        "url"
      )
    )
  }

  attrs <- .wa_normalize_attrs(
    list(
      "id" = input_id,
      "class" = class,
      "style" = style,
      "value" = value,
      "disabled" = disabled,
      "label" = label,
      "hint" = hint,
      "name" = name,
      "appearance" = appearance,
      "autocapitalize" = autocapitalize,
      "autocomplete" = autocomplete,
      "autocorrect" = autocorrect,
      "autofocus" = autofocus,
      "custom-error" = custom_error,
      "dir" = dir,
      "enterkeyhint" = enterkeyhint,
      "inputmode" = inputmode,
      "lang" = lang,
      "max" = max,
      "maxlength" = maxlength,
      "min" = min,
      "minlength" = minlength,
      "password-toggle" = password_toggle,
      "password-visible" = password_visible,
      "pattern" = pattern,
      "pill" = pill,
      "placeholder" = placeholder,
      "readonly" = readonly,
      "required" = required,
      "size" = size,
      "spellcheck" = spellcheck,
      "step" = step,
      "title" = title,
      "type" = type,
      "with-clear" = with_clear,
      "with-hint" = with_hint,
      "with-label" = with_label,
      "without-spin-buttons" = without_spin_buttons
    ),
    boolean_names = c(
      "disabled",
      "autofocus",
      "password-toggle",
      "password-visible",
      "pill",
      "readonly",
      "required",
      "spellcheck",
      "with-clear",
      "with-hint",
      "with-label",
      "without-spin-buttons"
    ),
    boolean_arg_names = c(
      "disabled" = "disabled",
      "autofocus" = "autofocus",
      "password-toggle" = "password_toggle",
      "password-visible" = "password_visible",
      "pill" = "pill",
      "readonly" = "readonly",
      "required" = "required",
      "spellcheck" = "spellcheck",
      "with-clear" = "with_clear",
      "with-hint" = "with_hint",
      "with-label" = "with_label",
      "without-spin-buttons" = "without_spin_buttons"
    )
  )

  do.call(
    .wa_component,
    c(
      list("wa-input", .attrs = attrs),
      children
    )
  )
}
# nolint end

# Generated by tools/generate_components.R. Do not edit by hand.

#' Update a `wa-input` component
#'
#' Generated update helper for the Web Awesome `wa-input` component.
#'
#' @param session Shiny session object.
#' @param input_id Input id of the component to update.
#' @param value Optional value to send to the component.
#' @param label Optional label text to send to the component.
#' @param hint Optional hint text to send to the component.
#' @param disabled Optional logical disabled state to send to the component.
#'
#' @return Invisibly returns `NULL`.
#'
#' @rdname wa_input
#' @export
update_wa_input <- function(
  session,
  input_id,
  value = NULL,
  label = NULL,
  hint = NULL,
  disabled = NULL
) {
  message <- Filter(
    Negate(is.null),
    list(
      value = value,
      label = label,
      hint = hint,
      disabled = disabled
    )
  )

  if (length(message) == 0L) {
    return(invisible(NULL))
  }

  session$sendInputMessage(input_id, message)
  invisible(NULL)
}

Try the shiny.webawesome package in your browser

Any scripts or data that you put into this service are public.

shiny.webawesome documentation built on April 22, 2026, 1:09 a.m.