R/wa_tree.R

Defines functions wa_tree

Documented in wa_tree

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

#' Create a `wa-tree` component
#'
#' Generated wrapper for the Web Awesome `wa-tree` component. When used as
#' a Shiny input, `input$<input_id>` reflects the component's current
#' semantic `selectedItemIds` state. The Shiny value is returned as a
#' character vector. For stable Shiny selection values, selectable
#' descendant `wa-tree-item` elements should have DOM `id` attributes.
#' 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 lang String. Optional Web Awesome attribute.
#' @param selection Enumerated string. Allowed values: `leaf`, `multiple`,
#' `single`. Default: `single`. The selection behavior of the tree. Single
#' selection allows only one node to be selected at a time. Multiple
#' displays checkboxes and allows more than one node to be selected. Leaf
#' allows only leaf nodes to be selected.
#' @param collapse_icon The icon to show when the tree item is collapsed.
#' Works best with `<wa-icon>`.
#' @param expand_icon The icon to show when the tree item is expanded.
#' Works best with `<wa-icon>`.
#'
#' @section Shiny Bindings:
#' `input$<input_id>` reflects the component's current semantic
#' `selectedItemIds` state. The Shiny value is returned as a character
#' vector.
#'
#' @return An HTML tag for the component.
#'
#' @export
wa_tree <- function(
  input_id,
  ...,
  class = NULL,
  style = NULL,
  dir = NULL,
  lang = NULL,
  selection = NULL,
  collapse_icon = NULL,
  expand_icon = NULL
) {
  children <- list(...)
  children <- c(
    children,
    list(
      .wa_slot(collapse_icon, "collapse-icon")
    )
  )
  children <- c(
    children,
    list(
      .wa_slot(expand_icon, "expand-icon")
    )
  )
  .wa_warn_missing_tree_item_ids(children, input_id = input_id)
  if (!is.null(selection)) {
    selection <- .wa_match_arg(
      selection,
      "selection",
      c(
        "leaf",
        "multiple",
        "single"
      )
    )
  }

  attrs <- .wa_normalize_attrs(
    list(
      "id" = input_id,
      "class" = class,
      "style" = style,
      "dir" = dir,
      "lang" = lang,
      "selection" = selection
    ),
    boolean_names = character(),
    boolean_arg_names = NULL
  )

  do.call(
    .wa_component,
    c(
      list("wa-tree", .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.