Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(820): check if media has captions #5075

Merged
merged 4 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
]