Skip to content

Commit fb51dd8

Browse files
authored
add a11y-media-has-caption check (#5075)
1 parent 308f3c2 commit fb51dd8

File tree

5 files changed

+60
-5
lines changed

5 files changed

+60
-5
lines changed

src/compiler/compile/nodes/Element.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,25 @@ export default class Element extends Node {
528528
}
529529
}
530530

531+
if (this.is_media_node()) {
532+
if (attribute_map.has('muted')) {
533+
return;
534+
}
535+
536+
let has_caption;
537+
const track = this.children.find((i: Element) => i.name === 'track');
538+
if (track) {
539+
has_caption = track.attributes.find(a => a.name === 'kind' && a.get_static_value() === 'captions');
540+
}
541+
542+
if (!has_caption) {
543+
component.warn(this, {
544+
code: `a11y-media-has-caption`,
545+
message: `A11y: Media elements must have a <track kind="captions">`
546+
});
547+
}
548+
}
549+
531550
if (a11y_no_onchange.has(this.name)) {
532551
if (handlers_map.has('change') && !handlers_map.has('blur')) {
533552
component.warn(this, {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
<div><video class="svelte-xyz" autoplay></video>
2-
<video></video></div>
1+
<div><video class="svelte-xyz" autoplay muted></video>
2+
<video muted></video></div>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<div>
2-
<video autoplay></video>
3-
<video></video>
2+
<video autoplay muted></video>
3+
<video muted></video>
44
</div>
55

66
<style>
77
[autoplay] {
88
color: red;
99
}
10-
</style>
10+
</style>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<video><track kind="captions"/></video>
2+
<video></video>
3+
<video><track /></video>
4+
<audio muted></audio>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[
2+
{
3+
"code": "a11y-media-has-caption",
4+
"end": {
5+
"character": 55,
6+
"column": 15,
7+
"line": 2
8+
},
9+
"message": "A11y: Media elements must have a <track kind=\"captions\">",
10+
"pos": 40,
11+
"start": {
12+
"character": 40,
13+
"column": 0,
14+
"line": 2
15+
}
16+
},
17+
{
18+
"code": "a11y-media-has-caption",
19+
"end": {
20+
"character": 80,
21+
"column": 24,
22+
"line": 3
23+
},
24+
"message": "A11y: Media elements must have a <track kind=\"captions\">",
25+
"pos": 56,
26+
"start": {
27+
"character": 56,
28+
"column": 0,
29+
"line": 3
30+
}
31+
}
32+
]

0 commit comments

Comments
 (0)