Skip to content

Commit 9b8088d

Browse files
authored
docs(tooltip,popover): Document trigger accessibility considerations (#825)
1 parent bee0b80 commit 9b8088d

File tree

6 files changed

+150
-20
lines changed

6 files changed

+150
-20
lines changed

R/popover.R

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@
2626
#'
2727
#' @section Theming/Styling:
2828
#'
29-
#' Like other bslib components, popovers can be themed by supplying [relevant
30-
#' theming
31-
#' variables](https://rstudio.github.io/bslib/articles/bs5-variables/index.html#popover-bg)
32-
#' to [bs_theme()], which effects styling of every popover on the page. To
33-
#' style a _specific_ popover differently from other popovers, utilize the
34-
#' `customClass` option:
29+
#' ```{r child="man/fragments/tooltip-popover_theming.Rmd", el = "popover"}
30+
#' ```
3531
#'
3632
#' ```
3733
#' popover(
@@ -46,6 +42,27 @@
4642
#' bs_theme() |> bs_add_rules(".my-pop { max-width: none; }")
4743
#' ```
4844
#'
45+
#' @section Accessibility of Popover Triggers:
46+
#'
47+
#' ```{r child="man/fragments/tooltip-popover_a11y-trigger.Rmd", el = "popover"}
48+
#' ```
49+
#'
50+
#' ```r
51+
#' popover(
52+
#' bsicons::bs_icon("gear", title = "Settings"),
53+
#' title = "Settings",
54+
#' sliderInput("n", "Number of points", 1, 100, 50)
55+
#' )
56+
#' ```
57+
#'
58+
#' ```r
59+
#' popover(
60+
#' fontawesome::fa("gear", a11y = "sem", title = "Settings"),
61+
#' title = "Settings",
62+
#' sliderInput("n", "Number of points", 1, 100, 50)
63+
#' )
64+
#' ```
65+
#'
4966
#' @describeIn popover Add a popover to a UI element
5067
#' @references <https://getbootstrap.com/docs/5.3/components/popovers/>
5168
#' @export

R/tooltip.R

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@
1717
#'
1818
#' @section Theming/Styling:
1919
#'
20-
#' Like other bslib components, tooltips can be themed by supplying [relevant
21-
#' theming
22-
#' variables](https://rstudio.github.io/bslib/articles/bs5-variables/index.html#tooltip-bg)
23-
#' to [bs_theme()], which effects styling of every popover on the page. To
24-
#' style a _specific_ popover differently from other popovers, utilize the
25-
#' `customClass` option:
20+
#' ```{r child="man/fragments/tooltip-popover_theming.Rmd", el="tooltip"}
21+
#' ```
2622
#'
2723
#' ```
2824
#' tooltip(
@@ -37,6 +33,25 @@
3733
#' bs_theme() |> bs_add_rules(".my-tip { max-width: none; }")
3834
#' ```
3935
#'
36+
#' @section Accessibility of Tooltip Triggers:
37+
#'
38+
#' ```{r child="man/fragments/tooltip-popover_a11y-trigger.Rmd", el = "tooltip"}
39+
#' ```
40+
#'
41+
#' ```r
42+
#' tooltip(
43+
#' bsicons::bs_icon("info-circle", title = "About tooltips"),
44+
#' "Text shown in the tooltip."
45+
#' )
46+
#' ```
47+
#'
48+
#' ```r
49+
#' tooltip(
50+
#' fontawesome::fa("info-circle", title = "About tooltips"),
51+
#' "Text shown in the tooltip."
52+
#' )
53+
#' ```
54+
#'
4055
#' @describeIn tooltip Add a tooltip to a UI element
4156
#' @references <https://getbootstrap.com/docs/5.3/components/tooltips/>
4257
#' @export
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
```{r include = FALSE}
2+
el <- function() knitr::opts_current$get("el")
3+
```
4+
5+
Because the user needs to interact with the `trigger` element to see the `r el()`, it's best practice to use an element that is typically accessible via keyboard interactions, like a button or a link.
6+
If you use a non-interactive element, like a `<span>` or text, bslib will automatically add the `tabindex="0"` attribute to the trigger element to make sure that users can reach the element with the keyboard.
7+
This means that in most cases you can use any element you want as the trigger.
8+
9+
One place where it's important to consider the accessibility of the trigger is when using an icon without any accompanying text.
10+
In these cases, many R packages that provide icons will create an icon element with the assumption that the icon is decorative, which will make it inaccessible to users of assistive technologies.
11+
12+
When using an icon as the primary trigger, ensure that the icon does not have `aria-hidden="true"` or `role="presentation"` attributes.
13+
Icon packages typically provide a way to specify a title for the icon, as well as a way to specify that the icon is not decorative.
14+
The title should be a short description of the purpose of the trigger, rather than a description of the icon itself.
15+
16+
* If you're using [bsicons::bs_icon()], provide a `title`.
17+
* If you're using [fontawesome::fa()], set `a11y = "sem"` and provide a `title`.
18+
19+
For example:
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
```{r include = FALSE}
2+
el <- function() knitr::opts_current$get("el")
3+
```
4+
5+
Like other bslib components, `r el()`s can be themed by supplying
6+
[relevant theming variables](https://rstudio.github.io/bslib/articles/bs5-variables/index.html#`r el()`-bg)
7+
to [bs_theme()],
8+
which effects styling of every `r el()` on the page.
9+
To style a _specific_ `r el()` differently from other `r el()`, utilize the `customClass` option:

man/popover.Rd

Lines changed: 40 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tooltip.Rd

Lines changed: 38 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)