Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default to a11y='sem' when a title is provided #8

Merged
merged 5 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions R/bs-icon.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
#' that.
#' @param a11y Cases that distinguish the role of the icon and inform which
#' accessibility attributes to be used. Icons can either be `"deco"`
#' (decorative, the default case) or `"sem"` (semantic). Using `"none"` will
#' result in no accessibility features for the icon.
#' (decorative, the default case), `"sem"` (semantic), `"none"` (no
#' accessibility features). The default, `"auto"`, resolves to `"sem"` if a
#' title is provided (and `"deco"` otherwise).
#' @param ... additional CSS properties (e.g., `margin`, `position`, etc.)
#' placed on the `<svg>` tag.
#'
Expand All @@ -40,7 +41,7 @@ bs_icon <- function(
size = "1em",
class = NULL,
title = NULL,
a11y = c("deco", "sem", "none"),
a11y = c("auto", "deco", "sem", "none"),
...
) {

Expand Down Expand Up @@ -74,9 +75,13 @@ bs_icon <- function(

# Generate accessibility attributes if either of
# the "deco" or "sem" cases are chosen
a11y <- match.arg(a11y)
a11y <- rlang::arg_match(a11y)
a11y_attrs <- ""

if (a11y == "auto") {
a11y <- if (is.null(title)) "deco" else "sem"
}

if (a11y == "deco") {
a11y_attrs <- 'aria-hidden="true" role="img" '
} else if (a11y == "sem") {
Expand Down
7 changes: 4 additions & 3 deletions man/bs_icon.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion tests/testthat/test-bsicon.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ test_that("bs_icon() returns a SVG string and renders as HTML", {
"rocket", size = "7rem",
class = "text-success mt-1",
title = "A rocket ship",
a11y = "sem",
border = "2px solid red"
)
expect_snapshot(as.character(rocket), cran = TRUE)
Expand Down