R/wa_select.R

Defines functions update_wa_select wa_select

Documented in update_wa_select wa_select

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

#' Create a `wa-select` component
#'
#' Generated wrapper for the Web Awesome `wa-select` component. When used
#' as a Shiny input, `input$<input_id>` reflects the component's current
#' `value` value. The Shiny value is returned as a character string for
#' single-select usage, or a character vector when `multiple` is `TRUE`.
#' 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 The select's value. This will be a string for single
#' select or an array for multi-select.
#' @param disabled Boolean. Default: `FALSE`. Disables the select control.
#' @param label String. Default: `""`. The select's label. If you need to
#' display HTML, use the `label` slot instead.
#' @param hint String. Default: `""`. The select's hint. If you need to
#' display HTML, use the `hint` slot instead.
#' @param name String. Default: `""`. The name of the select, submitted as
#' a name/value pair with form data.
#' @param appearance Enumerated string. Allowed values: `filled`,
#' `filled-outlined`, `outlined`. Default: `outlined`. The select's visual
#' appearance.
#' @param custom_error String. Default: `null`. Optional Web Awesome
#' attribute.
#' @param dir String. Optional Web Awesome attribute.
#' @param lang String. Optional Web Awesome attribute.
#' @param max_options_visible Number. Default: `3`. The maximum number of
#' selected options to show when `multiple` is TRUE. After the maximum,
#' "+n" will be shown to indicate the number of additional items that are
#' selected. Set to 0 to remove the limit.
#' @param multiple Boolean. Default: `FALSE`. Allows more than one option
#' to be selected.
#' @param open Boolean. Default: `FALSE`. Indicates whether or not the
#' select is open. You can toggle this attribute to show and hide the
#' menu, or you can use the `show()` and `hide()` methods and this
#' attribute will reflect the select's open state.
#' @param pill Boolean. Default: `FALSE`. Draws a pill-style select with
#' rounded edges.
#' @param placeholder String. Default: `""`. Placeholder text to show as a
#' hint when the select is empty.
#' @param placement Enumerated string. Allowed values: `bottom`, `top`.
#' Default: `bottom`. The preferred placement of the select's menu. Note
#' that the actual placement may vary as needed to keep the listbox inside
#' of the viewport.
#' @param required Boolean. Default: `FALSE`. The select's required
#' attribute.
#' @param size Enumerated string. Allowed values: `large`, `medium`,
#' `small`. Default: `medium`. The select's size.
#' @param with_clear Boolean. Default: `FALSE`. Adds a clear button when
#' the select 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 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
#' combobox.
#' @param expand_icon The icon to show when the control is expanded and
#' collapsed. Rotates on open and close.
#' @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 start An element, such as `<wa-icon>`, placed at the start of
#' the combobox.
#'
#' @section Shiny Bindings:
#' `input$<input_id>` reflects the component's current `value` value. The
#' Shiny value is returned as a character string for single-select usage,
#' or a character vector when `multiple` is `TRUE`.
#'
#' @return An HTML tag for the component.
#'
#' @export
wa_select <- function(
  input_id,
  ...,
  class = NULL,
  style = NULL,
  value = NULL,
  disabled = NULL,
  label = NULL,
  hint = NULL,
  name = NULL,
  appearance = NULL,
  custom_error = NULL,
  dir = NULL,
  lang = NULL,
  max_options_visible = NULL,
  multiple = NULL,
  open = NULL,
  pill = NULL,
  placeholder = NULL,
  placement = NULL,
  required = NULL,
  size = NULL,
  with_clear = NULL,
  with_hint = NULL,
  with_label = NULL,
  clear_icon = NULL,
  end = NULL,
  expand_icon = NULL,
  hint_slot = NULL,
  label_slot = 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(expand_icon, "expand-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(start, "start")
    )
  )

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

  if (!is.null(placement)) {
    placement <- .wa_match_arg(
      placement,
      "placement",
      c(
        "bottom",
        "top"
      )
    )
  }

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

  attrs <- .wa_normalize_attrs(
    list(
      "id" = input_id,
      "class" = class,
      "style" = style,
      "value" = value,
      "disabled" = disabled,
      "label" = label,
      "hint" = hint,
      "name" = name,
      "appearance" = appearance,
      "custom-error" = custom_error,
      "dir" = dir,
      "lang" = lang,
      "max-options-visible" = max_options_visible,
      "multiple" = multiple,
      "open" = open,
      "pill" = pill,
      "placeholder" = placeholder,
      "placement" = placement,
      "required" = required,
      "size" = size,
      "with-clear" = with_clear,
      "with-hint" = with_hint,
      "with-label" = with_label
    ),
    boolean_names = c(
      "disabled",
      "multiple",
      "open",
      "pill",
      "required",
      "with-clear",
      "with-hint",
      "with-label"
    ),
    boolean_arg_names = c(
      "disabled" = "disabled",
      "multiple" = "multiple",
      "open" = "open",
      "pill" = "pill",
      "required" = "required",
      "with-clear" = "with_clear",
      "with-hint" = "with_hint",
      "with-label" = "with_label"
    )
  )

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

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

#' Update a `wa-select` component
#'
#' Generated update helper for the Web Awesome `wa-select` 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_select
#' @export
update_wa_select <- 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.