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

pull/17312/head
Rich Harris 10 months 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': { case 'video': {
const aria_hidden_attribute = attribute_map.get('aria-hidden'); const aria_hidden_attribute = attribute_map.get('aria-hidden');
const aria_hidden_exist = aria_hidden_attribute && get_static_value(aria_hidden_attribute); const aria_hidden_exist = aria_hidden_attribute && get_static_value(aria_hidden_attribute);
if (attribute_map.has('muted') || aria_hidden_exist === 'true' || has_spread) { if (attribute_map.has('muted') || aria_hidden_exist === 'true' || has_spread) {
return; 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; let has_caption = false;
const track = /** @type {AST.RegularElement | undefined} */ ( const track = /** @type {AST.RegularElement | undefined} */ (
node.fragment.nodes.find((i) => i.type === 'RegularElement' && i.name === 'track') node.fragment.nodes.find((i) => i.type === 'RegularElement' && i.name === 'track')

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

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

Loading…
Cancel
Save