Skip to content

Commit 0990095

Browse files
authored
fix: don't issue a11y warning for video without captions if it has no src (#17311)
1 parent 46603d9 commit 0990095

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

.changeset/dark-buckets-hang.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: don't issue a11y warning for `<video>` without captions if it has no `src`

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,17 @@ export function check_element(node, context) {
486486
case 'video': {
487487
const aria_hidden_attribute = attribute_map.get('aria-hidden');
488488
const aria_hidden_exist = aria_hidden_attribute && get_static_value(aria_hidden_attribute);
489+
489490
if (attribute_map.has('muted') || aria_hidden_exist === 'true' || has_spread) {
490491
return;
491492
}
493+
494+
if (!attribute_map.has('src')) {
495+
// don't warn about missing captions if `<video>` has no `src` —
496+
// could e.g. be playing a MediaStream
497+
return;
498+
}
499+
492500
let has_caption = false;
493501
const track = /** @type {AST.RegularElement | undefined} */ (
494502
node.fragment.nodes.find((i) => i.type === 'RegularElement' && i.name === 'track')
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
<video><track kind="captions"/></video>
2-
<video></video>
3-
<video><track /></video>
1+
<video src="x"><track kind="captions"/></video>
2+
<video src="x"></video>
3+
<video src="x"><track /></video>
44
<audio></audio>
5-
<video aria-hidden="true"></video>
6-
<video aria-hidden="false"></video>
5+
<video src="x" aria-hidden="true"></video>
6+
<video src="x" aria-hidden="false"></video>
7+
<video></video> <!-- no src -->

packages/svelte/tests/validator/samples/a11y-media-has-caption/warnings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"code": "a11y_media_has_caption",
44
"end": {
5-
"column": 15,
5+
"column": 23,
66
"line": 2
77
},
88
"message": "`<video>` elements must have a `<track kind=\"captions\">`",
@@ -14,7 +14,7 @@
1414
{
1515
"code": "a11y_media_has_caption",
1616
"end": {
17-
"column": 24,
17+
"column": 32,
1818
"line": 3
1919
},
2020
"message": "`<video>` elements must have a `<track kind=\"captions\">`",
@@ -26,7 +26,7 @@
2626
{
2727
"code": "a11y_media_has_caption",
2828
"end": {
29-
"column": 35,
29+
"column": 43,
3030
"line": 6
3131
},
3232
"message": "`<video>` elements must have a `<track kind=\"captions\">`",

0 commit comments

Comments
 (0)