Skip to content

Commit c76d8da

Browse files
authored
Create accessibility vignette (#2518)
Including advice fixing the colour contrast issue caused by using the danger colour on a light navbar background (and apply that advice to pkgdown itself) Fixes #2344. Fixes #2283.
1 parent bb2f8e3 commit c76d8da

File tree

5 files changed

+67
-1
lines changed

5 files changed

+67
-1
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# pkgdown (development version)
22

3+
* New `vignette("accessibility")` describes what manual tasks you need to perform to make your site as accessible as possible (#2344).
34
* `build_reference()` now automatically translates `--`, `---`, ``` `` ```, and `''` to their unicode equivalents (#2530).
45
* Tweaked navbar display on mobile so that long titles in drop downs (e.g. article titles) are now wrapped, and the search input spans the full width (#2512).
56
* `build_reference()` now supports `\Sexpr[results=verbatim]` (@bastistician, #2510).

pkgdown/_pkgdown.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ template:
2121
primary: "#0054AD"
2222
border-radius: 0.5rem
2323
btn-border-radius: 0.25rem
24+
danger: "#A6081A"
2425
includes:
2526
in_header:
2627
<script defer data-domain="pkgdown.r-lib.org,all.tidyverse.org" src="https://plausible.io/js/plausible.js"></script>
@@ -33,6 +34,7 @@ articles:
3334
navbar: ~
3435
contents:
3536
- customise
37+
- accessibility
3638
- linking
3739
- search
3840
- metadata

vignettes/accessibility.Rmd

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: "Accessibility"
3+
output: rmarkdown::html_vignette
4+
vignette: >
5+
%\VignetteIndexEntry{accessibility}
6+
%\VignetteEngine{knitr::rmarkdown}
7+
%\VignetteEncoding{UTF-8}
8+
---
9+
10+
```{r, include = FALSE}
11+
knitr::opts_chunk$set(
12+
collapse = TRUE,
13+
comment = "#>"
14+
)
15+
```
16+
17+
pkgdown automates as many accessibility details as possible, so that your package website is readable by as many people as possible. This vignette describes the additional details that can't be automated away and you need to be aware of.
18+
19+
```{r setup}
20+
library(pkgdown)
21+
```
22+
23+
## Theming
24+
25+
* If you adjust any colours from the default theme (including the syntax highlighting theme), you should double check that the contrast between the background and foreground doesn't make any text difficult to read. A good place to start is running a representative page of your site through <https://wave.webaim.org>.
26+
27+
* The default colour of the development version label makes a slightly too low contrast against the pale grey background of the navbar. This colour comes from the bootstrap "danger" colour, so you can fix it by overriding that variable in your `_pkgdown.yml`:
28+
29+
```yaml
30+
template:
31+
bootstrap: 5
32+
bslib:
33+
danger: "#A6081A"
34+
```
35+
36+
* If you use custom navbar entries that only display an icon, make sure to also use the `aria-label` field to provide an accessible label that describes the icon.
37+
38+
```yaml
39+
cran:
40+
icon: fab fa-r-project
41+
href: https://cloud.r-project.org/package=pkgdown
42+
aria-label: View on CRAN
43+
```
44+
45+
## Images
46+
47+
To make your site fully accessible, the place where you are likely to need to do the most work is adding alternative text to any images that you create. Unfortunately, there's currently no way to do this for plots you generate in examples, but you can and should add alternative text to plots in vignettes using the `fig.alt` chunk option:
48+
49+
````{verbatim}
50+
```{r}
51+
#| fig.alt: >
52+
#| Histogram of time between eruptions for Old Faithful.
53+
#| It is a bimodal distribution with peaks at 50-55 and
54+
#| 80-90 minutes.
55+
hist(faithful$waiting)
56+
```
57+
````

vignettes/customise.Rmd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Upgrading to Bootstrap 5 has a low chance of breaking your site unless you were
4343
There are two ways to change the visual style of your site from `_pkgdown.yml`: using a pre-packaged bootswatch theme or customising theme variables with [bslib](https://rstudio.github.io/bslib/).
4444
The following sections show you how.
4545

46+
Please note that pkgdown's default theme has been carefully optimised to be accessible, so if you make changes, make sure that to also read `vignette("accessibility")` to learn about potential accessibility pitfalls.
47+
4648
### Bootswatch themes
4749

4850
The easiest way to change the entire appearance of your website is to use a [Bootswatch theme](https://bootswatch.com):
@@ -93,7 +95,7 @@ template:
9395
You can customise other components by setting more specific bslib variables, taking advantage of inheritance where possible.
9496
For example, `table-border-color` defaults to `border-color` which defaults to `gray-300`.
9597
If you want to change the colour of all borders, you can set `border-color`; if you just want to change the colour of table borders, you can set `table-border-color`.
96-
You can find a full list of variables in `vignette("bs5-variables", package = "bslib")`.
98+
You can find a full list of variables in the [bslib docs](https://rstudio.github.io/bslib/articles/bs5-variables/index.html).
9799

98100
Theming with bslib is powered by `bslib::bs_theme()` and the `bslib` field is a direct translation of the arguments to that function.
99101
As a result, you can fully specify a bslib theme using the `template.bslib` field, making it easy to share YAML with the `output.html_document.theme` field [of an R Markdown document](https://rstudio.github.io/bslib/articles/theming/index.html).

vignettes/pkgdown.Rmd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ Current available translations are:
7575
- `tr`: Turkish
7676
- `zh_CN`: Chinese (simplified)
7777

78+
## Accessibility
79+
80+
pkgdown's defaults work to ensure that your site is accessible to as many people as possible. But there are some accessibilty issues that only a human can solve, so make sure to also read `vignette("accessibility")` to learn about them.
81+
7882
## Home page
7983

8084
The contents of the home page are automatically generated from `index.md` or `README.md`.

0 commit comments

Comments
 (0)