fix: don't issue a11y warning for video without captions if it has no `src` (#17311)

pull/16903/merge
Rich Harris 21 hours ago committed by GitHub
parent 46603d93cb
commit 0990095aed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: don't issue a11y warning for `<video>` without captions if it has no `src`

@ -486,9 +486,17 @@ export function check_element(node, context) {
case 'video': {
const aria_hidden_attribute = attribute_map.get('aria-hidden');
const aria_hidden_exist = aria_hidden_attribute && get_static_value(aria_hidden_attribute);
if (attribute_map.has('muted') || aria_hidden_exist === 'true' || has_spread) {
return;
}
if (!attribute_map.has('src')) {
// don't warn about missing captions if `<video>` has no `src` —
// could e.g. be playing a MediaStream
return;
}
let has_caption = false;
const track = /** @type {AST.RegularElement | undefined} */ (
node.fragment.nodes.find((i) => i.type === 'RegularElement' && i.name === 'track')

@ -1,6 +1,7 @@
<video><track kind="captions"/></video>
<video></video>
<video><track /></video>
<video src="x"><track kind="captions"/></video>
<video src="x"></video>
<video src="x"><track /></video>
<audio></audio>
<video aria-hidden="true"></video>
<video aria-hidden="false"></video>
<video src="x" aria-hidden="true"></video>
<video src="x" aria-hidden="false"></video>
<video></video> <!-- no src -->

@ -2,7 +2,7 @@
{
"code": "a11y_media_has_caption",
"end": {
"column": 15,
"column": 23,
"line": 2
},
"message": "`<video>` elements must have a `<track kind=\"captions\">`",
@ -14,7 +14,7 @@
{
"code": "a11y_media_has_caption",
"end": {
"column": 24,
"column": 32,
"line": 3
},
"message": "`<video>` elements must have a `<track kind=\"captions\">`",
@ -26,7 +26,7 @@
{
"code": "a11y_media_has_caption",
"end": {
"column": 35,
"column": 43,
"line": 6
},
"message": "`<video>` elements must have a `<track kind=\"captions\">`",

Loading…
Cancel
Save