Skip to content

Commit 92f656d

Browse files
better docs
1 parent 2941475 commit 92f656d

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

docs/rules/a11y-no-title-attribute.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,42 @@
22

33
<!-- end auto-generated rule header -->
44

5+
The title attribute is strongly discouraged. The only exception is on an `<iframe>` element. It is hardly useful and cannot be accessed by multiple groups of users including keyboard-only users and mobile users.
6+
7+
The `title` attribute is commonly set on links, matching the link text. This is redundant and unnecessary so it can be simply be removed.
8+
9+
If you are considering the `title` attribute to provide supplementary description, consider whether the text in question can be persisted in the design. Alternatively, if it's important to display supplementary text that is hidden by default, consider using an accessible tooltip implementation that uses the aria-labelledby or aria-describedby semantics. Even so, proceed with caution: tooltips should only be used on interactive elements like links or buttons. See [Tooltip alternatives](https://primer.style/design/guides/accessibility/tooltip-alternatives) for more accessible alternatives.
10+
11+
### Should I use the title attribute to provide an accessible name for an <svg>?
12+
13+
Use a <title> element instead of the title attribute, or an aria-label.
14+
515
## Rule Details
616

17+
👎 Examples of **incorrect** code for this rule:
18+
19+
```jsx
20+
<a src="https://www.github.com" title="A home for all developers">
21+
GitHub
22+
</a>
23+
```
24+
25+
```jsx
26+
<a href="/" title="github.com">
27+
GitHub
28+
</a>
29+
```
30+
31+
```jsx
32+
<span src="https://www.github.com" title="supercalifragilisticexpialidocious">
33+
supercali...
34+
</span>
35+
```
36+
37+
👍 Examples of **correct** code for this rule:
38+
39+
```jsx
40+
<iframe src="https://www.github.com" title="Github"></iframe>
41+
```
42+
743
## Version

lib/rules/a11y-no-title-attribute.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ module.exports = {
1919
if (titleProp) {
2020
context.report({
2121
node,
22-
message:
23-
"The title attribute is not accessible and should never be used unless for an `<iframe>`. If you cannot convey the information in another way, replace the title attribute with an accessible tooltip like, Primer React's Tooltip.",
22+
message: 'The title attribute is not accessible and should never be used unless for an `<iframe>`.',
2423
})
2524
}
2625
}

tests/a11y-no-title-attribute.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ const ruleTester = new RuleTester({
1111
},
1212
})
1313

14-
const errorMessage =
15-
"The title attribute is not accessible and should never be used unless for an `<iframe>`. If you cannot convey the information in another way, replace the title attribute with an accessible tooltip like, Primer React's Tooltip."
14+
const errorMessage = 'The title attribute is not accessible and should never be used unless for an `<iframe>`.'
1615

1716
ruleTester.run('a11y-no-title-attribute', rule, {
1817
valid: [

0 commit comments

Comments
 (0)