Skip to content

Commit fb80463

Browse files
committed
Add note on accessibility to rating stars example; remove redundant attribute
Only one accessible name is needed on the image. Use title to also provide a tooltip on hover.
1 parent 066cad6 commit fb80463

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

vignettes/cookbook/cookbook.Rmd

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,13 @@ reactable(data, columns = list(
334334

335335
This example uses Font Awesome icons
336336
([via Shiny](https://shiny.rstudio.com/reference/shiny/latest/icon.html))
337-
to render rating stars in a table:
337+
to render rating stars in a table.
338+
339+
To make the rating star icons accessible, wrap them in a container with the
340+
[ARIA `img` role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/Role_Img)
341+
and add alternative text using an `aria-label` or `title` attribute. This
342+
ensures that the multiple icons are identified as a single image by assistive
343+
technologies.
338344

339345
```{r}
340346
library(htmltools)
@@ -350,8 +356,8 @@ rating_stars <- function(rating, max_rating = 5) {
350356
stars <- lapply(seq_len(max_rating), function(i) {
351357
if (i <= rounded_rating) star_icon() else star_icon(empty = TRUE)
352358
})
353-
label <- sprintf("%s out of %s", rating, max_rating)
354-
div(title = label, "aria-label" = label, role = "img", stars)
359+
label <- sprintf("%s out of %s stars", rating, max_rating)
360+
div(title = label, role = "img", stars)
355361
}
356362
357363
ratings <- data.frame(

0 commit comments

Comments
 (0)