shiny icon indicating copy to clipboard operation
shiny copied to clipboard

[Accessibility] `shiny::icons()` are not accessible to screen readers

Open jooyoungseo opened this issue 1 year ago • 2 comments

In the following example (retrieved from example(checkboxGroupInput, package = "shiny")), icons are used for informative purpose. However, the checkbox is not accessible for screen readers until explicit aria-label is used by content creator because this does not provide any icon alt text by default. It would be more desirable and safer if the aria-label is provided by default equal to font name and allow content creators to override that value if necessary.

library(shiny)

ui <- fluidPage(
  checkboxGroupInput("icons", "Choose icons:",
    choiceNames =
      list(icon("calendar"), icon("bed"),
           icon("cog"), icon("bug")),
    choiceValues =
      list("calendar", "bed", "cog", "bug")
  ),
  textOutput("txt")
)


server <- function(input, output, session) {
  output$txt <- renderText({
    icons <- paste(input$icons, collapse = ", ")
    paste("You chose", icons)
  })
}

shinyApp(ui, server)

CC @rich-iannone

Related discussion: quarto-ext/fontawesome#8

jooyoungseo avatar Jul 25 '22 13:07 jooyoungseo

FWIW you can use fontawesome::fa() directly (instead of icon()) which makes it easier to implement accessible icons

cpsievert avatar Jul 25 '22 17:07 cpsievert

@cpsievert I tried dropping fontawesome::fa() in place of icon() into

actionButton("go", "Search", icon = fontawesome::fa("magnifying-glass"))

but I see

Error in validateIcon(icon) : 
  Invalid icon. Use Shiny's 'icon()' function to generate a valid icon

ms609 avatar Aug 26 '22 15:08 ms609