Skip to content

Commit 586bfd8

Browse files
authored
6482 a11y documentation (#6680)
1 parent 29ec917 commit 586bfd8

14 files changed

+106
-35
lines changed

docs/ui-principles.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ code, which will make Warehouse easier to maintain in the long term.
2121
---------------------------------------
2222

2323
Ensuring Warehouse follows usability and accessibility best practices will make
24-
the site easier to use for everybody. At a minimum:
24+
the site easier to use for everybody.
25+
26+
Warehouse follows the `WCAG 2.0 AA standard <https://www.w3.org/TR/WCAG20/>`_.
27+
When working on the UI:
2528

2629
- Ensure contrast is high, particularly on text. This can be checked:
2730
- On Chrome by installing `Accessibility Developer Tools

warehouse/static/js/warehouse/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,14 @@ docReady(() => {
9595

9696
new Clipboard(".copy-tooltip").on("success", setCopiedTooltip);
9797

98-
// Get all elements with class "tooltipped" and bind to focousout and
99-
// mouseout events. Change the "aria-label" to "original-label" attribute
100-
// value.
10198
let setOriginalLabel = (element) => {
10299
element.setAttribute("data-tooltip-label", "Copy to clipboard");
103100
element.removeAttribute("role");
104101
element.blur();
105102
};
103+
106104
let tooltippedElems = Array.from(document.querySelectorAll(".copy-tooltip"));
105+
107106
tooltippedElems.forEach((element) => {
108107
element.addEventListener("focusout",
109108
setOriginalLabel.bind(undefined, element),

warehouse/static/sass/blocks/_applied-filters.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
<div class="applied-filters">
2020
// Filters go here (see filter-badge for details)
2121
<span class="applied-filters__add-button">
22-
// Button to toggle sidebar goes here
22+
<button type="button" class="-js-add-filter button button--small">
23+
Add filter
24+
</button>
2325
</div>
2426
</div>
2527
*/

warehouse/static/sass/blocks/_callout-block.scss

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,23 @@
1515
/*
1616
A block for highlighting important information:
1717
18+
// Basic component
1819
<div class="callput-block">
1920
<h3 class="callout-block__heading">Optional Heading</h3>
2021
// Any important message here.
2122
</div>
2223
23-
By default this component is styled with the primary color.
24+
// Dismissable
25+
- Add data attributes to connect to JS script
26+
- Add ARIA labels to close button
27+
28+
<div class="callout-block" data-controller="dismissable" data-dismissable-identifier="releases">
29+
<button type="button" title="Dismiss" data-action="click->dismissable#dismiss" class="callout-block__dismiss" aria-label="Close">
30+
<i class="fa fa-times" aria-hidden="true"></i>
31+
</button>
32+
<h3 class="callout-block__heading">Optional Heading</h3>
33+
// Any important message here.
34+
</div>
2435
2536
Modifiers:
2637
- danger: Makes border red

warehouse/static/sass/blocks/_checkbox-tree.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
<div class="checkbox-tree">
1919
<ul>
2020
<li>
21-
<input class="checkbox-tree__checkbox">
22-
<label class="checkbox-tree__label"></label>
21+
<input class="checkbox-tree__checkbox" id="mycheckbox">
22+
<label class="checkbox-tree__label" for="mycheckbox"></label>
2323
<!-- more tree here -->
2424
</li>
2525
</ul>

warehouse/static/sass/blocks/_copy-tooltip.scss

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1-
// The following is derived from https://github.com/primer/tooltips
1+
// The following is modified from https://github.com/primer/tooltips
22
// The MIT License (MIT)
3-
// Copyright (c) 2016 GitHub Inc.
3+
// Copyright (c) 2016 GitHub Inc
4+
5+
/*
6+
A tooltip that is attached to a button, incidacting that clicking the button will cause something to be copied:
7+
8+
<button type="button" class="copy-tooltip copy-tooltip-s" data-clipboard-target="#target" data-tooltip-label="Copy to clipboard">
9+
// Text or icon
10+
</button>
11+
12+
Data:
13+
- data-clipboard-target: the content that will be copied to the clipboard
14+
- data-tooltip-label: the label of the tooltip (before the button is clicked)
15+
16+
Modifiers:
17+
- copy-tooltip-s: Tooltip appears below the button (south)
18+
- copy-tooltip-n: Tooltip appears above the button (north)
19+
- copy-tooltip-e: Tooltip appears to the right of the button (east)
20+
- copy-tooltip-w: Tooltip appears to the left of the button (west)
21+
*/
22+
423

524
$tooltip-max-width: 250px !default;
625
$tooltip-background-color: transparentize($black, 0.3) !default;

warehouse/static/sass/blocks/_dropdown.scss

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,28 @@
1414

1515
/*
1616
A dropdown - containing a trigger and dropdown content, which may include
17-
links. Styled to match the banner.
18-
19-
<div class="dropdown">
20-
<button class="dropdown__trigger">
21-
<div class="dropdown__content">
22-
<a class="dropdown__link">Link Here</a>
23-
</div>
24-
</div>
17+
links.
18+
19+
<nav class="dropdown" aria-label="Dropdown label">
20+
<button type="button" class="dropdown__trigger" aria-haspopup="true" aria-expanded="false" aria-label="button label">
21+
// Button text or icon
22+
</button>
23+
<ul class="dropdown__content" aria-hidden="true" aria-label="Main menu">
24+
<li>
25+
<a class="dropdown__link" href="url">
26+
// Link text
27+
</a>
28+
</li>
29+
</ul>
30+
</nav>
31+
32+
Accessbility:
33+
- .dropdown - aria-label: label the entire dropdown. E.g. "Main navigation"
34+
- .dropdown__trigger - aria-label: label the button. E.g. "Show menu"
35+
- .dropdown__trigger - aria-haspopup: indicates that the button has a popup element attached
36+
- .dropdown__trigger - aria-expended: indicates whether or not the popup is expanded
37+
- .dropdown__content - aria-hidden: indicates whether or not list is hidden
38+
- .dropdown__content - aria-label: labels the content. E.g. "Main menu"
2539
2640
Modifiers:
2741
- on-menu: Styles the dropdown to match the site header

warehouse/static/sass/blocks/_filter-badge.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
<span class="filter-badge__description">
2424
// filter description here
2525
</span>
26-
<a class="filter-badge__remove-button">
26+
<button type="button" class="filter-badge__remove-button">
2727
// close icon here
28-
</a>
28+
</button>
2929
</div>
3030
*/
3131

warehouse/static/sass/blocks/_filter-panel.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
- shown over other content after being launched by a button
2121
2222
<div class="filter-panel">
23-
<a class="filter-panel__close">
24-
// close button
25-
</a>
23+
<button type="button" class="filter-panel__close -js-close-panel" aria-label="Close panel">
24+
<i class="fa fa-times" aria-hidden="true"></i>
25+
</button>
2626
// Panel content here
2727
</div>
2828
*/

warehouse/static/sass/blocks/_footer.scss

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@
2020
// footer icon image goes here
2121
</div>
2222
<div class="footer__menus"> // menu wrapper
23-
<ul class="footer__menu"> // 3 of these!
24-
<li><h3>Menu Title</h3></li>
25-
<li><a>Menu Link</a></li>
26-
</ul>
23+
<div class="footer__menu">
24+
// H2: Menu title
25+
<nav aria-label="menu label">
26+
<ul>
27+
<li><a>Menu Link</a></li>
28+
</ul>
29+
</nav>
30+
</div>
2731
</div>
2832
2933
<hr class="footer__divider">

warehouse/static/sass/blocks/_form-errors.scss

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,18 @@
1515
/*
1616
A list of form errors:
1717
18-
<ul class="form-errors">
19-
<li>This is a form error</li>
20-
<li>This is another error</li>
21-
</ul>
18+
<input aria-describedby="my-field-errors">
19+
20+
<div id="my-field-errors">
21+
<ul class="form-errors" role="alert">
22+
<li>This is a form error</li>
23+
<li>This is another error</li>
24+
</ul>
25+
</div>
26+
27+
Accessibility:
28+
- Wrap the error in a div associated with the field via 'aria-describedby'
29+
- Add 'role=alert'to notify screen readers
2230
2331
Modifiers:
2432
- full-width: makes error take entire available horizontal space

warehouse/static/sass/blocks/_horizontal-menu.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@
1515
/*
1616
A menu where the links stack horizontally.
1717
18-
<nav class="horizontal-menu">
18+
<nav class="horizontal-menu" aria-label="my label">
1919
<ul>
2020
<li class="horizontal-menu__item">
2121
<a class="horizontal-menu__link">A horizontal link</a>
2222
</li>
2323
</ul>
2424
</nav>
2525
26+
Accessibility:
27+
- Describe the menu with aria-label
28+
2629
Modifiers:
2730
- tall: Adds extra padding to the menu items
2831
- light: Makes the links white. Use on a dark background.

warehouse/static/sass/blocks/_search-form.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
A horizontal search form, with an input on the left and a button on the right.
1717
1818
<form class="search-form" role="search">
19-
<input class="search-form__search">
19+
<label for="my-search" class="sr-only">Search PyPI</label>
20+
<input class="search-form__search" id="my-search">
2021
<button type="submit" class="search-form__button">
2122
<i class="fa fa-search" aria-hidden="true"></i>
2223
<span class="sr-only">Search</span>

warehouse/static/sass/blocks/_table.scss

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
/*
1616
Tables for displaying data about a project, release or file.
1717
18-
<table>
18+
<table class="table">
19+
<caption class="sr-only">Caption for table</caption>
1920
<thead>
2021
<tr>
21-
<th>Heading</th>
22+
<th scope="col">Heading</th>
2223
</tr>
2324
</thead>
2425
<tbody>
2526
<tr>
27+
<th scope="row">Row title</th>
2628
<td>Data</td>
2729
</tr>
2830
</tbody>
@@ -33,6 +35,11 @@
3335
e.g. the downloads table will contain 'table__upload-date' to represent the
3436
upload column on that table.
3537
38+
Accessibility:
39+
- label the table with caption (for screen reader users)
40+
- Add 'scope="col"' to column headings
41+
- Use a th and add 'scope="row"' for row headings
42+
3643
Modifiers:
3744
- downloads: specific styles for downloads table on project detail page
3845
- releases: specific styles for releases table on manage project page

0 commit comments

Comments
 (0)