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: docs/rules/accessibility/avoid-generic-link-text-counter.md
+19-11Lines changed: 19 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,23 +11,31 @@ Additionally, generic link text can also problematic for heavy zoom users where
11
11
Ensure that your link text is descriptive and the purpose of the link is clear even when read out of context of surrounding text.
12
12
Learn more about how to write descriptive link text at [Access Guide: Write descriptive link text](https://www.accessguide.io/guide/descriptive-link-text)
13
13
14
-
### Use of ARIA attributes
14
+
If you _must_ use ARIA to replace the visible link text, include the visible text at the beginning.
15
15
16
-
It is acceptable to use `aria-label` or `aria-labelledby` to provide a more descriptive text in some cases. As note above, this is not the preferred solution and one should strive to make the visible text to be as descriptive as the design allows.
16
+
For example, on a pricing plans page, the following are good:
17
+
- Visible text: `Learn more`
18
+
- Accessible label: `Learn more about GitHub pricing plans`
17
19
18
-
If you _must_ use this technique, you need to ensure that the accessible name completely contains the visible text. Otherwise, this is a failure of [SC 2.5.3: Label in Name](https://www.w3.org/WAI/WCAG21/Understanding/label-in-name.html).
This linter will raise a flag when it is able to detect that a generic link has an accessible name that doesn't contain the visible text. Due to the restrictions of static code analysis, this may not catch all violations so it is important to supplement this check with other techniques like browser tests. For instance, ERB lint will not be able to evaluate the accessible name set by `aria-labelledby` or when a variable is set to `aria-label` since this requires runtime evaluation.
30
+
Including the visible text in the ARIA label satisfies [SC 2.5.3: Label in Name](https://www.w3.org/WAI/WCAG21/Understanding/label-in-name.html).
31
+
32
+
#### False negatives
33
+
34
+
Caution: because of the restrictions of static code analysis, we may not catch all violations.
0 commit comments