diff --git a/NEWS.md b/NEWS.md index aa2ca2ace..310ebf2bc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # pkgdown (development version) +* Custom navbars that specify `icon` but not `aria-label` will now generate a message reminding you to provide one for to improve accessibility (#2533). * `init_site()` will no longer automatically build favicons on CI systems (e.g. GHA). This is an expensive operation that uses an external service so it should only be run locally (#2553). * `build_home_index()` now reports when rendering the home page (#2544). * Bootstrap 3 has been deprecated. It was superseded in December 2021, and now we're starting to more directly encourage folks to move away from it. diff --git a/R/navbar-menu.R b/R/navbar-menu.R index 7f500d0cc..a7cf8fd07 100644 --- a/R/navbar-menu.R +++ b/R/navbar-menu.R @@ -197,6 +197,18 @@ navbar_html_text <- function(x) { iconset <- purrr::map_chr(strsplit(icon_classes, "-"), 1) icon <- html_tag("span", class = unique(c(iconset, classes))) + + if (is.null(x$`aria-label`)) { + cli::cli_inform( + c( + x = "Icon {.str {x$icon}} lacks an {.var aria-label}.", + i = "Specify {.var aria-label} to make the icon accessible to screen readers.", + i = "Learn more in {.vignette accessibility}." + ), + .frequency = "regularly", + .frequency_id = "icon-aria-label" + ) + } } paste0( diff --git a/tests/testthat/_snaps/navbar-menu.md b/tests/testthat/_snaps/navbar-menu.md index 9a01cbfc5..486696581 100644 --- a/tests/testthat/_snaps/navbar-menu.md +++ b/tests/testthat/_snaps/navbar-menu.md @@ -45,6 +45,16 @@ Output