Skip to content

Commit

Permalink
add a11y-media-has-caption check (sveltejs#5075)
Browse files Browse the repository at this point in the history
  • Loading branch information
skippednote authored and taylorzane committed Dec 17, 2020
1 parent ce1e24c commit c44e131
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
19 changes: 19 additions & 0 deletions src/compiler/compile/nodes/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,25 @@ export default class Element extends Node {
}
}

if (this.is_media_node()) {
if (attribute_map.has('muted')) {
return;
}

let has_caption;
const track = this.children.find((i: Element) => i.name === 'track');
if (track) {
has_caption = track.attributes.find(a => a.name === 'kind' && a.get_static_value() === 'captions');
}

if (!has_caption) {
component.warn(this, {
code: `a11y-media-has-caption`,
message: `A11y: Media elements must have a <track kind="captions">`
});
}
}

if (a11y_no_onchange.has(this.name)) {
if (handlers_map.has('change') && !handlers_map.has('blur')) {
component.warn(this, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<div><video class="svelte-xyz" autoplay></video>
<video></video></div>
<div><video class="svelte-xyz" autoplay muted></video>
<video muted></video></div>
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<div>
<video autoplay></video>
<video></video>
<video autoplay muted></video>
<video muted></video>
</div>

<style>
[autoplay] {
color: red;
}
</style>
</style>
4 changes: 4 additions & 0 deletions test/validator/samples/a11y-media-has-caption/input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<video><track kind="captions"/></video>
<video></video>
<video><track /></video>
<audio muted></audio>
32 changes: 32 additions & 0 deletions test/validator/samples/a11y-media-has-caption/warnings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"code": "a11y-media-has-caption",
"end": {
"character": 55,
"column": 15,
"line": 2
},
"message": "A11y: Media elements must have a <track kind=\"captions\">",
"pos": 40,
"start": {
"character": 40,
"column": 0,
"line": 2
}
},
{
"code": "a11y-media-has-caption",
"end": {
"character": 80,
"column": 24,
"line": 3
},
"message": "A11y: Media elements must have a <track kind=\"captions\">",
"pos": 56,
"start": {
"character": 56,
"column": 0,
"line": 3
}
}
]

0 comments on commit c44e131

Please sign in to comment.