R/wa_dropdown.R

Defines functions wa_dropdown

Documented in wa_dropdown

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

#' Create a `wa-dropdown` component
#'
#' Generated wrapper for the Web Awesome `wa-dropdown` component. When
#' used as a Shiny input, action semantics are exposed through
#' `input$<input_id>` and the latest selected dropdown item value is
#' exposed through `input$<input_id>_value`. The action input increments
#' on every selection, including repeated selection of the same item. The
#' companion value input reflects the selected item's `value`, returns
#' `NULL` when the selected item has no `value`, and preserves an explicit
#' empty string `""` when that is the selected item's value. Each
#' committed action publishes a numeric action 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 dir String. Optional Web Awesome attribute.
#' @param distance Number. Default: `0`. The distance of the dropdown menu
#' from its trigger.
#' @param lang String. Optional Web Awesome attribute.
#' @param open Boolean. Default: `FALSE`. Opens or closes the dropdown.
#' @param placement Enumerated string. Allowed values: `bottom`,
#' `bottom-end`, `bottom-start`, `left`, `left-end`, `left-start`,
#' `right`, `right-end`, `right-start`, `top`, `top-end`, `top-start`.
#' Default: `bottom-start`. The placement of the dropdown menu in
#' reference to the trigger. The menu will shift to a more optimal
#' location if the preferred placement doesn't have enough room.
#' @param size Enumerated string. Allowed values: `large`, `medium`,
#' `small`. Default: `medium`. The dropdown's size.
#' @param skidding Number. Default: `0`. The offset of the dropdown menu
#' along its trigger.
#' @param trigger The element that triggers the dropdown, such as a
#' `<wa-button>` or `<button>`.
#'
#' @section Shiny Bindings:
#' `input$<input_id>` uses action semantics and invalidates on each
#' committed action, including repeated selection of the same item. The
#' Shiny action value is returned as a numeric action value.
#'
#' `input$<input_id>_value` reflects the latest selected item's `value`
#' value, returns `NULL` when the selected item has no `value` , and
#' preserves an explicit empty string `""` when that is the selected
#' item's value. The payload value is returned as a character string or
#' `NULL`.
#'
#' @return An HTML tag for the component.
#'
#' @export
wa_dropdown <- function(
  input_id,
  ...,
  class = NULL,
  style = NULL,
  dir = NULL,
  distance = NULL,
  lang = NULL,
  open = NULL,
  placement = NULL,
  size = NULL,
  skidding = NULL,
  trigger = NULL
) {
  children <- list(...)
  children <- c(
    children,
    list(
      .wa_slot(trigger, "trigger")
    )
  )

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

  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,
      "dir" = dir,
      "distance" = distance,
      "lang" = lang,
      "open" = open,
      "placement" = placement,
      "size" = size,
      "skidding" = skidding
    ),
    boolean_names = c("open"),
    boolean_arg_names = c("open" = "open")
  )

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

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.