You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/accessibility/descriptive-buttons.mdx
+50-51Lines changed: 50 additions & 51 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,15 +8,15 @@ In order for a button’s purpose to be clear to all users, it must have a meani
8
8
9
9
### What is a meaningful name?
10
10
11
-
A meaningful name describes the button’s purpose: The action that occurs when the button is activated (e.g. removing a list item), and the action’s associated context (e.g. the specific item to be removed). To avoid unnecessary verbosity, button names should be as succinct as possible while still being descriptive and unique. Refer to [Identifying comments](#identifying-comments) below for an example of a succinct, unique name.
11
+
A meaningful name describes the button’s purpose: the action that occurs when the button is activated (for example: removing a list item), and the action’s associated context (for example: the specific item to be removed). To avoid unnecessary verbosity, button names should be as succinct as possible while still being descriptive and unique.
12
12
13
-
To explore how meaningful names can be set in code, refer to the [Examples](#examples) below.
13
+
Refer to [Identifying GitHub comments](#identifying-github-comments) below for an example of a succinct, unique name. To explore how meaningful names can be set in code, refer to the [examples](#examples) below.
14
14
15
15
### Why is a meaningful name necessary?
16
16
17
17
Clear and consistent labels set user expectations for button actions, giving users confidence that activating a button will have the outcome they expect.
18
18
19
-
Screen readers (e.g. VoiceOver) provide overlays to enable users to jump to specific types of elements, including buttons. Elements are listed by their names. When buttons don’t have meaningful names, it’s not possible to determine which action will be performed when selecting them from the list.
19
+
Screen readers (for example: VoiceOver) provide overlays to enable users to jump to specific types of elements, including buttons. Elements are listed by their names. When buttons don’t have meaningful names, it’s not possible to determine which action will be performed when selecting them from the list.
20
20
21
21
## How to test names
22
22
@@ -30,37 +30,53 @@ When reviewing buttons on a page, ensure the following are true:
30
30
31
31
### For designers
32
32
33
-
- When including an icon-only (i.e. unlabeled) button in a design, recommend an accessible name.
33
+
- When including an unlabeled, icon-only button in a design, recommend an accessible name.
34
34
- When including multiple buttons that peform the same function in a design, use the same label for each.
35
35
36
36
### For engineers
37
37
38
-
- When a button doesn’t have a visible label (e.g. an [IconButton](https://primer.style/view-components/components/iconbutton)), provide an accessible name. Refer to [ARIA 14: Using `aria-label` to provide an invisible label where a visible label cannot be used](https://www.w3.org/WAI/WCAG22/Techniques/aria/ARIA14).
39
-
- Because `aria-label` doesn’t _supplement_ visible labels but rather _supplants_ them, when a button has a visible label, include that label in its accessible name. A best practice is to have the text of the label at the start of the name.
38
+
- When a button doesn’t have a visible label (for example: an [IconButton](https://primer.style/view-components/components/iconbutton)), provide an accessible name. Refer to [ARIA 14: Using `aria-label` to provide an invisible label where a visible label cannot be used](https://www.w3.org/WAI/WCAG22/Techniques/aria/ARIA14).
39
+
- Because `aria-label` doesn’t _supplement_ visible labels but rather _supplants_ them, when a button has a visible label, include that label in its accessible name. A good practice is to have the text of the label at the start of the name.
40
40
- Don’t use `aria-label` when its content would be identical to a button’s visible label.
41
41
- Don’t reuse the same (visible) label or (invisible) name for buttons which perform different actions.
42
42
43
43
## Examples
44
44
45
-
### 👎 Bad: Redundant `aria-label` attribute
46
-
47
-
The button below has a redundant and unnecessary `aria-label` attribute:
### 👎 Bad: Meaningless name, reused for unrelated buttons
62
-
63
-
Although each button in the example below performs a different action, they all have the same name: ❌ (“cross mark”). This name does not describe the action that occurs when a given button is activated, nor does it describe the action’s context.
45
+
<DoDontContainer>
46
+
<Do>
47
+
<CodeclassName="language-html">
48
+
{`<button type="button">OK</button>`}
49
+
</Code>
50
+
<Caption>The button does not have a redundant `aria-label` attribute.</Caption>
51
+
</Do>
52
+
<Dont>
53
+
<CodeclassName="language-html">
54
+
{`<button type="button">OK</button>`}
55
+
</Code>
56
+
<Caption>The button has a redundant and unnecessary `aria-label` attribute.</Caption>
Each button in the example below has a unique name which describes its action (“Remove”) and its action’s context (e.g. “'Apples'”).
95
+
Although each button in the example below performs a different action, they all have the same name: ❌ (“cross mark”). This name does not describe the action that occurs when a given button is activated, nor does it describe the action’s context.
98
96
99
97
```HTML
100
98
<script>
@@ -104,12 +102,13 @@ Each button in the example below has a unique name which describes its action (
@@ -155,7 +154,7 @@ The name may be hidden and only exposed by assistive technology, whereas a label
155
154
156
155
#### Identifying GitHub comments
157
156
158
-
When a button is associated with a specific comment, a comment indentifier should be included within the button’s name. [`reaction_target_identifier`](https://github.com/github/github/blob/016b875e0542c0781a3c6f5ed27c58c472cc6717/app/components/reactions/reactions_component.rb#L47-L51) (only accessible to GitHub staff) uses [`aria-label-date`](https://github.com/github/github/blob/9bea7b7d0d120df6b9b864fda39fe374479acc0d/app/components/application_component.rb#L68-L78) (only accessible to GitHub staff) to generates a concise, unique comment identifier.
157
+
When a button is associated with a specific comment, a comment indentifier should be included within the button’s name. [`reaction_target_identifier`](https://github.com/github/github/blob/016b875e0542c0781a3c6f5ed27c58c472cc6717/app/components/reactions/reactions_component.rb#L47-L51) (only accessible to GitHub staff) uses [`aria-label-date`](https://github.com/github/github/blob/9bea7b7d0d120df6b9b864fda39fe374479acc0d/app/components/application_component.rb#L68-L78) (only accessible to GitHub staff) to generate a concise, unique comment identifier.
159
158
160
159
For example, `reaction_target_identifier` could be used in a reply-to-comment button’s name. In all cases, `reaction_target_identifier` adds the comment’s author and timestamp; conditionally, as needed, `reaction_target_identifier` adds progressively-verbose date information:
<Boxas="p">Events like toasts and status messages are visually communicated to GitHub users. Making sure those announcements are read via assistive technology allows users with low or no vision to get that status information.</Box>
36
36
</div>
37
37
<div>
38
-
<Linkhref="/design/accessibility/button-purpose"fontWeight="bold">Describing a button’s purpose</Link>
0 commit comments