Skip to content

Commit 46c10d0

Browse files
jakubkolesar7nikdummdidumm
authored
fix: missing title warning for buttons and anchor tags (#16872)
* fix(a11y): title warning for buttons and anchor tags * chore(changeset): added changeset * Update playgrounds/sandbox/index.html * Update .changeset/shiny-chicken-occur.md --------- Co-authored-by: 7nik <[email protected]> Co-authored-by: Simon H <[email protected]>
1 parent 25cbdc8 commit 46c10d0

File tree

8 files changed

+19
-8
lines changed

8 files changed

+19
-8
lines changed

.changeset/shiny-chicken-occur.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: silence label warning for buttons and anchor tags with title attributes

documentation/docs/98-reference/.generated/compile-warnings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Coding for the keyboard is important for users with physical disabilities who ca
8181
### a11y_consider_explicit_label
8282

8383
```
84-
Buttons and links should either contain text or have an `aria-label` or `aria-labelledby` attribute
84+
Buttons and links should either contain text or have an `aria-label`, `aria-labelledby` or `title` attribute
8585
```
8686

8787
### a11y_distracting_elements

packages/svelte/messages/compile-warnings/a11y.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Coding for the keyboard is important for users with physical disabilities who ca
6666

6767
## a11y_consider_explicit_label
6868

69-
> Buttons and links should either contain text or have an `aria-label` or `aria-labelledby` attribute
69+
> Buttons and links should either contain text or have an `aria-label`, `aria-labelledby` or `title` attribute
7070
7171
## a11y_distracting_elements
7272

packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,10 @@ export function check_element(node, context) {
382382
}
383383

384384
// element-specific checks
385-
const is_labelled = attribute_map.has('aria-label') || attribute_map.has('aria-labelledby');
385+
const is_labelled =
386+
attribute_map.has('aria-label') ||
387+
attribute_map.has('aria-labelledby') ||
388+
attribute_map.has('title');
386389

387390
switch (node.name) {
388391
case 'a':

packages/svelte/src/compiler/warnings.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ export function a11y_click_events_have_key_events(node) {
174174
}
175175

176176
/**
177-
* Buttons and links should either contain text or have an `aria-label` or `aria-labelledby` attribute
177+
* Buttons and links should either contain text or have an `aria-label`, `aria-labelledby` or `title` attribute
178178
* @param {null | NodeLike} node
179179
*/
180180
export function a11y_consider_explicit_label(node) {
181-
w(node, 'a11y_consider_explicit_label', `Buttons and links should either contain text or have an \`aria-label\` or \`aria-labelledby\` attribute\nhttps://svelte.dev/e/a11y_consider_explicit_label`);
181+
w(node, 'a11y_consider_explicit_label', `Buttons and links should either contain text or have an \`aria-label\`, \`aria-labelledby\` or \`title\` attribute\nhttps://svelte.dev/e/a11y_consider_explicit_label`);
182182
}
183183

184184
/**

packages/svelte/tests/validator/samples/a11y-anchor-has-content/warnings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"code": "a11y_consider_explicit_label",
4-
"message": "Buttons and links should either contain text or have an `aria-label` or `aria-labelledby` attribute",
4+
"message": "Buttons and links should either contain text or have an `aria-label`, `aria-labelledby` or `title` attribute",
55
"start": {
66
"line": 1,
77
"column": 0

packages/svelte/tests/validator/samples/a11y-consider-explicit-label/input.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<button aria-label="Valid empty button"></button>
55
<a href="/#" aria-label="Valid empty link"></a>
66

7+
<button title="Valid empty button"></button>
8+
<a href="/#" title="Valid empty link"></a>
9+
710
<button aria-hidden='true'></button>
811
<button inert></button>
912
<a href="/#" aria-hidden='true'><b></b></a>

packages/svelte/tests/validator/samples/a11y-consider-explicit-label/warnings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"code": "a11y_consider_explicit_label",
4-
"message": "Buttons and links should either contain text or have an `aria-label` or `aria-labelledby` attribute",
4+
"message": "Buttons and links should either contain text or have an `aria-label`, `aria-labelledby` or `title` attribute",
55
"start": {
66
"line": 1,
77
"column": 0
@@ -13,7 +13,7 @@
1313
},
1414
{
1515
"code": "a11y_consider_explicit_label",
16-
"message": "Buttons and links should either contain text or have an `aria-label` or `aria-labelledby` attribute",
16+
"message": "Buttons and links should either contain text or have an `aria-label`, `aria-labelledby` or `title` attribute",
1717
"start": {
1818
"line": 2,
1919
"column": 0

0 commit comments

Comments
 (0)