a11y_selectInput: Accessible select input

View source: R/inputs.R

a11y_selectInputR Documentation

Accessible select input

Description

A wrapper for shiny::selectInput() with ARIA attributes according to BITV 2.0, enforced visible label, optional heading annotation, custom CSS class, and sr-only description support.

Usage

a11y_selectInput(
  inputId,
  label,
  choices,
  selected = NULL,
  multiple = FALSE,
  ...,
  describedby = NULL,
  describedby_text = NULL,
  heading_level = NULL,
  aria_controls = NULL
)

Arguments

inputId

Input ID

label

Visible label (required)

choices

Choice list (as in shiny::selectInput())

selected

Preselection (optional)

multiple

Multiple selection (default: FALSE)

...

Additional arguments for shiny::selectInput()

describedby

ID of an element for aria-describedby (optional)

describedby_text

Creates an sr-only ⁠<div>⁠ that serves as a description and is linked via aria-describedby. If describedby is set, its ID is used, otherwise an ID is generated (⁠<inputId>-desc⁠). (optional)

heading_level

1–6, marks the visible ⁠<label>⁠ as a heading via role="heading" and aria-level (optional)

aria_controls

(optional) ARIA controls attribute

Value

HTML tag of the input component (possibly with sr-only description)

Examples

# Basic select input
a11y_selectInput("colour", "Colour",
  choices = c("Red", "Green", "Blue")
)

# With a screen-reader-only description
a11y_selectInput("size", "Size",
  choices = c("S", "M", "L"),
  describedby_text = "Choose a t-shirt size"
)

# Label promoted to a heading (useful for sectioned forms)
a11y_selectInput("n_breaks", "Number of bins",
  choices = c(10, 20, 35, 50),
  selected = 20,
  heading_level = 3
)

# Linking to an existing description element via its ID
htmltools::tags$p(id = "n_breaks_help", "Choose how many bins to display")
a11y_selectInput("n_breaks2", "Number of bins",
  choices = c(10, 20, 35, 50),
  describedby = "n_breaks_help"
)


a11yShiny documentation built on April 1, 2026, 5:07 p.m.